azure-storage 0.10.2.preview → 0.11.0.preview

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31054294abe6fc2b3f0dcb87d286291e9dfe0766
4
- data.tar.gz: 0d4555ce667aabb5dfd2f1d49d7d28b09ff0bd7b
3
+ metadata.gz: 8eb09fd448c403c8f348d9d50f1edd4f3824876e
4
+ data.tar.gz: 86f0661c191d66ea65a979e145aea7ef76d97414
5
5
  SHA512:
6
- metadata.gz: b3bdddb9899c6ad7f4680a8350b6351ddcf4a7ae29dace4cd1daf5ca27053a19e1503881b521ac364d08be1b6c5b1b97c275378e12dd5655c00b020a2d6077ef
7
- data.tar.gz: a473487c90bad59cac0a335e3d58df1405da2c70ee816cf717295f0ae09cf4061e0fb2789dc46da37e7fc9ddab529047b5bd0d0f1e9ffa35d93f6d4d4680147a
6
+ metadata.gz: 213bd465a59e3f6cdfbd24bc20e572f386d2d7e7f7d9f6661dd0058d6012f03920160f3d86b5c6b2fa124b484d4e823036e1ae8ae0066498ba16d35d7e53e7b2
7
+ data.tar.gz: e543a1360919133f26f822c8ae76bca7ec72467805a7ee2aa11cc6a66b2f0b5d4d2f4df0f315ba5f3663754ec652852b5465ec4eb0e56bfe1b2a14a772e281cb
@@ -66,4 +66,4 @@ module Azure
66
66
  end
67
67
 
68
68
  end
69
- end
69
+ end
@@ -22,6 +22,7 @@
22
22
  # THE SOFTWARE.
23
23
  #--------------------------------------------------------------------------
24
24
  require 'base64'
25
+ require 'azure/storage/core/auth/shared_key'
25
26
  require 'azure/storage/blob/container'
26
27
  require 'azure/storage/blob/blob'
27
28
  require 'azure/storage/blob/block'
@@ -37,7 +38,9 @@ module Azure::Storage
37
38
  include Azure::Storage::Blob::Container
38
39
 
39
40
  def initialize(options = {})
40
- super(nil, nil, options)
41
+ client_config = options[:client] || Azure::Storage
42
+ signer = options[:signer] || Azure::Storage::Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
43
+ super(signer, client_config.storage_account_name, options)
41
44
  @host = client.storage_blob_host
42
45
  end
43
46
 
@@ -87,20 +87,20 @@ module Azure::Storage
87
87
 
88
88
  # Azure Blob service client configured from this Azure Storage client instance
89
89
  # @return [Azure::Storage::Blob::BlobService]
90
- def blobClient(options = {})
91
- @blobClient ||= Azure::Storage::Blob::BlobService.new(default_client(options))
90
+ def blob_client(options = {})
91
+ @blob_client ||= Azure::Storage::Blob::BlobService.new(default_client(options))
92
92
  end
93
93
 
94
94
  # Azure Queue service client configured from this Azure Storage client instance
95
95
  # @return [Azure::Storage::Queue::QueueService]
96
- def queueClient(options = {})
97
- @queueClient ||= Azure::Storage::Queue::QueueService.new(default_client(options))
96
+ def queue_client(options = {})
97
+ @queue_client ||= Azure::Storage::Queue::QueueService.new(default_client(options))
98
98
  end
99
99
 
100
100
  # Azure Table service client configured from this Azure Storage client instance
101
101
  # @return [Azure::Storage::Table::TableService]
102
- def tableClient(options = {})
103
- @tableClient ||= Azure::Storage::Table::TableService.new(default_client(options))
102
+ def table_client(options = {})
103
+ @table_client ||= Azure::Storage::Table::TableService.new(default_client(options))
104
104
  end
105
105
 
106
106
  class << self
@@ -187,4 +187,4 @@ module Azure::Storage
187
187
  end
188
188
 
189
189
  end
190
- end
190
+ end
@@ -230,6 +230,18 @@ module Azure::Storage
230
230
  rescue InvalidOptionsError => e
231
231
  end
232
232
 
233
+ # P6 - account name and key or sas with explicit hosts
234
+ begin
235
+ results = validated_options(opts,
236
+ :required => [:storage_account_name],
237
+ :only_one => [:storage_access_key, :storage_sas_token],
238
+ :at_least_one => [:storage_blob_host, :storage_table_host, :storage_file_host, :storage_queue_host])
239
+ results[:use_path_style_uri] = results.key?(:use_path_style_uri)
240
+ normalize_hosts(results)
241
+ return results
242
+ rescue InvalidOptionsError => e
243
+ end
244
+
233
245
  raise InvalidOptionsError,"options provided are not valid set: #{opts}" # wrong opts if move to this line
