azure-storage 0.10.0.preview → 0.10.1.preview

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azure/storage/autoload.rb +2 -4
  3. data/lib/azure/storage/blob/blob_service.rb +2 -5
  4. data/lib/azure/storage/blob/container.rb +5 -1
  5. data/lib/azure/storage/client.rb +4 -4
  6. data/lib/azure/storage/{core/client_options.rb → client_options.rb} +1 -2
  7. data/lib/azure/storage/{core/client_options_error.rb → client_options_error.rb} +2 -2
  8. data/lib/azure/storage/core.rb +1 -1
  9. data/lib/azure/storage/core/auth/shared_access_signature.rb +3 -2
  10. data/lib/azure/storage/core/auth/shared_access_signature_generator.rb +31 -18
  11. data/lib/azure/storage/core/auth/shared_access_signature_signer.rb +1 -1
  12. data/lib/azure/storage/core/auth/shared_key.rb +4 -72
  13. data/lib/azure/storage/core/autoload.rb +17 -8
  14. data/lib/azure/storage/core/error.rb +2 -8
  15. data/lib/azure/storage/core/filter/exponential_retry_filter.rb +62 -0
  16. data/lib/azure/storage/core/{auth/shared_key_lite.rb → filter/linear_retry_filter.rb} +27 -29
  17. data/lib/azure/storage/core/filter/retry_filter.rb +172 -0
  18. data/lib/azure/storage/core/http_client.rb +1 -1
  19. data/lib/azure/storage/core/utility.rb +2 -10
  20. data/lib/azure/storage/{core/constants.rb → default.rb} +0 -0
  21. data/lib/azure/storage/service/storage_service.rb +7 -2
  22. data/lib/azure/storage/table/auth/shared_key.rb +2 -2
  23. data/lib/azure/storage/table/batch.rb +1 -1
  24. data/lib/azure/storage/table/table_service.rb +11 -11
  25. data/lib/azure/storage/version.rb +1 -1
  26. metadata +24 -18
  27. data/lib/azure/storage/core/auth/signer.rb +0 -60
  28. data/lib/azure/storage/core/filtered_service.rb +0 -54
  29. data/lib/azure/storage/core/http/debug_filter.rb +0 -45
  30. data/lib/azure/storage/core/http/http_error.rb +0 -95
  31. data/lib/azure/storage/core/http/http_filter.rb +0 -62
  32. data/lib/azure/storage/core/http/http_request.rb +0 -182
  33. data/lib/azure/storage/core/http/http_response.rb +0 -105
  34. data/lib/azure/storage/core/http/retry_policy.rb +0 -83
  35. data/lib/azure/storage/core/http/signer_filter.rb +0 -42
  36. data/lib/azure/storage/core/service.rb +0 -55
  37. data/lib/azure/storage/core/signed_service.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81d51da25ec4fc5a5f0bf93a3c071b255f94e3e2
4
- data.tar.gz: e4f064f2875bc72613c86c92ae31cfe18e534bec
3
+ metadata.gz: 68f699e6dbd6ceed52d8c35694a78d9c852ea5a0
4
+ data.tar.gz: 21e079f0fab409af5260dd228e1a3ec7e05d180c
5
5
  SHA512:
6
- metadata.gz: c44444db774de77bf408448be653708a0e678d2fd57a2610a44204c185c0a38878c467c6f9a5831e4852322c57dbe8745b231e6c3890fa847a24d98851117478
7
- data.tar.gz: afddf25b3f04414d2842fcb718efa05af2bd270ea137dafc6bdb4470c8894f2e60eba17442cf688ced49ad3ad2ac7cb5b3ff6ebf26b72579a3c8f33c0e5c380d
6
+ metadata.gz: c15b3eb7927d1856e98f0a36cfd543885d5bfedc6d4986d01147a234f0b016169683a66974126aa1b22bf9341547ad6f89708c4b848526d128666c5222433701
7
+ data.tar.gz: 4f9cf1548ad8e0761671dfba0835a71367544e3018c02b06b44ccd185af42ff0056a181f029aa291a8c79fe4e6b555a227cc85ca882618b1a0777873f4cc8caa
@@ -29,15 +29,13 @@ module Azure
29
29
  autoload :Storage, 'azure/storage/core'
30
30
 
31
31
  module Storage
