azure-storage 0.13.0.preview → 0.14.0.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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azure/storage.rb +14 -13
  3. data/lib/azure/storage/autoload.rb +31 -31
  4. data/lib/azure/storage/blob/append.rb +43 -41
  5. data/lib/azure/storage/blob/blob.rb +150 -147
  6. data/lib/azure/storage/blob/blob_service.rb +186 -184
  7. data/lib/azure/storage/blob/block.rb +56 -56
  8. data/lib/azure/storage/blob/container.rb +93 -92
  9. data/lib/azure/storage/blob/page.rb +187 -104
  10. data/lib/azure/storage/blob/serialization.rb +32 -18
  11. data/lib/azure/storage/client.rb +18 -17
  12. data/lib/azure/storage/client_options.rb +192 -193
  13. data/lib/azure/storage/client_options_error.rb +5 -5
  14. data/lib/azure/storage/configurable.rb +39 -39
  15. data/lib/azure/storage/core.rb +6 -4
  16. data/lib/azure/storage/core/auth/shared_access_signature.rb +5 -3
  17. data/lib/azure/storage/core/auth/shared_access_signature_generator.rb +34 -33
  18. data/lib/azure/storage/core/auth/shared_access_signature_signer.rb +5 -5
  19. data/lib/azure/storage/core/auth/shared_key.rb +17 -15
  20. data/lib/azure/storage/core/autoload.rb +15 -13
  21. data/lib/azure/storage/core/error.rb +3 -1
  22. data/lib/azure/storage/core/filter/exponential_retry_filter.rb +13 -11
  23. data/lib/azure/storage/core/filter/linear_retry_filter.rb +10 -8
  24. data/lib/azure/storage/core/filter/retry_filter.rb +30 -29
  25. data/lib/azure/storage/core/http_client.rb +18 -16
  26. data/lib/azure/storage/core/sr.rb +50 -48
  27. data/lib/azure/storage/core/utility.rb +19 -17
  28. data/lib/azure/storage/default.rb +371 -361
  29. data/lib/azure/storage/file/directory.rb +36 -31
  30. data/lib/azure/storage/file/file.rb +103 -100
  31. data/lib/azure/storage/file/file_service.rb +42 -40
  32. data/lib/azure/storage/file/serialization.rb +9 -6
  33. data/lib/azure/storage/file/share.rb +48 -46
  34. data/lib/azure/storage/queue/message.rb +3 -1
  35. data/lib/azure/storage/queue/queue.rb +3 -2
  36. data/lib/azure/storage/queue/queue_service.rb +152 -151
  37. data/lib/azure/storage/queue/serialization.rb +7 -5
  38. data/lib/azure/storage/service/access_policy.rb +3 -1
  39. data/lib/azure/storage/service/cors.rb +4 -2
  40. data/lib/azure/storage/service/cors_rule.rb +3 -1
  41. data/lib/azure/storage/service/enumeration_results.rb +3 -1
  42. data/lib/azure/storage/service/logging.rb +5 -3
  43. data/lib/azure/storage/service/metrics.rb +5 -3
  44. data/lib/azure/storage/service/retention_policy.rb +3 -1
  45. data/lib/azure/storage/service/serialization.rb +31 -30
  46. data/lib/azure/storage/service/signed_identifier.rb +5 -4
  47. data/lib/azure/storage/service/storage_service.rb +33 -32
  48. data/lib/azure/storage/service/storage_service_properties.rb +6 -4
  49. data/lib/azure/storage/table/auth/shared_key.rb +9 -8
  50. data/lib/azure/storage/table/batch.rb +55 -55
  51. data/lib/azure/storage/table/batch_response.rb +17 -17
  52. data/lib/azure/storage/table/edmtype.rb +9 -7
  53. data/lib/azure/storage/table/entity.rb +4 -3
  54. data/lib/azure/storage/table/guid.rb +3 -1
  55. data/lib/azure/storage/table/query.rb +17 -19
  56. data/lib/azure/storage/table/serialization.rb +14 -12
  57. data/lib/azure/storage/table/table_service.rb +79 -80
  58. data/lib/azure/storage/version.rb +7 -5
  59. metadata +2 -2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #-------------------------------------------------------------------------
2
4
  # # Copyright (c) Microsoft and contributors. All rights reserved.
3
5
  #
@@ -21,9 +23,9 @@
21
23
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
24
  # THE SOFTWARE.
23
25
  #--------------------------------------------------------------------------
24
- require 'azure/storage/service/logging'
25
- require 'azure/storage/service/metrics'
26
- require 'azure/storage/service/cors'
26
+ require "azure/storage/service/logging"
27
+ require "azure/storage/service/metrics"
28
+ require "azure/storage/service/cors"
27
29
 