234
246
  end
235
247
 
@@ -331,4 +343,4 @@ module Azure::Storage
331
343
 
332
344
  end
333
345
 
334
- end
346
+ end
@@ -53,7 +53,8 @@ module Azure::Storage
53
53
 
54
54
  attr_accessor :storage_access_key,
55
55
  :storage_account_name,
56
- :storage_connection_string
56
+ :storage_connection_string,
57
+ :storage_sas_token
57
58
 
58
59
  attr_writer :storage_table_host,
59
60
  :storage_blob_host,
@@ -67,6 +68,7 @@ module Azure::Storage
67
68
  :storage_access_key,
68
69
  :storage_account_name,
69
70
  :storage_connection_string,
71
+ :storage_sas_token,
70
72
  :storage_table_host,
71
73
  :storage_blob_host,
72
74
  :storage_queue_host
@@ -25,4 +25,4 @@
25
25
  require 'azure/storage/core/auth/shared_access_signature_generator'
26
26
  require 'azure/storage/core/auth/shared_access_signature_signer'
27
27
 
28
- include Azure::Storage::Auth
28
+ include Azure::Storage::Core::Auth
@@ -29,7 +29,7 @@ require 'time'
29
29
  require 'uri'
30
30
 
31
31
  # @see https://msdn.microsoft.com/library/azure/dn140255.aspx for more information on construction
32
- module Azure::Storage
32
+ module Azure::Storage::Core
33
33
  module Auth
34
34
  class SharedAccessSignature
35
35
 
@@ -38,12 +38,32 @@ module Azure::Storage
38
38
  version: Azure::Storage::Default::STG_VERSION
39
39
  }
40
40
 
