aws-sdk-cloudfront 1.0.0.rc2 → 1.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,35 +18,23 @@ module Aws
18
18
  # )
19
19
  #
20
20
  class UrlSigner
21
-
22
- # @option options [String] :key_pair_id
23
- # @option options [String] :private_key
24
- # @option options [String] :private_key_path
25
- def initialize(options = {})
26
- @key_pair_id = key_pair_id(options)
27
- @private_key = private_key(options)
28
- end
21
+ include Signer
29
22
 
30
23
  # create a signed Amazon CloudFront URL
31
24
  # @param [String] url
32
25
  # @option params [Time, DateTime, Date, String, Integer<timestamp>] :expires
33
26
  # @option params [String<JSON>] :policy
34
27
  def signed_url(url, params = {})
35
- url_sections = url.split('://')
36
- if url_sections.length < 2
37
- raise ArgumentError, "Invaild URL:#{url}"
38
- end
39
- # removing wildcard character to get real scheme
40
- scheme = url_sections[0].gsub('*', '')
41
- uri = "#{scheme}://#{url_sections[1]}"
28
+ scheme, uri = scheme_and_uri(url)
42
29
  signed_content = signature(
43
- :resource => resource(scheme, uri),
44
- :expires => time(params[:expires]),
45
- :policy => params[:policy]
30
+ resource: resource(scheme, uri),
31
+ expires: time(params[:expires]),
32
+ policy: params[:policy]
46
33
  )
47
34
 
48
35
  start_flag = URI.parse(uri).query ? '&' : '?'
49
- uri = "#{uri}#{start_flag}#{signed_content}"
36
+ signature = signed_content.map{ |k, v| "#{k}=#{v}" }.join('&').gsub("\n", '')
37
+ uri = "#{uri}#{start_flag}#{signature}"
50
38
 
51
39
  if scheme == 'rtmp'
52
40
  rtmp_url(URI(uri))
@@ -55,115 +43,6 @@ module Aws
55
43
  end
56
44
  end
57
45
 
58
- private
59
-
60
- def time(expires)
61
- case expires
62
- when Time then expires.to_i
63
- when DateTime, Date then expires.to_time.to_i
64
- when String then Time.parse(expires).to_i
65
- when Integer, NIL then expires
66
- else
67
- msg = "expected a time value for :expires, got `#{expires.class}'"
68
- raise ArgumentError, msg
69
- end
70
- end
71
-
72
- # create a relative signed URL for RTMP distribution
73
- def rtmp_url(uri)
74
- result = uri.path.gsub(' ', '/')
75
- result[0] = ''
76
- if uri.query
77
- "#{result}?#{uri.query}"
78
- else
79
- result
80
- end
81
- end
82
-
83
- # prepare resource for signing
84
- def resource(scheme, url)
85
- case scheme
86
- when 'http', 'http*', 'https' then url
87
- when 'rtmp'
88
- url_info = URI.parse(url)
89
- path = url_info.path
90
- path[0] = ''
91
- resource_content = "#{File.dirname(path)}/#{File.basename(path)}".gsub(' ', '/')
92
- if url_info.query
93
- "#{resource_content}?#{uri.query}"
94
- else
95
- resource_content
96
- end
97
- else
98
- msg = "Invaild URI scheme:#{scheme}.Scheme must be one of: http, https or rtmp."
99
- raise ArgumentError, msg
100
- end
101
- end
102
-
103
- # create signed values that used to construct signed URLs
104
- # @option param [String] :resource
105
- # @option param [Integer<timestamp>] :expires
106
- # @option param [String<JSON>] :policy
107
- def signature(params = {})
108
- signature_content = []
109
- if params[:policy]
110
- policy = params[:policy].gsub('/\s/s', '')
111
- signature_content << "Policy=#{encode(policy)}"
112
- elsif params[:resource] && params[:expires]
113
- policy = canned_policy(params[:resource], params[:expires])
114
- signature_content << "Expires=#{params[:expires]}"
115
- else
116
- msg = "Either a policy or a resource with an expiration time must be provided."
117
- raise ArgumentError, msg
118
- end
119
-
120
- signature_content << "Signature=#{encode(sign_policy(policy))}"
121
- signature_content << "Key-Pair-Id=#{@key_pair_id}"
122
- signature_content.join('&').gsub("\n", '')
123
- end
124
-
125
- # create the signature string with policy signed
126
- def sign_policy(policy)
127
- key = OpenSSL::PKey::RSA.new(@private_key)
128
- key.sign(OpenSSL::Digest::SHA1.new, policy)
129
- end
130
-
131
- # create canned policy that used for signing
132
- def canned_policy(resource, expires)
133
- json_hash = {
134
- 'Statement' => [
135
- 'Resource' => resource,
136
- 'Condition' => {
137
- 'DateLessThan' => {'AWS:EpochTime' => expires}
138
- }
139
- ]
140
- }
141
- json_hash.to_json
142
- end
143
-
144
- def encode(policy)
145
- Base64.encode64(policy).gsub(/[+=\/]/, '+' => '-', '=' => '_', '/' => '~')
146
- end
147
-
148
- def key_pair_id(options)
149
- if options[:key_pair_id].nil? or options[:key_pair_id] == ''
150
- raise ArgumentError, ":key_pair_id must not be blank"
151
- else
152
- options[:key_pair_id]
153
- end
154
- end
155
-
156
- def private_key(options)
157
- if options[:private_key]
158
- options[:private_key]
159
- elsif options[:private_key_path]
160
- File.open(options[:private_key_path], 'rb') { |f| f.read }
161
- else
162
- msg = ":private_key or :private_key_path should be provided"
163
- raise ArgumentError, msg
164
- end
165
- end
166
-
167
46
  end