28
30
  module Azure::Storage
29
31
  module Service
@@ -43,4 +45,4 @@ module Azure::Storage
43
45
  attr_accessor :default_service_version
44
46
  end
45
47
  end
46
- end
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #-------------------------------------------------------------------------
2
4
  # # Copyright (c) Microsoft and contributors. All rights reserved.
3
5
  #
@@ -21,8 +23,8 @@
21
23
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
24
  # THE SOFTWARE.
23
25
  #--------------------------------------------------------------------------
24
- require 'cgi'
25
- require 'azure/storage/core/auth/shared_key'
26
+ require "cgi"
27
+ require "azure/storage/core/auth/shared_key"
26
28
 
27
29
  module Azure::Storage
28
30
  module Table
@@ -41,9 +43,9 @@ module Azure::Storage
41
43
  def signable_string(method, uri, headers)
42
44
  [
43
45
  method.to_s.upcase,
44
- headers.fetch('Content-MD5', ''),
45
- headers.fetch('Content-Type', ''),
46
- headers.fetch('Date') { headers.fetch('x-ms-date') },
46
+ headers.fetch("Content-MD5", ""),
47
+ headers.fetch("Content-Type", ""),
48
+ headers.fetch("Date") { headers.fetch("x-ms-date") },
47
49
  canonicalized_resource(uri)
48
50
  ].join("\n")
49
51
  end
@@ -56,12 +58,11 @@ module Azure::Storage
56
58
  def canonicalized_resource(uri)
57
59
  resource = "/#{account_name}#{uri.path}"
58
60
 
59
- comp = CGI.parse(uri.query.to_s).fetch('comp', nil)
60
- resource = [resource, 'comp=' + comp[0]].join('?') if comp
61
+ comp = CGI.parse(uri.query.to_s).fetch("comp", nil)
62
+ resource = [resource, "comp=" + comp[0]].join("?") if comp
61
63
 
62
64
  resource
63
65
  end
64
-
65
66
  end
66
67
  end
67
68
  end
@@ -21,17 +21,17 @@
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 'securerandom'
24
+ require "securerandom"
25
25
 
26
- require 'azure/core/http/http_error'
27
- require 'azure/storage/table/serialization'
28
- require 'azure/storage/table/table_service'
29
- require 'azure/storage/table/batch_response'
26
+ require "azure/core/http/http_error"
27
+ require "azure/storage/table/serialization"
28
+ require "azure/storage/table/table_service"
29
+ require "azure/storage/table/batch_response"
30
30
 
31
31
  module Azure::Storage
32
32
  module Table
33
33
  # Represents a batch of table operations.
34
- #
34
+ #
35
35
  # Example usage (block syntax):
36
36
  #
37
37
  # results = Batch.new "table", "partition" do
@@ -46,9 +46,9 @@ module Azure::Storage
46
46
  # .insert("row2", {"meta"=>"data"})
47
47
  # .execute
48
48
  #
49
- # which is equivalent to (as class):
50
- #
51
- # svc = TableSerice.new
49
+ # which is equivalent to (as class):
50
+ #
51
+ # svc = TableSerice.new
52
52
  #
53
53
  # batch = Batch.new "table", "partition"
54
54
  # batch.insert "row1", {"meta"=>"data"}
@@ -70,74 +70,74 @@ module Azure::Storage
70
70
  end
71
71
 
72
72
  private
73
- attr_reader :table
74
- attr_reader :partition
75
- attr_reader :table_service
73
+ attr_reader :table
74
+ attr_reader :partition
75
+ attr_reader :table_service
76
76
 
77
- attr_accessor :operations
78
- attr_accessor :entity_keys
79
- attr_accessor :changeset_id
77
+ attr_accessor :operations
78
+ attr_accessor :entity_keys
79
+ attr_accessor :changeset_id
80
80
 
81
81
  public
82
82
  attr_accessor :batch_id
83
83
 
84
84
  protected
85
- def execute
86
- @table_service.execute_batch(self)
87
- end
85
+ def execute
86
+ @table_service.execute_batch(self)
87
+ end
88
88
 
89
89
  protected
90
- class ResponseWrapper
91
- def initialize(hash)
92
- @hash = hash
93
- end
90
+ class ResponseWrapper
91
+ def initialize(hash)
92
+ @hash = hash
93
+ end
94
94
 
95
- def uri
96
- @hash[:uri]
97
- end
98
-
99
- def status_code
100
- @hash[:status_code].to_i
101
- end
95
+ def uri
96
+ @hash[:uri]
97
+ end
102
98
 