41
- KEY_MAPPINGS = {
41
+ SERVICE_TYPE_MAPPING = {
42
+ b: Azure::Storage::ServiceType::BLOB,
43
+ t: Azure::Storage::ServiceType::TABLE,
44
+ q: Azure::Storage::ServiceType::QUEUE,
45
+ f: Azure::Storage::ServiceType::FILE
46
+ }
47
+
48
+ ACCOUNT_KEY_MAPPINGS = {
49
+ version: :sv,
50
+ service: :ss,
51
+ resource: :srt,
52
+ permissions: :sp,
53
+ start: :st,
54
+ expiry: :se,
55
+ protocol: :spr,
56
+ ip_range: :sip
57
+ }
58
+
59
+ SERVICE_KEY_MAPPINGS = {
42
60
  version: :sv,
43
61
  permissions: :sp,
44
62
  start: :st,
45
63
  expiry: :se,
46
- identifier: :si
64
+ identifier: :si,
65
+ protocol: :spr,
66
+ ip_range: :sip
47
67
  }
48
68
 
49
69
  BLOB_KEY_MAPPINGS = {
@@ -56,14 +76,16 @@ module Azure::Storage
56
76
  }
57
77
 
58
78
  TABLE_KEY_MAPPINGS = {
59
- tablename: :tn,
79
+ table_name: :tn,
60
80
  startpk: :spk,
61
81
  endpk: :epk,
62
82
  startrk: :srk,
63
83
  endrk: :erk
64
84
  }
65
85
 
66
- OPTIONAL_QUERY_PARAMS = [:sp, :si, :rscc, :rscd, :rsce, :rscl, :rsct, :spk, :srk, :epk, :erk]
86
+ SERVICE_OPTIONAL_QUERY_PARAMS = [:sp, :si, :sip, :spr, :rscc, :rscd, :rsce, :rscl, :rsct, :spk, :srk, :epk, :erk]
87
+
88
+ ACCOUNT_OPTIONAL_QUERY_PARAMS = [:st, :sip, :spr]
67
89
 
68
90
  attr :account_name
69
91
 
@@ -76,132 +98,234 @@ module Azure::Storage
76
98
  @signer = Azure::Core::Auth::Signer.new(access_key)
77
99
  end
78
100
 
79
- # Shared Access Signature for the given path and options
80
- # @param path [String] Path of the URI
101
+ # Service Shared Access Signature Token for the given path and options
102
+ # @param path [String] Path of the URI or the table name
81
103
  # @param options [Hash]
82
104
  #
83
105
  # ==== Options
84
106
  #
85
- # * +:permissions+ - String. Combination of 'r','w','d','l' (container only) in this order. Default 'r'
86
- # * +:start+ - String. UTC Date/Time in ISO8601 format. Optional.
87
- # * +:expiry+ - String. UTC Date/Time in ISO8601 format. Optional. Default now + 30 minutes.
88
- # * +:identifier+ - String. Identifier for stored access policy. Optional
107
+ # * +:service+ - String. Required. Service type. 'b' (blob) or 'q' (queue) or 't' (table) or 'f' (file).
108
+ # * +:resource+ - String. Required. Resource type, 'b' (blob) or 'c' (container) or 'f' (file) or 's' (share).
109
+ # * +:permissions+ - String. Optional. Combination of 'r', 'a', 'c', w','d','l' in this order for a container.
110
+ # Combination of 'r', 'a', 'c', 'w', 'd' in this order for a blob.
111
+ # Combination of 'r', 'c', 'w', 'd', 'l' in this order for a share.
112
+ # Combination of 'r', 'c', 'w', 'd' in this order for a file.
113
+ # Combination of 'r', 'a', 'u', 'p' in this order for a queue.
114
+ # Combination of 'r', 'a', 'u', 'd' in this order for a table.
115
+ # This option must be omitted if it has been specified in an associated stored access policy.
116
+ # * +:start+ - String. Optional. UTC Date/Time in ISO8601 format.
117
+ # * +:expiry+ - String. Optional. UTC Date/Time in ISO8601 format. Default now + 30 minutes.
118
+ # * +:identifier+ - String. Optional. Identifier for stored access policy.
119
+ # * +:protocol+ - String. Optional. Permitted protocols.
120
+ # * +:ip_range+ - String. Optional. An IP address or a range of IP addresses from which to accept requests.
89
121
  #
90
- # Below options for Blob only
91
- # * +:resource+ - String. Resource type, either 'b' (blob) or 'c' (container). Default 'b'
92
- # * +:cache_control+ - String. Response header override. Optional.
93
- # * +:content_disposition+ - String. Response header override. Optional.
94
- # * +:content_encoding+ - String. Response header override. Optional.
95
- # * +:content_language+ - String. Response header override. Optional.
96
- # * +:content_type+ - String. Response header override. Optional.
122
+ # Below options for blob serivce only
123
+ # * +:cache_control+ - String. Optional. Response header override.
124
+ # * +:content_disposition+ - String. Optional. Response header override.
125
+ # * +:content_encoding+ - String. Optional. Response header override.
126
+ # * +:content_language+ - String. Optional. Response header override.
127
+ # * +:content_type+ - String. Optional. Response header override.
97
128
  #
98
- # Below options for table only
99
- # * +:startpk+ - String. The start partition key of a specified partition key range. Optional but startpk must accompany startrk.
100
- # * +:endpk+ - String. The end partition key of a specified partition key range. Optional but endpk must accompany endrk.
101
- # * +:startrk+ - String. The start row key of a specified row key range. Optional.
102
- # * +:endrk+ - String. The end row key of a specified row key range. Optional.
103
- def generate(path, options={})
104
- service_type = options[:service_type] || Azure::Storage::ServiceType::BLOB
105
- options.delete(:service_type) if options.key?(:service_type)
106
-
107
- options[:start] = Time.parse(options[:start]).utc.iso8601 if options[:start]
108
- options[:expiry] = Time.parse(options[:expiry]).utc.iso8601 if options[:expiry]
109
- options[:expiry] ||= (Time.now + 60*30).utc.iso8601
129
+ # Below options for table service only
130
+ # * +:startpk+ - String. Optional but must accompany startrk. The start partition key of a specified partition key range.
131
+ # * +:endpk+ - String. Optional but must accompany endrk. The end partition key of a specified partition key range.
132
+ # * +:startrk+ - String. Optional. The start row key of a specified row key range.
133
+ # * +:endrk+ - String. Optional. The end row key of a specified row key range.
134
+ def generate_service_sas_token(path, options={})
135
+ if options.key?(:service)
136
+ service_type = SERVICE_TYPE_MAPPING[options[:service].to_sym]
137
+ options.delete(:service)
138
+ end
110
139
 
111
- raise InvalidOptionsError,"SAS version cannot be set" if options[:version]
140
+ raise Azure::Storage::InvalidOptionsError,"SAS version cannot be set" if options[:version]
112
141
 
113
142
  options = DEFAULTS.merge(options)
114
- valid_mappings = KEY_MAPPINGS
143
+ valid_mappings = SERVICE_KEY_MAPPINGS
115
144
  if service_type == Azure::Storage::ServiceType::BLOB
116
- options.merge!(resource: 'b')
145
+ if options[:resource]
146
+ options.merge!(resource: options[:resource])
147
+ else
148
+ options.merge!(resource: 'b')
149
+ end
117
150
  valid_mappings.merge!(BLOB_KEY_MAPPINGS)
118
151
  elsif service_type == Azure::Storage::ServiceType::TABLE
119
- options.merge!(tablename: path)
152
+ options.merge!(table_name: path)
120
153
  valid_mappings.merge!(TABLE_KEY_MAPPINGS)
121
154
  end
122
155
 
123
156
  invalid_options = options.reject { |k,v| valid_mappings.key?(k) }
124
- raise InvalidOptionsError,"invalid options #{invalid_options} provided for SAS token generate" if invalid_options.length > 0
157
+ raise Azure::Storage::InvalidOptionsError,"invalid options #{invalid_options} provided for SAS token generate" if invalid_options.length > 0
158
+
159
+ canonicalize_time(options)
125
160
 
126
- query_hash = Hash[options.map { |k, v| [KEY_MAPPINGS[k], v] }]
127
- .reject { |k, v| OPTIONAL_QUERY_PARAMS.include?(k) && v.to_s == '' }
128
- .merge( sig: @signer.sign(signable_string(service_type, path, options)) )
161
+ query_hash = Hash[options.map { |k, v| [SERVICE_KEY_MAPPINGS[k], v] }]
162
+ .reject { |k, v| SERVICE_OPTIONAL_QUERY_PARAMS.include?(k) && v.to_s == '' }
163
+ .merge( sig: @signer.sign(signable_string_for_service(service_type, path, options)) )
129
164
 
130
165
  sas_params = URI.encode_www_form(query_hash)
131
166
  end
132
-
167
+
133
168
  # Construct the plaintext to the spec required for signatures
134
169
  # @return [String]
135
- def signable_string(service_type, path, options)
170
+ def signable_string_for_service(service_type, path, options)
136
171
  # Order is significant
137
172
  # The newlines from empty strings here are required
138
- options[:start] = Time.parse(options[:start]).utc.iso8601 if options[:start]
139
- options[:expiry] = Time.parse(options[:expiry]).utc.iso8601 if options[:expiry]
140
-
141
- signable_string =
173
+ signable_fields =
142
174
  [
143
175
  options[:permissions],
144
176
  options[:start],
145
177
  options[:expiry],
146
178
  canonicalized_resource(service_type, path),
147
179
  options[:identifier],
148
- Azure::Storage::Default::STG_VERSION,
180
+ options[:ip_range],
181
+ options[:protocol],
182
+ Azure::Storage::Default::STG_VERSION
183
+ ]
184
+
185
+ signable_fields.concat [
149
186
  options[:cache_control],
150
187
  options[:content_disposition],
151
188
  options[:content_encoding],
152
189
  options[:content_language],
153
190
  options[:content_type]
191
+ ] if service_type == Azure::Storage::ServiceType::BLOB
192
+
193
+ signable_fields.concat [
194
+ options[:startpk],
195
+ options[:startrk],
196
+ options[:endpk],
197
+ options[:endrk]
198
+ ] if service_type == Azure::Storage::ServiceType::TABLE
199
+
200
+ signable_fields.join "\n"
201
+ end
202
+
203
+ # Account Shared Access Signature Token for the given options
204
+ # @param account_name [String] storage account name
205
+ # @param options [Hash]
206
+ #
207
+ # ==== Options
208
+ #
209
+ # * +:service+ - String. Required. Accessible services. Combination of 'b' (blob), 'q' (queue), 't' (table), 'f' (file).
210
+ # * +:resource+ - String. Required. Accessible resource types. Combination of 's' (service), 'c' (container-level), 'o'(object-level).
211
+ # * +:permissions+ - String. Required. Permissions. Combination of 'r' (read), 'w' (write), 'd'(delete), 'l'(list), 'a'(add),
212
+ # 'c'(create), 'u'(update), 'p'(process). Permissions are only valid if they match
213
+ # the specified signed resource type; otherwise they are ignored.
214
+ # * +:start+ - String. Optional. UTC Date/Time in ISO8601 format.
215
+ # * +:expiry+ - String. Optional. UTC Date/Time in ISO8601 format. Default now + 30 minutes.
216
+ # * +:protocol+ - String. Optional. Permitted protocols.
217
+ # * +:ip_range+ - String. Optional. An IP address or a range of IP addresses from which to accept requests.
218
+ # When specifying a range, note that the range is inclusive.
219
+ def generate_account_sas_token(options={})
220
+ raise Azure::Storage::InvalidOptionsError,"SAS version cannot be set" if options[:version]
221
+
222
+ options = DEFAULTS.merge(options)
223
+ valid_mappings = ACCOUNT_KEY_MAPPINGS
224
+
225
+ invalid_options = options.reject { |k,v| valid_mappings.key?(k) }
226
+ raise Azure::Storage::InvalidOptionsError,"invalid options #{invalid_options} provided for SAS token generate" if invalid_options.length > 0
227
+
228
+ canonicalize_time(options)
229
+
230
+ query_hash = Hash[options.map { |k, v| [ACCOUNT_KEY_MAPPINGS[k], v] }]
231
+ .reject { |k, v| ACCOUNT_OPTIONAL_QUERY_PARAMS.include?(k) && v.to_s == '' }
232
+ .merge( sig: @signer.sign(signable_string_for_account(options)) )
233
+
234
+ sas_params = URI.encode_www_form(query_hash)
235
+ end
236
+
237
+ # Construct the plaintext to the spec required for signatures
238
+ # @return [String]
239
+ def signable_string_for_account(options)
240
+ # Order is significant
241
+ # The newlines from empty strings here are required
242
+ signable_string =
243
+ [
244
+ @account_name,
245
+ options[:permissions],
246
+ options[:service],
247
+ options[:resource],
248
+ options[:start],
249
+ options[:expiry],
250
+ options[:ip_range],
251
+ options[:protocol],
252
+ Azure::Storage::Default::STG_VERSION,
253
+ ''
154
254
  ].join("\n")
155
255
  end
156
-
256
+
157
257
  # Return the cononicalized resource representation of the blob resource
158
258
  # @return [String]
159
259
  def canonicalized_resource(service_type, path)
160
260
  "/#{service_type}/#{account_name}#{path.start_with?('/') ? '' : '/'}#{path}"
161
261
  end
162
262
 
263
+ def canonicalize_time(options)
264
+ options[:start] = Time.parse(options[:start]).utc.iso8601 if options[:start]
265
+ options[:expiry] = Time.parse(options[:expiry]).utc.iso8601 if options[:expiry]
266
+ options[:expiry] ||= (Time.now + 60*30).utc.iso8601
267
+ end
268
+
163
269
  # A customised URI reflecting options for the resource signed with Shared Access Signature
164
- # @param uri [URI] uri to resource including query options
165
- # @param options [Hash]
270
+ # @param uri [URI] uri to resource including query options
271
+ # @param use_account_sas [Boolean] Whether uses account SAS
272
+ # @param options [Hash]
166
273
  #
167
274
  # ==== Options
168
275
  #
169
- # * +:permissions+ - String. Combination of 'r','w','d','l' (container only) in this order. Default 'r'
170
- # * +:start+ - String. UTC Date/Time in ISO8601 format. Optional.
171
- # * +:expiry+ - String. UTC Date/Time in ISO8601 format. Optional. Default now + 30 minutes.
172
- # * +:identifier+ - String. Identifier for stored access policy. Optional
276
+ # * +:start+ - String. Optional. UTC Date/Time in ISO8601 format.
277
+ # * +:expiry+ - String. Optional. UTC Date/Time in ISO8601 format. Default now + 30 minutes.
278
+ # * +:protocol+ - String. Optional. Permitted protocols.
279
+ # * +:ip_range+ - String. Optional. An IP address or a range of IP addresses from which to accept requests.
280
+ # When specifying a range, note that the range is inclusive.
281
+ #
282
+ # Below options for account SAS only
283
+ # * +:service+ - String. Required. Accessible services. Combination of 'b' (blob), 'q' (queue), 't' (table), 'f' (file).
284
+ # * +:resource+ - String. Required. Accessible resource types. Combination of 's' (service), 'c' (container-level), 'o'(object-level).
285
+ # * +:permissions+ - String. Required. Permissions. Combination of 'r' (read), 'w' (write), 'd'(delete), 'l'(list), 'a'(add),
286
+ # 'c'(create), 'u'(update), 'p'(process). Permissions are only valid if they match
287
+ # the specified signed resource type; otherwise they are ignored.
288
+ #
289
+ # Below options for service SAS only
290
+ # * +:service+ - String. Required. Service type. 'b' (blob) or 'q' (queue) or 't' (table) or 'f' (file).
291
+ # * +:resource+ - String. Required. Resource type, 'b' (blob) or 'c' (container) or 'f' (file) or 's' (share).
292
+ # * +:identifier+ - String. Optional. Identifier for stored access policy.
293
+ # * +:permissions+ - String. Optional. Combination of 'r', 'a', 'c', w','d','l' in this order for a container.
294
+ # Combination of 'r', 'a', 'c', 'w', 'd' in this order for a blob.
295
+ # Combination of 'r', 'c', 'w', 'd', 'l' in this order for a share.
296
+ # Combination of 'r', 'c', 'w', 'd' in this order for a file.
297
+ # Combination of 'r', 'a', 'u', 'p' in this order for a queue.
298
+ # Combination of 'r', 'a', 'u', 'd' in this order for a table.
173
299
  #
174
- # Below options for Blob only
175
- # * +:resource+ - String. Resource type, either 'b' (blob) or 'c' (container). Default 'b'
176
- # * +:cache_control+ - String. Response header override. Optional.
177
- # * +:content_disposition+ - String. Response header override. Optional.
178
- # * +:content_encoding+ - String. Response header override. Optional.
179
- # * +:content_language+ - String. Response header override. Optional.
180
- # * +:content_type+ - String. Response header override. Optional.
300
+ # Below options for Blob service only
301
+ # * +:cache_control+ - String. Optional. Response header override.
302
+ # * +:content_disposition+ - String. Optional. Response header override.
303
+ # * +:content_encoding+ - String. Optional. Response header override.
304
+ # * +:content_language+ - String. Optional. Response header override.
305
+ # * +:content_type+ - String. Optional. Response header override.
181
306
  #
182
- # Below options for table only
183
- # * +:tablename+ - String. Table name for SAS
184
- # * +:startpk+ - String. The start partition key of a specified partition key range. Optional but startpk must accompany startrk.
185
- # * +:endpk+ - String. The end partition key of a specified partition key range. Optional but endpk must accompany endrk.
186
- # * +:startrk+ - String. The start row key of a specified row key range. Optional.
187
- # * +:endrk+ - String. The end row key of a specified row key range. Optional.
188
- def signed_uri(uri, options)
307
+ # Below options for Table service only
308
+ # * +:table_name+ - String. Required. Table name for SAS.
309
+ # * +:startpk+ - String. Optional but must accompany startrk. The start partition key of a specified partition key range.
310
+ # * +:endpk+ - String. Optional but must accompany endrk. The end partition key of a specified partition key range.
311
+ # * +:startrk+ - String. Optional. The start row key of a specified row key range.
312
+ # * +:endrk+ - String. Optional. The end row key of a specified row key range.
313
+ def signed_uri(uri, use_account_sas, options)
189
314
  parsed_query = CGI::parse(uri.query || '').inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
190
-
191
- if parsed_query.has_key?(:restype)
192
- options[:resource] = parsed_query[:restype].first == 'container' ? 'c' : 'b'
193
- end
194
315
 
195
316
  if options[:service_type] == nil and uri.host != nil
196
317
  host_splits = uri.host.split('.')
197
- options[:service_type] = host_splits[1] if host_splits.length > 1 && host_splits[0] == account_name
318
+ options[:service_type] = host_splits[1] if host_splits.length > 1 && host_splits[0] == @account_name
198
319
  end
199
320
 
200
- sas_params = generate(uri.path, options)
321
+ sas_params = if use_account_sas
322
+ generate_account_sas_token(options)
323
+ else
324
+ generate_service_sas_token(uri.path, options)
325
+ end
201
326
 
202
- URI.parse(uri.to_s + (uri.query.nil? ? '?' : '&') + sas_params)
327
+ result = URI.parse(uri.to_s + (uri.query.nil? ? '?' : '&') + sas_params)
203
328
  end
204
-
205
329
  end
206
330
  end
207
331
  end
@@ -24,7 +24,7 @@
24
24
 
25
25
  require 'azure/core/auth/signer'
26
26
 
27
- module Azure::Storage
27
+ module Azure::Storage::Core
28
28
  module Auth
29
29
  class SharedAccessSignatureSigner < Azure::Core::Auth::Signer
30
30
 
@@ -40,8 +40,7 @@ module Azure::Storage
40
40
  end
41
41
 
42
42
  def sign_request(req)
43
- ori_uri = req.uri
44
- URI.parse(ori_uri.to_s + (ori_uri.query.nil? ? '?' : '&') + sas_token.sub(/^\?/,'') + '&api-version=' + Azure::Storage::Default::STG_VERSION)
43
+ req.uri = URI.parse(req.uri.to_s + (req.uri.query.nil? ? '?' : '&') + sas_token.sub(/^\?/,'') + '&api-version=' + Azure::Storage::Default::STG_VERSION)
45
44
  end
46
45
 
47
46
  end
@@ -23,6 +23,7 @@
23
23
  #--------------------------------------------------------------------------
24
24
  require 'cgi'
25
25
  require 'azure/core/auth/signer'
26
+ require 'azure/core/auth/shared_key'
26
27
 
27
28
  module Azure::Storage::Core
28
29
  module Auth
@@ -32,6 +32,8 @@ module Azure
32
32
 
33
33
  module Auth
34
34
  autoload :SharedKey, 'azure/storage/core/auth/shared_key.rb'
35
+ autoload :SharedAccessSignature, 'azure/storage/core/auth/shared_access_signature_generator.rb'
36
+ autoload :SharedAccessSignatureSigner, 'azure/storage/core/auth/shared_access_signature_signer.rb'
35
37
  end
36
38
 
37
39
  module Filter
@@ -98,6 +98,12 @@ module Azure::Storage
98
98
  ENV['AZURE_STORAGE_CONNECTION_STRING']
99
99
  end
100
100
 
101
+ # Default storage shared access signature token
102
+ # @return [String]
103
+ def storage_sas_token
104
+ ENV['AZURE_STORAGE_SAS_TOKEN']
105
+ end
106
+
101
107
  # Default storage table host
102
108
  # @return [String]
103
109
  def storage_table_host
@@ -124,7 +130,7 @@ module Azure::Storage
124
130
  end
125
131
  end
126
132
 
127
- # ServiceType prefix to suffix
133
+ # Service Types
128
134
  module ServiceType
129
135
  BLOB = 'blob'
130
136
  QUEUE = 'queue'
@@ -1074,4 +1080,4 @@ module Azure::Storage
1074
1080
  NOT_IMPLEMENTED = 'NotImplemented'
1075
1081
  end
1076
1082
 
1077
- end
1083
+ end
@@ -21,6 +21,7 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
  #--------------------------------------------------------------------------
24
+ require 'azure/storage/core/auth/shared_key'
24
25
  require 'azure/storage/service/storage_service'
25
26
  require 'azure/storage/queue/serialization'
26
27
 
@@ -30,7 +31,9 @@ module Azure::Storage
30
31
  class QueueService < StorageService
31
32
 
32
33
  def initialize(options = {})
33
- super(nil, nil, options)
34
+ client_config = options[:client] || Azure::Storage
35
+ signer = options[:signer] || Azure::Storage::Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
36
+ super(signer, client_config.storage_account_name, options)
34
37
  @host = @client.storage_queue_host
35
38
  end
36
39
 
@@ -33,4 +33,4 @@ module Azure::Storage
33
33
  attr_accessor :cors_rules
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -43,4 +43,4 @@ module Azure::Storage
43
43
  attr_accessor :allowed_headers
44
44
  end
45
45
  end
46
- end
46
+ end
@@ -34,14 +34,17 @@ module Azure::Storage
34
34
  #
35
35
  # @param signer [Azure::Core::Auth::Signer] An implementation of Signer used for signing requests.
36
36
  # (optional, Default=Azure::Storage::Auth::SharedKey.new)
37
- # @param account_name [String] The account name (optional, Default=Azure.config.storage_account_name)
37
+ # @param account_name [String] The account name (optional, Default=Azure::Storage.storage_account_name)
38
38
  # @param options [Azure::Storage::Configurable] the client configuration context
39
39
  def initialize(signer=nil, account_name=nil, options = {})
40
40
  options[:client] = Azure::Storage if options[:client] == nil
41
41
  client_config = options[:client]
42
42
  signer = signer || Azure::Storage::Core::Auth::SharedKey.new(
43
43
  client_config.storage_account_name,
44
- client_config.storage_access_key)
44
+ client_config.storage_access_key) if client_config.storage_access_key
45
+ signer = signer || Azure::Storage::Core::Auth::SharedAccessSignatureSigner.new(
46
+ client_config.storage_account_name,
47
+ client_config.storage_sas_token)
45
48
  super(signer, account_name, options)