32
- autoload :Default, 'azure/storage/core/constants'
32
+ autoload :Default, 'azure/storage/default'
33
33
  autoload :Configurable, 'azure/storage/configurable'
34
34
  autoload :Client, 'azure/storage/client'
35
- autoload :ClientOptions, 'azure/storage/core/client_options'
35
+ autoload :ClientOptions, 'azure/storage/client_options'
36
36
 
37
37
  module Auth
38
38
  autoload :SharedAccessSignature, 'azure/storage/core/auth/shared_access_signature'
39
- autoload :SharedKey, 'azure/storage/core/auth/shared_key'
40
- autoload :SharedKeyLite, 'azure/storage/core/auth/shared_key_lite'
41
39
  end
42
40
 
43
41
  module Service
@@ -30,17 +30,14 @@ require 'azure/storage/blob/append'
30
30
 
31
31
  module Azure::Storage
32
32
  include Service
33
+
33
34
  module Blob
34
35
  class BlobService < StorageService
35
36
  include Azure::Storage::Blob
36
37
  include Azure::Storage::Blob::Container
37
38
 
38
39
  def initialize(options = {})
39
- client_config = options[:client] || Azure::Storage
40
- signer = options[:signer] || Auth::SharedKey.new(
41
- client_config.storage_account_name,
42
- client_config.storage_access_key)
43
- super(signer, client_config.storage_account_name, options)
40
+ super(nil, nil, options)
44
41
  @host = client.storage_blob_host
45
42
  end
46
43
 
@@ -545,7 +545,11 @@ module Azure::Storage::Blob
545
545
  response = call(:get, uri)
546
546
 
547
547
  # Result
548
- Serialization.blob_enumeration_results_from_xml(response.body)
548
+ if response.success?
549
+ Serialization.blob_enumeration_results_from_xml(response.body)
550
+ else
551
+ response.exception
552
+ end
549
553
  end
550
554
 
551
555
  end
@@ -22,10 +22,10 @@
22
22
  # THE SOFTWARE.
23
23
  #--------------------------------------------------------------------------
24
24
 
25
+ require 'azure/storage/core'
25
26
  require 'azure/storage/core/http_client'
26
27
 
27
- require 'azure/storage/core'
28
- require 'azure/storage/core/client_options'
28
+ require 'azure/storage/client_options'
29
29
 
30
30
  require 'azure/storage/blob/blob_service'
31
31
  require 'azure/storage/table/table_service'
@@ -35,7 +35,7 @@ module Azure::Storage
35
35
  class Client
36
36
  include Azure::Storage::Configurable
37
37
  include Azure::Storage::ClientOptions
38
- include Azure::Core::HttpClient
38
+ include Azure::Storage::Core::HttpClient
39
39
 
40
40
  # Public: Creates an instance of [Azure::Storage::Client]
41
41
  #
@@ -178,7 +178,7 @@ module Azure::Storage
178
178
  private
179
179
 
180
180
  def default_client(opts)
181
- {client: self}.merge(opts || {})
181
+ !opts.empty? ? {client: Azure::Storage.client(opts)} : {client: self}
182
182
  end
183
183
 
184
184
  end
@@ -23,8 +23,7 @@
23
23
  #--------------------------------------------------------------------------
24
24
 
25
25
  require 'uri'
26
- require 'azure/storage/core'
27
- require 'azure/storage/core/client_options_error'
26
+ require 'azure/storage/client_options_error'
28
27
 
29
28
  module Azure::Storage
30
29
  module ClientOptions
@@ -24,13 +24,13 @@
24
24
 
25
25
  module Azure::Storage
26
26
 
27
- class InvalidConnectionStringError < StorageError
27
+ class InvalidConnectionStringError < Core::StorageError
28
28
  def initialize(message = SR::INVALID_CONNECTION_STRING)
29
29
  super(message)
30
30
  end
31
31
  end
32
32
 
33
- class InvalidOptionsError < StorageError
33
+ class InvalidOptionsError < Core::StorageError
34
34
  def initialize(message = SR::INVALID_CLIENT_OPTIONS)
35
35
  super(message)
36
36
  end
@@ -28,6 +28,6 @@ module Azure
28
28
  end
29
29
 
30
30
  require 'azure/storage/core/error'
31
- require 'azure/storage/core/constants'
31
+ require 'azure/storage/default'
32
32
  require 'azure/storage/core/sr'
33
33
  require 'azure/storage/core/utility'