103
- def body
104
- @hash[:body]
99
+ def status_code
100
+ @hash[:status_code].to_i
101
+ end
102
+
103
+ def body
104
+ @hash[:body]
105
+ end
105
106
  end
106
- end
107
107
 
108
108
  protected
109
- def add_operation(method, uri, body = nil, headers = nil)
110
- op = {
111
- method: method,
112
- uri: uri,
113
- body: body,
114
- headers: headers.merge(
115
- HeaderConstants::CONTENT_TYPE => HeaderConstants::JSON_CONTENT_TYPE_VALUE,
116
- HeaderConstants::DATA_SERVICE_VERSION => TableConstants::DEFAULT_DATA_SERVICE_VERSION
117
- )
118
- }
119
- operations.push op
120
- end
109
+ def add_operation(method, uri, body = nil, headers = nil)
110
+ op = {
111
+ method: method,
112
+ uri: uri,
113
+ body: body,
114
+ headers: headers.merge(
115
+ HeaderConstants::CONTENT_TYPE => HeaderConstants::JSON_CONTENT_TYPE_VALUE,
116
+ HeaderConstants::DATA_SERVICE_VERSION => TableConstants::DEFAULT_DATA_SERVICE_VERSION
117
+ )
118
+ }
119
+ operations.push op
120
+ end
121
121
 
122
122
  protected
123
- def check_entity_key(key)
124
- raise ArgumentError, "Only allowed to perform a single operation per entity, and there is already a operation registered in this batch for the key: #{key}." if entity_keys.include? key
125
- entity_keys.push key
126
- end
123
+ def check_entity_key(key)
124
+ raise ArgumentError, "Only allowed to perform a single operation per entity, and there is already a operation registered in this batch for the key: #{key}." if entity_keys.include? key
125
+ entity_keys.push key
126
+ end
127
127
 
128
128
  public
129
129
  def parse_response(response)
130
130
  responses = BatchResponse.parse response.body
131
131
  new_responses = []
132
132
 