46
49
  end
47
50
 
@@ -21,7 +21,7 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
  #--------------------------------------------------------------------------
24
- require 'uuid'
24
+ require 'securerandom'
25
25
 
26
26
  require 'azure/core/http/http_error'
27
27
  require 'azure/storage/table/serialization'
@@ -63,9 +63,8 @@ module Azure::Storage
63
63
  @operations = []
64
64
  @entity_keys = []
65
65
  @table_service = Azure::Storage::Table::TableService.new
66
- uuid = UUID.new
67
- @batch_id = "batch_" + uuid.generate
68
- @changeset_id = "changeset_" + uuid.generate
66
+ @batch_id = "batch_" + SecureRandom.uuid
67
+ @changeset_id = "changeset_" + SecureRandom.uuid
69
68
 
70
69
  self.instance_eval(&block) if block_given?
71
70
  end
@@ -310,7 +310,9 @@ module Azure::Storage
310
310
  query = { }
311
311
  query["timeout"] = options[:timeout].to_s if options[:timeout]
312
312
 
313
- uri = entities_uri(table_name, entity_values["PartitionKey"], entity_values["RowKey"], query)
313
+ uri = entities_uri(table_name,
314
+ entity_values[:PartitionKey] || entity_values['PartitionKey'],
315
+ entity_values[:RowKey] || entity_values["RowKey"], query)
314
316
 