168
47
  end
169
48
  end
@@ -1,125 +1,124 @@
1
1
  # WARNING ABOUT GENERATED CODE
2
2
  #
3
- # This file is generated. See the contributing for info on making contributions:
3
+ # This file is generated. See the contributing guide for more information:
4
4
  # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
5
5
  #
6
6
  # WARNING ABOUT GENERATED CODE
7
7
 
8
8
  require 'aws-sdk-core/waiters'
9
9
 
10
- module Aws
11
- module CloudFront
12
- module Waiters
13
- class DistributionDeployed
14
-
15
- # @param [Hash] options
16
- # @option options [required, Client] :client
17
- # @option options [Integer] :max_attempts (25)
18
- # @option options [Integer] :delay (60)
19
- # @option options [Proc] :before_attempt
20
- # @option options [Proc] :before_wait
21
- def initialize(options)
22
- @client = options.fetch(:client)
23
- @waiter = Aws::Waiters::Waiter.new({
24
- max_attempts: 25,
25
- delay: 60,
26
- poller: Aws::Waiters::Poller.new(
27
- "description" => "Wait until a distribution is deployed.",
28
- operation_name: :get_distribution,
29
- acceptors: [{
30
- "expected" => "Deployed",
31
- "matcher" => "path",
32
- "state" => "success",
33
- "argument" => "distribution.status"
34
- }]
35
- )
36
- }.merge(options))
37
- end
38
-
39
- # @option (see Client#get_distribution)
40
- # @return (see Client#get_distribution)
41
- def wait(params = {})
42
- @waiter.wait(client: @client, params: params)
43
- end
44
-
45
- # @api private
46
- attr_reader :waiter
10
+ module Aws::CloudFront
11
+ module Waiters
12
+
13
+ # Wait until a distribution is deployed.
14
+ class DistributionDeployed
15
+
16
+ # @param [Hash] options
17
+ # @option options [required, Client] :client
18
+ # @option options [Integer] :max_attempts (25)
19
+ # @option options [Integer] :delay (60)
20
+ # @option options [Proc] :before_attempt
21
+ # @option options [Proc] :before_wait
22
+ def initialize(options)
23
+ @client = options.fetch(:client)
24
+ @waiter = Aws::Waiters::Waiter.new({
25
+ max_attempts: 25,
26
+ delay: 60,
27
+ poller: Aws::Waiters::Poller.new(
28
+ operation_name: :get_distribution,
29
+ acceptors: [{
30
+ "expected" => "Deployed",
31
+ "matcher" => "path",
32
+ "state" => "success",
33
+ "argument" => "distribution.status"
34
+ }]
35
+ )
36
+ }.merge(options))
37
+ end
47
38
 
39
+ # @option (see Client#get_distribution)
40
+ # @return (see Client#get_distribution)
41
+ def wait(params = {})
42
+ @waiter.wait(client: @client, params: params)
48
43
  end
49
44
 
