azure-storage 0.10.0.preview

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/lib/azure/storage.rb +58 -0
  3. data/lib/azure/storage/autoload.rb +71 -0
  4. data/lib/azure/storage/blob/append.rb +154 -0
  5. data/lib/azure/storage/blob/blob.rb +821 -0
  6. data/lib/azure/storage/blob/blob_service.rb +510 -0
  7. data/lib/azure/storage/blob/block.rb +264 -0
  8. data/lib/azure/storage/blob/container.rb +552 -0
  9. data/lib/azure/storage/blob/page.rb +380 -0
  10. data/lib/azure/storage/blob/serialization.rb +297 -0
  11. data/lib/azure/storage/client.rb +185 -0
  12. data/lib/azure/storage/configurable.rb +137 -0
  13. data/lib/azure/storage/core.rb +33 -0
  14. data/lib/azure/storage/core/auth/shared_access_signature.rb +27 -0
  15. data/lib/azure/storage/core/auth/shared_access_signature_generator.rb +194 -0
  16. data/lib/azure/storage/core/auth/shared_access_signature_signer.rb +49 -0
  17. data/lib/azure/storage/core/auth/shared_key.rb +125 -0
  18. data/lib/azure/storage/core/auth/shared_key_lite.rb +55 -0
  19. data/lib/azure/storage/core/auth/signer.rb +60 -0
  20. data/lib/azure/storage/core/autoload.rb +35 -0
  21. data/lib/azure/storage/core/client_options.rb +334 -0
  22. data/lib/azure/storage/core/client_options_error.rb +39 -0
  23. data/lib/azure/storage/core/constants.rb +1077 -0
  24. data/lib/azure/storage/core/error.rb +47 -0
  25. data/lib/azure/storage/core/filtered_service.rb +54 -0
  26. data/lib/azure/storage/core/http/debug_filter.rb +45 -0
  27. data/lib/azure/storage/core/http/http_error.rb +95 -0
  28. data/lib/azure/storage/core/http/http_filter.rb +62 -0
  29. data/lib/azure/storage/core/http/http_request.rb +182 -0
  30. data/lib/azure/storage/core/http/http_response.rb +105 -0
  31. data/lib/azure/storage/core/http/retry_policy.rb +83 -0
  32. data/lib/azure/storage/core/http/signer_filter.rb +42 -0
  33. data/lib/azure/storage/core/http_client.rb +63 -0
  34. data/lib/azure/storage/core/service.rb +55 -0
  35. data/lib/azure/storage/core/signed_service.rb +54 -0
  36. data/lib/azure/storage/core/sr.rb +83 -0
  37. data/lib/azure/storage/core/utility.rb +254 -0
  38. data/lib/azure/storage/queue/message.rb +39 -0
  39. data/lib/azure/storage/queue/queue.rb +37 -0
  40. data/lib/azure/storage/queue/queue_service.rb +580 -0
  41. data/lib/azure/storage/queue/serialization.rb +113 -0
  42. data/lib/azure/storage/service/access_policy.rb +35 -0
  43. data/lib/azure/storage/service/cors.rb +36 -0
  44. data/lib/azure/storage/service/cors_rule.rb +46 -0
  45. data/lib/azure/storage/service/enumeration_results.rb +30 -0
  46. data/lib/azure/storage/service/logging.rb +45 -0
  47. data/lib/azure/storage/service/metrics.rb +43 -0
  48. data/lib/azure/storage/service/retention_policy.rb +35 -0
  49. data/lib/azure/storage/service/serialization.rb +308 -0
  50. data/lib/azure/storage/service/signed_identifier.rb +39 -0
  51. data/lib/azure/storage/service/storage_service.rb +131 -0
  52. data/lib/azure/storage/service/storage_service_properties.rb +46 -0
  53. data/lib/azure/storage/table/auth/shared_key.rb +68 -0
  54. data/lib/azure/storage/table/auth/shared_key_lite.rb +53 -0
  55. data/lib/azure/storage/table/batch.rb +339 -0
  56. data/lib/azure/storage/table/batch_response.rb +127 -0
  57. data/lib/azure/storage/table/edmtype.rb +136 -0
  58. data/lib/azure/storage/table/entity.rb +40 -0
  59. data/lib/azure/storage/table/guid.rb +33 -0
  60. data/lib/azure/storage/table/query.rb +121 -0
  61. data/lib/azure/storage/table/serialization.rb +117 -0
  62. data/lib/azure/storage/table/table_service.rb +571 -0
  63. data/lib/azure/storage/version.rb +46 -0
  64. metadata +329 -0