315
317
  headers = {}
316
318
  headers["If-Match"] = if_match || "*" unless options[:create_if_not_exists]
@@ -348,7 +350,9 @@ module Azure::Storage
348
350
  query = { }
349
351
  query["timeout"] = options[:timeout].to_s if options[:timeout]
350
352
 
351
- uri = entities_uri(table_name, entity_values["PartitionKey"], entity_values["RowKey"], query)
353
+ uri = entities_uri(table_name,
354
+ entity_values[:PartitionKey] || entity_values['PartitionKey'],
355
+ entity_values[:RowKey] || entity_values['RowKey'], query)
352
356
 
353
357
  headers = { "X-HTTP-Method"=> "MERGE" }
354
358
  headers["If-Match"] = if_match || "*" unless options[:create_if_not_exists]
@@ -27,8 +27,8 @@ module Azure
27
27
  class Version
28
28
  # Fields represent the parts defined in http://semver.org/
29
29
  MAJOR = 0 unless defined? MAJOR
30
- MINOR = 10 unless defined? MINOR
31
- UPDATE = 2 unless defined? UPDATE
30
+ MINOR = 11 unless defined? MINOR
31
+ UPDATE = 0 unless defined? UPDATE
32
32
  PRE = 'preview' unless defined? PRE
33
33
 