@@ -22,6 +22,7 @@
22
22
  # THE SOFTWARE.
23
23
  #--------------------------------------------------------------------------
24
24
 
25
-
26
25
  require 'azure/storage/core/auth/shared_access_signature_generator'
27
- require 'azure/storage/core/auth/shared_access_signature_signer'
26
+ require 'azure/storage/core/auth/shared_access_signature_signer'
27
+
28
+ include Azure::Storage::Auth
@@ -23,8 +23,8 @@
23
23
  #--------------------------------------------------------------------------
24
24
 
25
25
  require 'azure/storage/core'
26
- require 'azure/storage/core/client_options_error'
27
- require 'azure/storage/core/auth/signer'
26
+ require 'azure/storage/client_options_error'
27
+ require 'azure/core/auth/signer'
28
28
  require 'time'
29
29
  require 'uri'
30
30
 
@@ -104,47 +104,60 @@ module Azure::Storage
104
104
  service_type = options[:service_type] || Azure::Storage::ServiceType::BLOB
105
105
  options.delete(:service_type) if options.key?(:service_type)
106
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]
107
109
  options[:expiry] ||= (Time.now + 60*30).utc.iso8601
108
110
 
109
111
  raise InvalidOptionsError,"SAS version cannot be set" if options[:version]
110
112
 
111
- defs = DEFAULTS
113
+ options = DEFAULTS.merge(options)
112
114
  valid_mappings = KEY_MAPPINGS
113
115
  if service_type == Azure::Storage::ServiceType::BLOB
114
- defs.merge!(resource: 'b')
116
+ options.merge!(resource: 'b')
115
117
  valid_mappings.merge!(BLOB_KEY_MAPPINGS)
116
118
  elsif service_type == Azure::Storage::ServiceType::TABLE
117
- defs.merge!(tablename: path)
119
+ options.merge!(tablename: path)
118
120
  valid_mappings.merge!(TABLE_KEY_MAPPINGS)
119
121
  end
120
122
 
121
123
  invalid_options = options.reject { |k,v| valid_mappings.key?(k) }
122
124
  raise InvalidOptionsError,"invalid options #{invalid_options} provided for SAS token generate" if invalid_options.length > 0
123
125
 
124
- options.merge!(defs)
125
-
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)) )
129
+
130
+ sas_params = URI.encode_www_form(query_hash)
131
+ end
132
+
133
+ # Construct the plaintext to the spec required for signatures
134
+ # @return [String]
135
+ def signable_string(service_type, path, options)
126
136
  # Order is significant
127
137
  # 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
+
128
141
  signable_string =
129
142
  [
130
143
  options[:permissions],
131
144
  options[:start],
132
145
  options[:expiry],
133
- "/#{service_type}/#{account_name}#{path.start_with?('/') ? '' : '/'}#{path}",
146
+ canonicalized_resource(service_type, path),
134
147
  options[:identifier],
135
- options[:version],
148
+ Azure::Storage::Default::STG_VERSION,
136
149
  options[:cache_control],
137
150
  options[:content_disposition],
138
151
  options[:content_encoding],
139
152
  options[:content_language],
140
153
  options[:content_type]
141
154
  ].join("\n")
142
-
143
- query_hash = Hash[options.map { |k, v| [KEY_MAPPINGS[k], v] }]
144
- .reject { |k, v| OPTIONAL_QUERY_PARAMS.include?(k) && v.to_s == '' }
145
- .merge( sig: @signer.sign(signable_string) )
146
-
147
- sas_params = URI.encode_www_form(query_hash)
155
+ end
156
+
157
+ # Return the cononicalized resource representation of the blob resource
158
+ # @return [String]
159
+ def canonicalized_resource(service_type, path)
160
+ "/#{service_type}/#{account_name}#{path.start_with?('/') ? '' : '/'}#{path}"
148
161
  end
149
162
 
150
163
  # A customised URI reflecting options for the resource signed with Shared Access Signature
@@ -172,14 +185,14 @@ module Azure::Storage
172
185
  # * +:endpk+ - String. The end partition key of a specified partition key range. Optional but endpk must accompany endrk.
173
186
  # * +:startrk+ - String. The start row key of a specified row key range. Optional.
174
187
  # * +:endrk+ - String. The end row key of a specified row key range. Optional.