133
- (0..responses.length-1).each { |index|
133
+ (0..responses.length - 1).each { |index|
134
134
  operation = operations[index]
135
135
  response = responses[index]
136
136
 
137
137
  if response[:status_code].to_i > 299
138
138
  # failed
139
- error = Azure::Core::Http::HTTPError.new(ResponseWrapper.new(response.merge({:uri=>operation[:uri]})))
140
- error.description = response[:message] if (error.description || '').strip == ''
139
+ error = Azure::Core::Http::HTTPError.new(ResponseWrapper.new(response.merge(uri: operation[:uri])))
140
+ error.description = response[:message] if (error.description || "").strip == ""
141
141
  raise error
142
142
  else
143
143
  # success
@@ -150,10 +150,10 @@ module Azure::Storage
150
150
 
151
151
  new_responses.push entity
152
152
  when :put, :merge
153
- # etag from headers
153
+ # etag from headers
154
154
  new_responses.push response[:headers]["etag"]
155
155
  when :delete
156
- # true
156
+ # true
157
157
  new_responses.push nil
158
158
  end
159
159
  end
@@ -165,7 +165,7 @@ module Azure::Storage
165
165
  public
166
166
  def to_body
167
167
  body = ""
168
- body.define_singleton_method(:add_line) do |a| self << (a||nil) + "\n" end
168
+ body.define_singleton_method(:add_line) do |a| self << (a || nil) + "\n" end
169
169
 
170
170
  body.add_line "--#{batch_id}"
171
171
  body.add_line "Content-Type: multipart/mixed; boundary=#{changeset_id}"
@@ -203,7 +203,7 @@ module Azure::Storage
203
203
  #
204
204
  # * +row_key+ - String. The row key
205
205
  # * +entity_values+ - Hash. A hash of the name/value pairs for the entity.
206
- # * +options+ - Hash. Optional parameters.
206
+ # * +options+ - Hash. Optional parameters.
207
207
  #
208
208
  # ==== Options
209
209
  #
@@ -25,16 +25,16 @@ module Azure::Storage
25
25
  module Table
26
26
  module BatchResponse
27
27
  def self.parse(data)
28
- context = {
29
- :lines => data.lines.to_a,
30
- :index=> 0,
31
- :responses => []
28
+ context = {
29
+ lines: data.lines.to_a,
30
+ index: 0,
31
+ responses: []
32
32
  }
33
33
 
34
34
  find(context) { |c| batch_boundary c }
35
35
  find(context) { |c| batch_headers c }
36
-
37
- while(find(context){ |c| changeset_boundary_or_end c } == :boundary)
36
+
37
+ while (find(context) { |c| changeset_boundary_or_end c } == :boundary)
38
38
  find(context) { |c| changeset_headers c }
39
39
  find(context) { |c| response c }
40
40
  find(context) { |c| response_headers c }
@@ -45,22 +45,22 @@ module Azure::Storage
45
45
  end
46
46
 
47
47
  def self.find(context, &block)
48
- while(context[:index] < context[:lines].length)
48
+ while (context[:index] < context[:lines].length)
49
49
  result = block.call(context)
50
50
  return result if result
51
- context[:index] +=1
51
+ context[:index] += 1
52
52
  end
53
53
  end
54
54
 
55
55
  def self.response_body(context)
56
56
  end_of_body = nil
57
- end_of_body = changeset_boundary_or_end(context.dup.merge!({:index=>context[:index] + 1})) if context[:index] < (context[:lines].length - 1)
57
+ end_of_body = changeset_boundary_or_end(context.dup.merge!(index: context[:index] + 1)) if context[:index] < (context[:lines].length - 1)
58
58
 
59
59
  if end_of_body
60
60
  context[:responses].last[:body] ||= ""
61
61
  context[:responses].last[:body] << current_line(context)
62
62
  return context[:responses].last[:body]
63
- else
63
+ else
64
64
  context[:responses].last[:body] ||= ""
65
65
  context[:responses].last[:body] << current_line(context)
66
66
  return nil
@@ -70,7 +70,7 @@ module Azure::Storage
70
70
  def self.response_headers(context)
71
71
  match = /(.*): (.*)/.match(current_line(context))
72
72
 
73
- if context[:responses].last[:headers] and not match
73
+ if context[:responses].last[:headers] && (not match)
74
74
  context[:index] += 1
75
75
  return context[:responses].last[:headers]
76
76
  elsif match
@@ -85,25 +85,25 @@ module Azure::Storage
85
85
  def self.response(context)
86
86
  match = /HTTP\/1.1 (\d*) (.*)/.match(current_line(context))
87
87
  return nil unless match
88
- response = {:status_code => match[1], :message => match[2] }
88
+ response = { status_code: match[1], message: match[2] }
89
89
  context[:responses].push response
90
90
  end
91
-
91
+
92
92
  def self.changeset_headers(context)
93
- current_line(context).strip == ''
93
+ current_line(context).strip == ""
94
94
  end
95
95
 
96
96
  def self.changeset_boundary_or_end(context)
97
97
  match_boundary = /--changesetresponse_(.*)/.match(current_line(context))
98
98
  match_end = /--changesetresponse_(.*)--/.match(current_line(context))
99
99
 
100
- (match_boundary and not match_end) ? :boundary : (match_end ? :end : nil)
100
+ (match_boundary && (not match_end)) ? :boundary : (match_end ? :end : nil)
101
101
  end
102
102
 
103
103
  def self.batch_headers(context)
104
104
  match = /(.*): (.*)/.match(current_line(context))
105
105
 
106
- if context[:batch_headers] and not match
106
+ if context[:batch_headers] && (not match)
107
107
  return context[:batch_headers]
108
108
  elsif match
109
109
  context[:batch_headers] ||= {}
@@ -118,7 +118,7 @@ module Azure::Storage
118
118
  match = /--batchresponse_(.*)/.match(current_line(context))
119
119
  match ? match[1] : nil
120
120
  end
121
-
121
+
122
122
  def self.current_line(context)
123
123
  context[:lines][context[:index]]
124
124
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #-------------------------------------------------------------------------
2
4
  # # Copyright (c) Microsoft and contributors. All rights reserved.
3
5
  #
@@ -22,7 +24,7 @@
22
24
  # THE SOFTWARE.
23
25
  #--------------------------------------------------------------------------
24
26
 
25
- require 'azure/storage/table/guid'
27
+ require "azure/storage/table/guid"
26
28
 
27
29
  require "time"
28
30
  require "date"
@@ -75,7 +77,7 @@ module Azure::Storage
75
77
  end
76
78
 
77
79
  # Public: Serializes EDM value into proper value to be used in query.
78
- #
80
+ #
79
81
  # value - String. The value to serialize.
80
82
  #
81
83
  # Returns the serialized value
@@ -96,7 +98,7 @@ module Azure::Storage
96
98
  "X'" + value.to_s.unpack("H*").join("") + "'"
97
99
  else
98
100
  # NULL also is treated as EdmType::STRING
99
- value.to_s.gsub("'","''");
101
+ value.to_s.gsub("'", "''");
100
102
  end
101
103
  end
102
104
  end
@@ -116,20 +118,20 @@ module Azure::Storage
116
118
  when "Edm.Int32", "Edm.Int64"
117
119
  Integer(value)
118
120
  when "Edm.Boolean"
119
- value == true || value == 'true' ? true : false
121
+ value == true || value == "true" ? true : false
120
122
  when "Edm.Guid"
121
123
  GUID.new(value.to_s)
122
124
  when "Edm.Binary"
123
125
  Base64.decode64(value.to_s).force_encoding("BINARY")
124
126
  else
125
- value == '' ? nil : value.to_s
127
+ value == "" ? nil : value.to_s
126
128
  end
127
129
  end
128
130
 
129
131
  def self.to_edm_time(value)
130
132
  date = value.is_a?(Time) ? value : Time.parse(value)
131
- date.utc.strftime('%Y-%m-%dT%H:%M:%S.%6N0Z')
133
+ date.utc.strftime("%Y-%m-%dT%H:%M:%S.%6N0Z")
132
134
  end
133
135
  end
134
136
  end
135
- end
137
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #-------------------------------------------------------------------------
2
4
  # # Copyright (c) Microsoft and contributors. All rights reserved.
3
5
  #
@@ -25,8 +27,7 @@
25
27
  module Azure::Storage
26
28
  module Table
27
29
  class Entity
28
-
29
- def initialize
30
+ def initialize
30
31
  @properties = {}
31
32
  yield self if block_given?
32
33
  end
@@ -35,4 +36,4 @@ module Azure::Storage
35
36
  attr_accessor :properties
36
37
  end
37
38
  end
38
- end
39
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #-------------------------------------------------------------------------
2
4
  # # Copyright (c) Microsoft and contributors. All rights reserved.
3
5
  #
@@ -30,4 +32,4 @@ module Azure::Storage
30
32
  class GUID < SimpleDelegator
31
33
  end
32
34
  end
33
- end
35
+ end
@@ -21,13 +21,13 @@
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/table/table_service'
25
- require 'azure/storage/table/edmtype'
24
+ require "azure/storage/table/table_service"
25
+ require "azure/storage/table/edmtype"
26
26
 
27
27
  module Azure::Storage
28
28
  module Table
29
29
  class Query
30
- def initialize(table="", partition=nil, row=nil, &block)
30
+ def initialize(table = "", partition = nil, row = nil, &block)
31
31
  @table = table
32
32
  @partition_key = partition
33
33
  @row_key = row
@@ -37,7 +37,7 @@ module Azure::Storage
37
37
  @table_service = Azure::Storage::Table::TableService.new
38
38
  self.instance_eval(&block) if block_given?
39
39
  end
40
-
40
+
41
41
  attr_reader :table
42
42
  attr_reader :partition_key
43
43
  attr_reader :row_key
@@ -75,7 +75,7 @@ module Azure::Storage
75
75
  @filters.push(p)
76
76
  self
77
77
  end
78
-
78
+
79
79
  def top(n)
80
80
  @top_n = n
81
81
  self
@@ -92,17 +92,15 @@ module Azure::Storage
92
92
  end
93
93
 
94
94
  def execute
95
- @table_service.query_entities(@table, {
96
- :partition_key => @partition_key,
97
- :row_key => @row_key,
98
- :select => @fields.map{ |f| f.to_s },
99
- :filter => _build_filter_string,
100
- :top => (@top_n ? @top_n.to_i : @top_n),
101
- :continuation_token => {
102
- :next_partition_key => @next_partition_key,
103
- :next_row_key => @next_row_key
104
- }
105
- })
95
+ @table_service.query_entities(@table, partition_key: @partition_key,
96
+ row_key: @row_key,
97
+ select: @fields.map { |f| f.to_s },
98
+ filter: _build_filter_string,
99
+ top: (@top_n ? @top_n.to_i : @top_n),
100
+ continuation_token: {
101
+ next_partition_key: @next_partition_key,
102
+ next_row_key: @next_row_key
103
+ })
106
104
  end
107
105
 
108
106
  def _build_filter_string
@@ -111,11 +109,11 @@ module Azure::Storage
111
109
  filters.each { |f|
112
110
  clauses.push "#{f[0]} #{f[1]} #{Azure::Storage::Table::EdmType.serialize_query_value(f[2])}"
113
111
  }
114
- return nil if clauses.length == 0
115
-
112
+ return nil if clauses.length == 0
113
+
116
114
  result << clauses.join(" and ")
117
115
  result
118
116
  end
119
117
  end
120
118
  end
121
- end
119
+ end