34
34
  class << self
@@ -43,4 +43,4 @@ module Azure
43
43
  end
44
44
  end
45
45
  end
46
- end
46
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2.preview
4
+ version: 0.11.0.preview
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-30 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.19'
139
- - !ruby/object:Gem::Dependency
140
- name: uuid
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '2.0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '2.0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: dotenv
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -297,7 +283,6 @@ files:
297
283
  - lib/azure/storage/service/storage_service.rb
298
284
  - lib/azure/storage/service/storage_service_properties.rb
299
285
  - lib/azure/storage/table/auth/shared_key.rb
300
- - lib/azure/storage/table/auth/shared_key_lite.rb
301
286
  - lib/azure/storage/table/batch.rb
302
287
  - lib/azure/storage/table/batch_response.rb
303
288
  - lib/azure/storage/table/edmtype.rb
@@ -327,9 +312,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
312
  version: 1.3.1
328
313
  requirements: []
329
314
  rubyforge_project:
330
- rubygems_version: 2.4.6
315
+ rubygems_version: 2.5.1
331
316
  signing_key:
332
317
  specification_version: 4
333
318
  summary: Official Ruby client library to consume Azure Storage services
334
319
  test_files: []
335
- has_rdoc:
@@ -1,53 +0,0 @@
1
- #-------------------------------------------------------------------------
2
- # # Copyright (c) Microsoft and contributors. All rights reserved.
3
- #
4
- # The MIT License(MIT)
5
-
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files(the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions :
12
-
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
-
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
- #--------------------------------------------------------------------------
24
- require 'azure/storage/table/auth/shared_key'
25
-
26
- module Azure::Storage
27
- module Table
28
- module Auth
29
- class SharedKeyLite < SharedKey
30
- # Public: The name of the strategy.
31
- #
32
- # Returns a String.
33
- def name
34
- 'SharedKeyLite'
35
- end
36
-
37
- # Generate the string to sign.
38
- #
39
- # verb - The HTTP request method.
40
- # uri - The URI of the request we're signing.
41
- # headers - A Hash of HTTP request headers.
42
- #
43
- # Returns a plain text string.
44
- def signable_string(method, uri, headers)
45
- [
46
- headers.fetch('Date') { headers.fetch('x-ms-date') },
47
- canonicalized_resource(uri)
48
- ].join("\n")
49
- end
50
- end
51
- end
52
- end
53
- end