@@ -0,0 +1,127 @@
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
+ module Azure::Storage
25
+ module Table
26
+ module BatchResponse
27
+ def self.parse(data)
28
+ context = {
29
+ :lines => data.lines.to_a,
30
+ :index=> 0,
31
+ :responses => []
32
+ }
33
+
34
+ find(context) { |c| batch_boundary c }
35
+ find(context) { |c| batch_headers c }
36
+
37
+ while(find(context){ |c| changeset_boundary_or_end c } == :boundary)
38
+ find(context) { |c| changeset_headers c }
39
+ find(context) { |c| response c }
40
+ find(context) { |c| response_headers c }
41
+ find(context) { |c| response_body c }
42
+ end
43
+
44
+ context[:responses]
45
+ end
46
+
47
+ def self.find(context, &block)
48
+ while(context[:index] < context[:lines].length)
49
+ result = block.call(context)
50
+ return result if result
51
+ context[:index] +=1
52
+ end
53
+ end
54
+
55
+ def self.response_body(context)
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)
58
+
59
+ if end_of_body
60
+ context[:responses].last[:body] ||= ""
61
+ context[:responses].last[:body] << current_line(context)
62
+ return context[:responses].last[:body]
63
+ else
64
+ context[:responses].last[:body] ||= ""
65
+ context[:responses].last[:body] << current_line(context)
66
+ return nil
67
+ end
68
+ end
69
+
70
+ def self.response_headers(context)
71
+ match = /(.*): (.*)/.match(current_line(context))
72
+
73
+ if context[:responses].last[:headers] and not match
74
+ context[:index] += 1
75
+ return context[:responses].last[:headers]
76
+ elsif match
77
+ context[:responses].last[:headers] ||= {}
78
+ context[:responses].last[:headers][match[1].downcase] = match[2].strip
79
+ return nil
80
+ else
81
+ return nil
82
+ end
83
+ end
84
+
85
+ def self.response(context)
86
+ match = /HTTP\/1.1 (\d*) (.*)/.match(current_line(context))
87
+ return nil unless match
88
+ response = {:status_code => match[1], :message => match[2] }
89
+ context[:responses].push response
90
+ end
91
+
92
+ def self.changeset_headers(context)
93
+ current_line(context).strip == ''
94
+ end
95
+
96
+ def self.changeset_boundary_or_end(context)
97
+ match_boundary = /--changesetresponse_(.*)/.match(current_line(context))
98
+ match_end = /--changesetresponse_(.*)--/.match(current_line(context))
99
+
100
+ (match_boundary and not match_end) ? :boundary : (match_end ? :end : nil)
101
+ end
102
+
103
+ def self.batch_headers(context)
104
+ match = /(.*): (.*)/.match(current_line(context))
105
+
106
+ if context[:batch_headers] and not match
107
+ return context[:batch_headers]
108
+ elsif match
109
+ context[:batch_headers] ||= {}
110
+ context[:batch_headers][match[1].downcase] = match[2]
111
+ return nil
112
+ else
113
+ return nil
114
+ end
115
+ end
116
+
117
+ def self.batch_boundary(context)
118
+ match = /--batchresponse_(.*)/.match(current_line(context))
119
+ match ? match[1] : nil
120
+ end
121
+
122
+ def self.current_line(context)
123
+ context[:lines][context[:index]]
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,136 @@
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
+
25
+ require 'azure/storage/table/guid'
26
+
27
+ require "time"
28
+ require "date"
29
+
30
+ module Azure::Storage
31
+ module Table
32
+ module EdmType
33
+ # Public: Get the Edm type of an object
34
+ #
35
+ # value - Object. An typed instance
36
+ #
37
+ # Returns the Edm type as a String
38
+ def self.property_type(value)
39
+ case value
40
+ when Float
41
+ "Edm.Double"
42
+ when Date, Time, DateTime
43
+ "Edm.DateTime"
44
+ when Integer
45
+ value.abs < 2**31 ? "Edm.Int32" : "Edm.Int64"
46
+ when TrueClass, FalseClass
47
+ "Edm.Boolean"
48
+ when GUID
49
+ "Edm.Guid"
50
+ when IO, File
51
+ "Edm.Binary"
52
+ when String
53
+ value.encoding.names.include?("BINARY") ? "Edm.Binary" : ""
54
+ else
55
+ value.kind_of?(IO) ? "Edm.Binary" : ""
56
+ end
57
+ end
58
+
59
+ # Public: Get the value of a property in a serialized way
60
+ #
61
+ # value - Object. An typed instance
62
+ #
63
+ # Returns the Edm type as a String
64
+ def self.serialize_value(type, value)
65
+ case type
66
+ when "Edm.Double", "Edm.Int32", "Edm.Int64", "Edm.Guid", "Edm.String", nil
67
+ value.to_s
68
+ when "Edm.Binary"
69
+ Base64.encode64(value.to_s).chomp("\n")
70
+ when "Edm.DateTime"
71
+ value.xmlschema(7)
72
+ when "Edm.Boolean"
73
+ if value.nil?
74
+ ''
75
+ else
76
+ value == true ? '1' : '0'
77
+ end
78
+ else
79
+ value.to_s
80
+ end
81
+ end
82
+
83
+ # Public: Serializes EDM value into proper value to be used in query.
84
+ #
85
+ # value - String. The value to serialize.
86
+ #
87
+ # Returns the serialized value
88
+ def self.serialize_query_value(value)
89
+ case value
90
+ when Date, Time, DateTime
91
+ "datetime'#{value.iso8601}'"
92
+ when TrueClass, FalseClass
93
+ value ? "true" : "false"
94
+ when Float, Integer
95
+ value.abs < 2**31 ? value.to_s : value.to_s + "L"
96
+ when GUID
97
+ "guid'#{value.to_s}'"
98
+ when IO, File
99
+ "X'" + value.to_s.unpack("H*").join("") + "'"
100
+ else
101
+ if value != nil && value.encoding.names.include?("BINARY")
102
+ "X'" + value.to_s.unpack("H*").join("") + "'"
103
+ else
104
+ # NULL also is treated as EdmType::STRING
105
+ value.to_s.gsub("'","''");
106
+ end
107
+ end
108
+ end
109
+
110
+ # Public: Convert a serialized value into an typed object
111
+ #
112
+ # value - String. The Edm value
113
+ # type - String. The Edm datatype
114
+ #
115
+ # Returns an typed object
116
+ def self.unserialize_query_value(value, type)
117
+ case type
118
+ when "Edm.DateTime"
119
+ Time.parse(value)
120
+ when "Edm.Double"
121
+ Float(value)
122
+ when "Edm.Int32", "Edm.Int64"
123
+ Integer(value)
124
+ when "Edm.Boolean"
125
+ /true/i === value
126
+ when "Edm.Guid"
127
+ GUID.new(value.to_s)
128
+ when "Edm.Binary"
129
+ Base64.decode64(value.to_s).force_encoding("BINARY")
130
+ else
131
+ value.to_s
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,40 @@
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
+
25
+ module Azure::Storage
26
+ module Table
27
+ class Entity
28
+
29
+ def initialize
30
+ @properties = {}
31
+ yield self if block_given?
32
+ end
33
+
34
+ attr_accessor :table
35
+ attr_accessor :updated
36
+ attr_accessor :etag
37
+ attr_accessor :properties
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
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 "delegate"
25
+
26
+ module Azure::Storage
27
+ module Table
28
+ # Public: Wrapper around a string to represent a GUID
29
+ #
30
+ class GUID < SimpleDelegator
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,121 @@
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/table_service'
25
+ require 'azure/storage/table/edmtype'
26
+
27
+ module Azure::Storage
28
+ module Table
29
+ class Query
30
+ def initialize(table="", partition=nil, row=nil, &block)
31
+ @table = table
32
+ @partition_key = partition
33
+ @row_key = row
34
+ @fields = []
35
+ @filters = []
36
+ @top_n = nil
37
+ @table_service = Azure::Storage::Table::TableService.new
38
+ self.instance_eval(&block) if block_given?
39
+ end
40
+
41
+ attr_reader :table
42
+ attr_reader :partition_key
43
+ attr_reader :row_key
44
+
45
+ attr_reader :fields
46
+ attr_reader :filters
47
+ attr_reader :top_n
48
+
49
+ attr_reader :next_partition_key
50
+ attr_reader :next_row_key
51
+
52
+ attr_reader :table_service
53
+
54
+ def from(table_name)
55
+ @table = table_name
56
+ self
57
+ end
58
+
59
+ def partition(partition_key)
60
+ @partition_key = partition_key
61
+ self
62
+ end
63
+
64
+ def row(row_key)
65
+ @row_key = row_key
66
+ self
67
+ end
68
+
69
+ def select(*p)
70
+ @fields.concat(p)
71
+ self
72
+ end
73
+
74
+ def where(*p)
75
+ @filters.push(p)
76
+ self
77
+ end
78
+
79
+ def top(n)
80
+ @top_n = n
81
+ self
82
+ end
83
+
84
+ def next_partition(next_partition_key)
85
+ @next_partition_key = next_partition_key
86
+ self
87
+ end
88
+
89
+ def next_row(next_row_key)
90
+ @next_row_key = next_row_key
91
+ self
92
+ end
93
+
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
+ })
106
+ end
107
+
108
+ def _build_filter_string
109
+ result = ""
110
+ clauses = []
111
+ filters.each { |f|
112
+ clauses.push "#{f[0].to_s} #{f[1].to_s} #{Azure::Storage::Table::EdmType.serialize_query_value(f[2])}"
113
+ }
114
+ return nil if clauses.length == 0
115
+
116
+ result << clauses.join(" and ")
117
+ result
118
+ end
119
+ end
120
+ end
121
+ end