175
- def sign_uri(uri, options)
188
+ def signed_uri(uri, options)
176
189
  parsed_query = CGI::parse(uri.query || '').inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
177
-
190
+
178
191
  if parsed_query.has_key?(:restype)
179
192
  options[:resource] = parsed_query[:restype].first == 'container' ? 'c' : 'b'
180
193
  end
181
194
 
182
- if options[:service_type] == nil
195
+ if options[:service_type] == nil and uri.host != nil
183
196
  host_splits = uri.host.split('.')
184
197
  options[:service_type] = host_splits[1] if host_splits.length > 1 && host_splits[0] == account_name
185
198
  end
@@ -22,7 +22,7 @@
22
22
  # THE SOFTWARE.
23
23
  #--------------------------------------------------------------------------
24
24
 
25
- require 'azure/storage/core/auth/signer'
25
+ require 'azure/core/auth/signer'
26
26
 
27
27
  module Azure::Storage
28
28
  module Auth
@@ -22,53 +22,11 @@
22
22
  # THE SOFTWARE.
23
23
  #--------------------------------------------------------------------------
24
24
  require 'cgi'
25
- require 'azure/storage/core/auth/signer'
25
+ require 'azure/core/auth/signer'
26
26
 
27
- module Azure::Storage
27
+ module Azure::Storage::Core
28
28
  module Auth
29
- class SharedKey < Azure::Core::Auth::Signer
30
- # The Azure account's name.
31
- attr :account_name
32
-
33
- # Initialize the Signer.
34
- #
35
- # @param account_name [String] The account name. Defaults to the one in the
36
- # global configuration.
37
- # @param access_key [String] The access_key encoded in Base64. Defaults to the
38
- # one in the global configuration.
39
- def initialize(account_name=Azure::Storage.config.storage_account_name, access_key=Azure::Storage.config.storage_access_key)
40
- @account_name = account_name
41
- super(access_key)
42
- end
43
-
44
- # The name of the strategy.
45
- #
46
- # @return [String]
47
- def name
48
- 'SharedKey'
49
- end
50
-
51
- # Create the signature for the request parameters
52
- #
53
- # @param method [Symbol] HTTP request method.
54
- # @param uri [URI] URI of the request we're signing.
55
- # @param headers [Hash] HTTP request headers.
56
- #
57
- # @return [String] base64 encoded signature
58
- def sign(method, uri, headers)
59
- "#{account_name}:#{super(signable_string(method, uri, headers))}"
60
- end
61
-
62
- # Sign the request
63
- #
64
- # @param req [Azure::Core::Http::HttpRequest] HTTP request to sign
65
- #
66
- # @return [Azure::Core::Http::HttpRequest]
67
- def sign_request(req)
68
- req.headers['Authorization'] = "#{name} #{sign(req.method, req.uri, req.headers)}"
69
- req
70
- end
71
-
29
+ class SharedKey < Azure::Core::Auth::SharedKey
72
30
  # Generate the string to sign.
73
31
  #
74
32
  # @param method [Symbol] HTTP request method.
@@ -94,32 +52,6 @@ module Azure::Storage
94
52
  canonicalized_resource(uri)
95
53
  ].join("\n")
96
54
  end
97
-
98
- # Calculate the Canonicalized Headers string for a request.
99
- #
100
- # @param headers [Hash] HTTP request headers.
101
- #
102
- # @return [String] a string with the canonicalized headers.
103
- def canonicalized_headers(headers)
104
- headers = headers.map { |k,v| [k.to_s.downcase, v] }
105
- headers.select! { |k,v| k =~ /^x-ms-/ }
106
- headers.sort_by! { |(k,v)| k }
107
- headers.map! { |k,v| '%s:%s' % [k, v] }
108
- headers.map! { |h| h.gsub(/\s+/, ' ') }.join("\n")
109
- end
110
-
111
- # Calculate the Canonicalized Resource string for a request.
112
- #
113
- # @param uri [URI] URI of the request we're signing.
114
- #
115
- # @return [String] a string with the canonicalized resource.
116
- def canonicalized_resource(uri)
117
- resource = '/' + account_name + (uri.path.empty? ? '/' : uri.path)
118
- params = CGI.parse(uri.query.to_s).map { |k,v| [k.downcase, v] }
119
- params.sort_by! { |k,v| k }
120
- params.map! { |k,v| '%s:%s' % [k, v.map(&:strip).sort.join(',')] }
121
- [resource, *params].join("\n")
122
- end
123
55
  end
