azure-signature 0.2.0 → 0.2.1
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 +4 -4
- data/CHANGES +5 -0
- data/README +1 -1
- data/azure-signature.gemspec +2 -1
- data/lib/azure/signature.rb +46 -35
- data/test/test_signature.rb +9 -2
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7a1b158412c4274214bec5787766675894710b2
|
4
|
+
data.tar.gz: be496da96d1f71a5f51d458c2a17dff98f0cba2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 755801a587abb2d6e700da4efd375da537944aced3638102aeae7c495aa6592a1650ea920a4ce859a0d3bcad2ae05fef6b173c4a42837dbe6cd4917bc5cb4886
|
7
|
+
data.tar.gz: d7bd143b29cdaafa758475a7576c990826049efdcf451ebe24d7692dad7a0adadc31001ff009fdd04e6d02b1a56e78254b9ef2e07c39f5e8604ce8a50b528bc7
|
data/CHANGES
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
= 0.2.1 - 13-June-2016
|
2
|
+
* The signature methods now accept standard header strings as key arguments
|
3
|
+
as well as symbols, e.g. 'auth-type' vs :auth_type.
|
4
|
+
* Replaced URI with Addressable::URI since it's more robust.
|
5
|
+
|
1
6
|
= 0.2.0 - 13-Oct-2015
|
2
7
|
* Added support for other types of signatures (blobs, queues, files).
|
3
8
|
* The :auth_string argument no longer returns the word "Authorization".
|
data/README
CHANGED
data/azure-signature.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = 'azure-signature'
|
5
|
-
gem.version = '0.2.
|
5
|
+
gem.version = '0.2.1'
|
6
6
|
gem.author = 'Daniel J. Berger'
|
7
7
|
gem.license = 'Apache 2.0'
|
8
8
|
gem.email = 'djberg96@gmail.com'
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
|
14
14
|
gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
15
15
|
|
16
|
+
gem.add_dependency('addressable')
|
16
17
|
gem.add_development_dependency('test-unit')
|
17
18
|
|
18
19
|
gem.description = <<-EOF
|
data/lib/azure/signature.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'addressable'
|
2
2
|
require 'openssl'
|
3
3
|
require 'base64'
|
4
4
|
require 'cgi'
|
@@ -9,7 +9,7 @@ module Azure
|
|
9
9
|
# The Signature class encapsulates an canonicalized resource string.
|
10
10
|
class Signature
|
11
11
|
# The version of the azure-signature library.
|
12
|
-
VERSION = '0.2.
|
12
|
+
VERSION = '0.2.1'
|
13
13
|
|
14
14
|
# The resource (URL) passed to the constructor.
|
15
15
|
attr_reader :resource
|
@@ -37,10 +37,10 @@ module Azure
|
|
37
37
|
#
|
38
38
|
def initialize(resource, key)
|
39
39
|
@resource = resource
|
40
|
-
@uri = URI.parse(resource)
|
40
|
+
@uri = Addressable::URI.parse(resource)
|
41
41
|
@account_name = @uri.host.split(".").first.split("-").first
|
42
42
|
@key = Base64.strict_decode64(key)
|
43
|
-
@canonical_resource = canonicalize_resource(
|
43
|
+
@canonical_resource = canonicalize_resource(@uri)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Generate a signature for use with the table service. Use the +options+
|
@@ -54,16 +54,21 @@ module Azure
|
|
54
54
|
# - :auth_string. If true, prepends the auth_type + account name to the
|
55
55
|
# result and returns a string. The default is false.
|
56
56
|
#
|
57
|
+
# You may also use the string forms as keys, e.g. "Auth-Type" instead of
|
58
|
+
# :auth_type, if you prefer.
|
59
|
+
#
|
57
60
|
# The result is a digest string that you can use as an authorization header
|
58
61
|
# for future http requests to (presumably) Azure storage endpoints.
|
59
62
|
#
|
60
63
|
def table_signature(options = {})
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
options.clone.each{ |k,v| options[k.to_s.downcase.tr('_', '-')] = v }
|
65
|
+
|
66
|
+
auth_type = options['auth-type'] || 'SharedKey'
|
67
|
+
verb = options['verb'] || 'GET'
|
68
|
+
date = options['date'] || Time.now.httpdate
|
69
|
+
auth_string = options['auth-string'] || false
|
70
|
+
content_md5 = options['content-md5']
|
71
|
+
content_type = options['content-type']
|
67
72
|
|
68
73
|
unless ['SharedKey', 'SharedKeyLight'].include?(auth_type)
|
69
74
|
raise ArgumentError, "auth type must be SharedKey or SharedKeyLight"
|
@@ -93,6 +98,9 @@ module Azure
|
|
93
98
|
# - :auth_string. If true, prepends the auth_type + account name to the
|
94
99
|
# result and returns a string. The default is false.
|
95
100
|
#
|
101
|
+
# You may also use the string forms as keys, e.g. "Auth-Type" instead of
|
102
|
+
# :auth_type, if you prefer.
|
103
|
+
#
|
96
104
|
# The other headers of potential significance are below. Note that you
|
97
105
|
# are not required to set any of them.
|
98
106
|
#
|
@@ -131,7 +139,7 @@ module Azure
|
|
131
139
|
# }
|
132
140
|
#
|
133
141
|
# sig = sig.blob_signature(headers)
|
134
|
-
#
|
142
|
+
# headers['Authorization'] = sig
|
135
143
|
#
|
136
144
|
# req = RestClient::Request.new(
|
137
145
|
# :method => 'get',
|
@@ -139,23 +147,25 @@ module Azure
|
|
139
147
|
# :headers => headers
|
140
148
|
# )
|
141
149
|
#
|
142
|
-
#
|
143
|
-
#
|
150
|
+
# response = req.execute
|
151
|
+
# p response.body
|
144
152
|
#
|
145
153
|
def blob_signature(headers = {})
|
146
|
-
|
147
|
-
|
148
|
-
|
154
|
+
headers.clone.each{ |k,v| headers[k.to_s.downcase.tr('_', '-')] = v }
|
155
|
+
|
156
|
+
auth_string = headers.delete('auth-string') || false
|
157
|
+
auth_type = headers.delete('auth_type') || 'SharedKey'
|
158
|
+
verb = headers.delete('verb') || 'GET'
|
149
159
|
|
150
160
|
unless ['SharedKey', 'SharedKeyLight'].include?(auth_type)
|
151
161
|
raise ArgumentError, "auth type must be SharedKey or SharedKeyLight"
|
152
162
|
end
|
153
163
|
|
154
|
-
headers['x-ms-date'] ||=
|
155
|
-
headers['x-ms-version'] ||=
|
164
|
+
headers['x-ms-date'] ||= Time.now.httpdate
|
165
|
+
headers['x-ms-version'] ||= '2015-02-21'
|
156
166
|
|
157
167
|
if auth_type == 'SharedKeyLight'
|
158
|
-
headers['
|
168
|
+
headers['date'] ||= headers['x-ms-date'] || Time.now.httpdate
|
159
169
|
end
|
160
170
|
|
161
171
|
body = generate_string(verb, headers, auth_type).encode('UTF-8')
|
@@ -187,31 +197,32 @@ module Azure
|
|
187
197
|
private
|
188
198
|
|
189
199
|
def generate_string(verb, headers, auth_type)
|
200
|
+
headers.clone.keys.each{ |k| headers[k.to_s.downcase] = headers[k] }
|
190
201
|
canonical_headers = canonicalize_headers(headers)
|
191
202
|
|
192
203
|
if auth_type == 'SharedKeyLight'
|
193
204
|
[
|
194
205
|
verb.to_s.upcase,
|
195
|
-
headers['
|
196
|
-
headers['
|
197
|
-
headers['
|
206
|
+
headers['content-md5'],
|
207
|
+
headers['content-type'],
|
208
|
+
headers['date'],
|
198
209
|
canonical_headers,
|
199
210
|
canonical_resource
|
200
211
|
].join("\n")
|
201
212
|
else
|
202
213
|
[
|
203
214
|
verb.to_s.upcase,
|
204
|
-
headers['
|
205
|
-
headers['
|
206
|
-
headers['
|
207
|
-
headers['
|
208
|
-
headers['
|
209
|
-
headers['
|
210
|
-
headers['
|
211
|
-
headers['
|
212
|
-
headers['
|
213
|
-
headers['
|
214
|
-
headers['
|
215
|
+
headers['content-encoding'],
|
216
|
+
headers['content-language'],
|
217
|
+
headers['content-length'],
|
218
|
+
headers['content-md5'],
|
219
|
+
headers['content-type'],
|
220
|
+
headers['date'],
|
221
|
+
headers['if-modified-since'],
|
222
|
+
headers['if-match'],
|
223
|
+
headers['if-none-match'],
|
224
|
+
headers['if-unmodified-since'],
|
225
|
+
headers['range'],
|
215
226
|
canonical_headers,
|
216
227
|
canonical_resource,
|
217
228
|
].join("\n")
|
@@ -222,7 +233,7 @@ module Azure
|
|
222
233
|
#--
|
223
234
|
# Borrowed from azure-sdk-for-ruby. I had my own, but this was nicer.
|
224
235
|
#
|
225
|
-
def canonicalize_resource(
|
236
|
+
def canonicalize_resource(uri)
|
226
237
|
resource = '/' + account_name + (uri.path.empty? ? '/' : uri.path)
|
227
238
|
params = CGI.parse(uri.query.to_s).map { |k,v| [k.downcase, v] }
|
228
239
|
params.sort_by! { |k,v| k }
|
@@ -236,7 +247,7 @@ module Azure
|
|
236
247
|
#
|
237
248
|
def canonicalize_headers(headers)
|
238
249
|
headers = headers.map { |k,v| [k.to_s.gsub('_', '-').downcase, v] }
|
239
|
-
headers.select! { |k,v| k =~ /^x-ms-/ }
|
250
|
+
headers.select! { |k,v| k =~ /^x-ms-/i }
|
240
251
|
headers.sort_by! { |k,v| k }
|
241
252
|
headers.map! { |k,v| '%s:%s' % [k, v] }
|
242
253
|
headers.map! { |h| h.gsub(/\s+/, ' ') }.join("\n")
|
data/test/test_signature.rb
CHANGED
@@ -9,7 +9,7 @@ class TC_Azure_Signature < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
test "version constant is set to expected value" do
|
12
|
-
assert_equal("0.2.
|
12
|
+
assert_equal("0.2.1", Azure::Signature::VERSION)
|
13
13
|
end
|
14
14
|
|
15
15
|
test "key method basic functionality" do
|
@@ -34,7 +34,7 @@ class TC_Azure_Signature < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
test "uri method basic functionality" do
|
36
36
|
assert_respond_to(@sig, :uri)
|
37
|
-
assert_kind_of(URI, @sig.uri)
|
37
|
+
assert_kind_of(Addressable::URI, @sig.uri)
|
38
38
|
end
|
39
39
|
|
40
40
|
test "canonical_resource method basic functionality" do
|
@@ -95,6 +95,13 @@ class TC_Azure_Signature < Test::Unit::TestCase
|
|
95
95
|
assert_alias_method(@sig, :blob_signature, :queue_signature)
|
96
96
|
end
|
97
97
|
|
98
|
+
test "signature with strings or symbols is identical" do
|
99
|
+
date = '2016-01-01'
|
100
|
+
sig_symbol = @sig.signature(:table, :auth_string => true, :date => date, :verb => 'PUT')
|
101
|
+
sig_string = @sig.signature(:table, 'Auth-String' => true, 'Date' => date, 'Verb' => 'PUT')
|
102
|
+
assert_equal(sig_symbol, sig_string)
|
103
|
+
end
|
104
|
+
|
98
105
|
def teardown
|
99
106
|
@key = nil
|
100
107
|
@url = nil
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azure-signature
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: test-unit
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
78
|
version: '0'
|
65
79
|
requirements: []
|
66
80
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.4
|
81
|
+
rubygems_version: 2.6.4
|
68
82
|
signing_key:
|
69
83
|
specification_version: 4
|
70
84
|
summary: Generate authentication signatures for Azure
|