50
- class InvalidationCompleted
51
-
52
- # @param [Hash] options
53
- # @option options [required, Client] :client
54
- # @option options [Integer] :max_attempts (30)
55
- # @option options [Integer] :delay (20)
56
- # @option options [Proc] :before_attempt
57
- # @option options [Proc] :before_wait
58
- def initialize(options)
59
- @client = options.fetch(:client)
60
- @waiter = Aws::Waiters::Waiter.new({
61
- max_attempts: 30,
62
- delay: 20,
63
- poller: Aws::Waiters::Poller.new(
64
- "description" => "Wait until an invalidation has completed.",
65
- operation_name: :get_invalidation,
66
- acceptors: [{
67
- "expected" => "Completed",
68
- "matcher" => "path",
69
- "state" => "success",
70
- "argument" => "invalidation.status"
71
- }]
72
- )
73
- }.merge(options))
74
- end
75
-
76
- # @option (see Client#get_invalidation)
77
- # @return (see Client#get_invalidation)
78
- def wait(params = {})
79
- @waiter.wait(client: @client, params: params)
80
- end
81
-
82
- # @api private
83
- attr_reader :waiter
45
+ # @api private
46
+ attr_reader :waiter
47
+
48
+ end
49
+
50
+ # Wait until an invalidation has completed.
51
+ class InvalidationCompleted
52
+
53
+ # @param [Hash] options
54
+ # @option options [required, Client] :client
55
+ # @option options [Integer] :max_attempts (30)
56
+ # @option options [Integer] :delay (20)
57
+ # @option options [Proc] :before_attempt
58
+ # @option options [Proc] :before_wait
59
+ def initialize(options)
60
+ @client = options.fetch(:client)
61
+ @waiter = Aws::Waiters::Waiter.new({
62
+ max_attempts: 30,
63
+ delay: 20,
64
+ poller: Aws::Waiters::Poller.new(
65
+ operation_name: :get_invalidation,
66
+ acceptors: [{
67
+ "expected" => "Completed",
68
+ "matcher" => "path",
69
+ "state" => "success",
70
+ "argument" => "invalidation.status"
71
+ }]
72
+ )
73
+ }.merge(options))
74
+ end
84
75
 
76
+ # @option (see Client#get_invalidation)
77
+ # @return (see Client#get_invalidation)
78
+ def wait(params = {})
79
+ @waiter.wait(client: @client, params: params)
85
80
  end
86
81
 
87
- class StreamingDistributionDeployed
88
-
89
- # @param [Hash] options
90
- # @option options [required, Client] :client
91
- # @option options [Integer] :max_attempts (25)
92
- # @option options [Integer] :delay (60)
93
- # @option options [Proc] :before_attempt
94
- # @option options [Proc] :before_wait
95
- def initialize(options)
96
- @client = options.fetch(:client)
97
- @waiter = Aws::Waiters::Waiter.new({
98
- max_attempts: 25,
99
- delay: 60,
100
- poller: Aws::Waiters::Poller.new(
101
- "description" => "Wait until a streaming distribution is deployed.",
102
- operation_name: :get_streaming_distribution,
103
- acceptors: [{
104
- "expected" => "Deployed",
105
- "matcher" => "path",
106
- "state" => "success",
107
- "argument" => "streaming_distribution.status"
108
- }]
109
- )
110
- }.merge(options))
111
- end
112
-
113
- # @option (see Client#get_streaming_distribution)
114
- # @return (see Client#get_streaming_distribution)
115
- def wait(params = {})
116
- @waiter.wait(client: @client, params: params)
117
- end
118
-
119
- # @api private
120
- attr_reader :waiter
82
+ # @api private
83
+ attr_reader :waiter
121
84
 
85
+ end
86
+
87
+ # Wait until a streaming distribution is deployed.
88
+ class StreamingDistributionDeployed
89
+
90
+ # @param [Hash] options
91
+ # @option options [required, Client] :client
92
+ # @option options [Integer] :max_attempts (25)
93
+ # @option options [Integer] :delay (60)
94
+ # @option options [Proc] :before_attempt
95
+ # @option options [Proc] :before_wait
96
+ def initialize(options)
97
+ @client = options.fetch(:client)
98
+ @waiter = Aws::Waiters::Waiter.new({
99
+ max_attempts: 25,
100
+ delay: 60,
101
+ poller: Aws::Waiters::Poller.new(
102
+ operation_name: :get_streaming_distribution,
103
+ acceptors: [{
104
+ "expected" => "Deployed",
105
+ "matcher" => "path",
106
+ "state" => "success",
107
+ "argument" => "streaming_distribution.status"
108
+ }]
109
+ )
110
+ }.merge(options))
111
+ end
112
+
113
+ # @option (see Client#get_streaming_distribution)
114
+ # @return (see Client#get_streaming_distribution)
115
+ def wait(params = {})
116
+ @waiter.wait(client: @client, params: params)
122
117
  end
118
+
119
+ # @api private
120
+ attr_reader :waiter
121
+
123
122
  end
124
123
  end
125
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-cloudfront
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
4
+ version: 1.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-10 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -49,9 +49,11 @@ files:
49
49
  - lib/aws-sdk-cloudfront.rb
50
50
  - lib/aws-sdk-cloudfront/client.rb
51
51
  - lib/aws-sdk-cloudfront/client_api.rb
52
+ - lib/aws-sdk-cloudfront/cookie_signer.rb
52
53
  - lib/aws-sdk-cloudfront/customizations.rb
53
54
  - lib/aws-sdk-cloudfront/errors.rb
54
55
  - lib/aws-sdk-cloudfront/resource.rb
56
+ - lib/aws-sdk-cloudfront/signer.rb
55
57
  - lib/aws-sdk-cloudfront/types.rb
56
58
  - lib/aws-sdk-cloudfront/url_signer.rb
57
59
  - lib/aws-sdk-cloudfront/waiters.rb