124
56
  end
125
- end
57
+ end
@@ -23,13 +23,22 @@
23
23
  #--------------------------------------------------------------------------
24
24
 
25
25
  module Azure
26
- module Core
27
- autoload :HttpClient, 'azure/storage/core/http_client'
28
- autoload :Utility, 'azure/storage/core/utility'
29
- autoload :Logger, 'azure/storage/core/utility'
30
- autoload :Error, 'azure/storage/core/error'
31
- autoload :Service, 'azure/storage/core/service'
32
- autoload :FilteredService, 'azure/storage/core/filtered_service'
33
- autoload :SignedService, 'azure/storage/core/signed_service'
26
+ module Storage
27
+ module Core
28
+ autoload :HttpClient, 'azure/storage/core/http_client'
29
+ autoload :Utility, 'azure/storage/core/utility'
30
+ autoload :Logger, 'azure/storage/core/utility'
31
+ autoload :Error, 'azure/storage/core/error'
32
+
33
+ module Auth
34
+ autoload :SharedKey, 'azure/storage/core/auth/shared_key.rb'
35
+ end
36
+
37
+ module Filter
38
+ autoload :RetryPolicyFilter, 'azure/storage/core/filter/retry_filter'
39
+ autoload :LinearRetryPolicyFilter, 'azure/storage/core/filter/linear_retry_filter'
40
+ autoload :ExponentialRetryPolicyFilter, 'azure/storage/core/filter/exponential_retry_filter'
41
+ end
42
+ end
34
43
  end
35
44
  end
@@ -21,15 +21,9 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
  #--------------------------------------------------------------------------
24
- module Azure
25
- module Core
26
- # Superclass for errors generated from this library, so people can
27
- # just rescue this for generic error handling
28
- class Error < StandardError;end
29
- end
30
- end
24
+ require 'azure/core'
31
25
 
32
- module Azure::Storage
26
+ module Azure::Storage::Core
33
27
  # Superclass for errors generated from this library, so people can
34
28
  # just rescue this for generic error handling
35
29
  class StorageError < StandardError
@@ -0,0 +1,62 @@
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/core'
25
+ require 'azure/core/http/retry_policy'
26
+
27
+ module Azure::Storage::Core::Filter
28
+ class ExponentialRetryPolicyFilter < RetryPolicyFilter
29
+ def initialize(retry_count=nil, min_retry_interval=nil, max_retry_interval=nil)
30
+ @retry_count = retry_count || ExponentialRetryPolicyFilter::DEFAULT_RETRY_COUNT
31
+ @min_retry_interval = min_retry_interval || ExponentialRetryPolicyFilter::DEFAULT_MIN_RETRY_INTERVAL
32
+ @max_retry_interval = max_retry_interval || ExponentialRetryPolicyFilter::DEFAULT_MAX_RETRY_INTERVAL
33
+
34
+ super @retry_count, @min_retry_interval
35
+ end
36
+
37
+ attr_reader :min_retry_interval,
38
+ :max_retry_interval
39
+
40
+ DEFAULT_RETRY_COUNT = 3
41
+ DEFAULT_MIN_RETRY_INTERVAL = 10
42
+ DEFAULT_MAX_RETRY_INTERVAL = 90
43
+
44
+ # Overrides the base class implementation of call to determine
45
+ # how the HTTP request should continue retrying
46
+ #
47
+ # retry_data - Hash. Stores stateful retry data
48
+ #
49
+ # The retry_data is a Hash which can be used to store
50
+ # stateful data about the request execution context (such as an
51
+ # incrementing counter, timestamp, etc). The retry_data object
52
+ # will be the same instance throughout the lifetime of the request
53
+ def apply_retry_policy(retry_data)
54
+ # Adjust retry count
55
+ retry_data[:count] = retry_data[:count] === nil ? 1 : retry_data[:count] + 1
56
+
57
+ # Adjust retry interval
58
+ increment_delta = (@max_retry_interval - @min_retry_interval).fdiv(2 ** (@retry_count - 1)) * (2 ** (retry_data[:count] - 1));
59
+ retry_data[:interval] = retry_data[:interval] === nil ? @min_retry_interval : [@min_retry_interval + increment_delta, @max_retry_interval].min;
60
+ end
61
+ end
62
+ end