cloudfront-signer 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39a04cdad6eadba7f441fb8cfba1c643b3f5fe9b
4
- data.tar.gz: 7786c9d47b121178a26e832b129b9a163e299bf5
3
+ metadata.gz: 7d944157441307ac5089ebdebf6cb792ae146de9
4
+ data.tar.gz: c1e333b58d90f8d3538a50daa6dc7d812b92e53c
5
5
  SHA512:
6
- metadata.gz: 39a5a4e824e33d04b5b5d19726f2a935e0b51d3202ed9819900cf9ff952b6e1eea17a335a355d5990a0048e1c2f203684a5033d38abe1d381b36d86e62c62a14
7
- data.tar.gz: 03a54b2be4915bb859b96c5ffba4fb15d5c845a8c0fef62f70e81dc6566e73b4d4c3653d31906599100f5a78829694dee2e2f98a4ae42b505a822dc7a18f000f
6
+ metadata.gz: cc3ca840dd7ba3894e4dbb265b3ccc0dd2412397dbfd4887d09112c06b4985679c9f8607b5d67a21df72b7e0f4278d4daec8561aa9835a4c220012232326b152
7
+ data.tar.gz: 9888e0ce34a7892461721a68f61aa4480b93ac3ea9f7deb33fb146274508d5578313e1e4f2b9bb27d43896749f38a2ed3e0a91b8d8f13cb88c42ebfae0ffc51e
@@ -1,5 +1,9 @@
1
+ ### 2.2.0 / 2015-04-29
2
+ * Accepted merge request from https://github.com/leonelgalan - `sign_params` method returns raw params to be used in urls or cookies.
3
+
1
4
  ### 2.1.2 / 2015-04-16
2
5
  * Accepted merge request from https://github.com/tuvistavie - fixing custom policy bug.
6
+
3
7
  ### 2.1.1 / 2013-10-31
4
8
  * Added changelog file
5
9
  * Aceppted merge request from https://github.com/bullfight, Refactored configuration to allow for key to be passed in directly.
@@ -157,15 +157,11 @@ module AWS
157
157
  self.sign(subject, {:remove_spaces => false, :html_escape => true}, policy_options)
158
158
  end
159
159
 
160
-
161
- # Public: Sign a subject url or stream resource name with optional configuration and
160
+ # Public: Builds a signed url or stream resource name with optional configuration and
162
161
  # policy options
163
162
  #
164
163
  # Returns a String
165
164
  def self.sign(subject, configuration_options = {}, policy_options = {})
166
-
167
- raise "Configure using AWS::CF::Signer.configure before signing." unless self.is_configured?
168
-
169
165
  # If the url or stream path already has a query string parameter - append to that.
170
166
  separator = subject =~ /\?/ ? '&' : '?'
171
167
 
@@ -173,29 +169,43 @@ module AWS
173
169
  subject.gsub!(/\s/, "%20")
174
170
  end
175
171
 
172
+ result = subject + separator + self.signed_params(subject, policy_options).collect{ |k,v| "#{k}=#{v}" }.join('&')
173
+
174
+ if configuration_options[:html_escape]
175
+ return html_encode(result)
176
+ else
177
+ return result
178
+ end
179
+ end
180
+
181
+ # Public: Sign a subject url or stream resource name with optional policy options.
182
+ # It returns raw params to be used in urls or cookies
183
+ #
184
+ # Returns a Hash
185
+ def self.signed_params(subject, policy_options = {})
186
+ result = {}
187
+
176
188
  if policy_options[:policy_file]
177
189
  policy = IO.read(policy_options[:policy_file])
178
- result = "#{subject}#{separator}Policy=#{encode_policy(policy)}&Signature=#{create_signature(policy)}&Key-Pair-Id=#{@key_pair_id}"
190
+ result['Policy'] = encode_policy(policy)
179
191
  else
180
192
  policy_options[:expires] = epoch_time(policy_options[:expires] || Time.now + default_expires)
193
+
181
194
  if policy_options.keys.size <= 1
182
195
  # Canned Policy - shorter URL
183
196
  expires_at = policy_options[:expires]
184
197
  policy = %({"Statement":[{"Resource":"#{subject}","Condition":{"DateLessThan":{"AWS:EpochTime":#{expires_at}}}}]})
185
- result = "#{subject}#{separator}Expires=#{expires_at}&Signature=#{create_signature(policy)}&Key-Pair-Id=#{@key_pair_id}"
198
+ result['Expires'] = expires_at
186
199
  else
187
200
  # Custom Policy
188
201
  resource = policy_options[:resource] || subject
189
202
  policy = generate_custom_policy(resource, policy_options)
190
- result = "#{subject}#{separator}Policy=#{encode_policy(policy)}&Signature=#{create_signature(policy)}&Key-Pair-Id=#{@key_pair_id}"
203
+ result['Policy'] = encode_policy(policy)
191
204
  end
192
205
  end
193
206
 
194
- if configuration_options[:html_escape]
195
- return html_encode(result)
196
- else
197
- return result
198
- end
207
+ result.merge 'Signature' => create_signature(policy),
208
+ 'Key-Pair-Id' => @key_pair_id
199
209
  end
200
210
 
201
211
  # Private helper methods
@@ -1,5 +1,5 @@
1
1
  module AWS
2
2
  module CF
3
- VERSION = "2.1.2"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudfront-signer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Bouch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec