mss-sdk 1.0.0

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 (131) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/LICENSE.txt +0 -0
  4. data/README.md +192 -0
  5. data/bin/mss-rb +178 -0
  6. data/ca-bundle.crt +3554 -0
  7. data/lib/mss/core/async_handle.rb +89 -0
  8. data/lib/mss/core/cacheable.rb +76 -0
  9. data/lib/mss/core/client.rb +786 -0
  10. data/lib/mss/core/collection/simple.rb +81 -0
  11. data/lib/mss/core/collection/with_limit_and_next_token.rb +70 -0
  12. data/lib/mss/core/collection/with_next_token.rb +96 -0
  13. data/lib/mss/core/collection.rb +262 -0
  14. data/lib/mss/core/configuration.rb +527 -0
  15. data/lib/mss/core/credential_providers.rb +653 -0
  16. data/lib/mss/core/data.rb +251 -0
  17. data/lib/mss/core/deprecations.rb +83 -0
  18. data/lib/mss/core/endpoints.rb +36 -0
  19. data/lib/mss/core/http/connection_pool.rb +374 -0
  20. data/lib/mss/core/http/curb_handler.rb +150 -0
  21. data/lib/mss/core/http/handler.rb +88 -0
  22. data/lib/mss/core/http/net_http_handler.rb +144 -0
  23. data/lib/mss/core/http/patch.rb +98 -0
  24. data/lib/mss/core/http/request.rb +258 -0
  25. data/lib/mss/core/http/response.rb +80 -0
  26. data/lib/mss/core/indifferent_hash.rb +87 -0
  27. data/lib/mss/core/inflection.rb +55 -0
  28. data/lib/mss/core/ini_parser.rb +41 -0
  29. data/lib/mss/core/json_client.rb +46 -0
  30. data/lib/mss/core/json_parser.rb +75 -0
  31. data/lib/mss/core/json_request_builder.rb +34 -0
  32. data/lib/mss/core/json_response_parser.rb +78 -0
  33. data/lib/mss/core/lazy_error_classes.rb +107 -0
  34. data/lib/mss/core/log_formatter.rb +426 -0
  35. data/lib/mss/core/managed_file.rb +31 -0
  36. data/lib/mss/core/meta_utils.rb +44 -0
  37. data/lib/mss/core/model.rb +61 -0
  38. data/lib/mss/core/naming.rb +29 -0
  39. data/lib/mss/core/option_grammar.rb +737 -0
  40. data/lib/mss/core/options/json_serializer.rb +81 -0
  41. data/lib/mss/core/options/validator.rb +154 -0
  42. data/lib/mss/core/options/xml_serializer.rb +117 -0
  43. data/lib/mss/core/page_result.rb +74 -0
  44. data/lib/mss/core/policy.rb +938 -0
  45. data/lib/mss/core/query_client.rb +40 -0
  46. data/lib/mss/core/query_error_parser.rb +23 -0
  47. data/lib/mss/core/query_request_builder.rb +46 -0
  48. data/lib/mss/core/query_response_parser.rb +34 -0
  49. data/lib/mss/core/region.rb +84 -0
  50. data/lib/mss/core/region_collection.rb +79 -0
  51. data/lib/mss/core/resource.rb +412 -0
  52. data/lib/mss/core/resource_cache.rb +39 -0
  53. data/lib/mss/core/response.rb +214 -0
  54. data/lib/mss/core/response_cache.rb +49 -0
  55. data/lib/mss/core/rest_error_parser.rb +23 -0
  56. data/lib/mss/core/rest_json_client.rb +39 -0
  57. data/lib/mss/core/rest_request_builder.rb +153 -0
  58. data/lib/mss/core/rest_response_parser.rb +65 -0
  59. data/lib/mss/core/rest_xml_client.rb +46 -0
  60. data/lib/mss/core/service_interface.rb +82 -0
  61. data/lib/mss/core/signers/base.rb +45 -0
  62. data/lib/mss/core/signers/cloud_front.rb +55 -0
  63. data/lib/mss/core/signers/s3.rb +158 -0
  64. data/lib/mss/core/signers/version_2.rb +71 -0
  65. data/lib/mss/core/signers/version_3.rb +85 -0
  66. data/lib/mss/core/signers/version_3_https.rb +60 -0
  67. data/lib/mss/core/signers/version_4/chunk_signed_stream.rb +190 -0
  68. data/lib/mss/core/signers/version_4.rb +227 -0
  69. data/lib/mss/core/uri_escape.rb +43 -0
  70. data/lib/mss/core/xml/frame.rb +245 -0
  71. data/lib/mss/core/xml/frame_stack.rb +84 -0
  72. data/lib/mss/core/xml/grammar.rb +306 -0
  73. data/lib/mss/core/xml/parser.rb +69 -0
  74. data/lib/mss/core/xml/root_frame.rb +64 -0
  75. data/lib/mss/core/xml/sax_handlers/libxml.rb +46 -0
  76. data/lib/mss/core/xml/sax_handlers/nokogiri.rb +55 -0
  77. data/lib/mss/core/xml/sax_handlers/ox.rb +40 -0
  78. data/lib/mss/core/xml/sax_handlers/rexml.rb +46 -0
  79. data/lib/mss/core/xml/stub.rb +122 -0
  80. data/lib/mss/core.rb +602 -0
  81. data/lib/mss/errors.rb +161 -0
  82. data/lib/mss/rails.rb +194 -0
  83. data/lib/mss/s3/access_control_list.rb +262 -0
  84. data/lib/mss/s3/acl_object.rb +263 -0
  85. data/lib/mss/s3/acl_options.rb +200 -0
  86. data/lib/mss/s3/bucket.rb +757 -0
  87. data/lib/mss/s3/bucket_collection.rb +161 -0
  88. data/lib/mss/s3/bucket_lifecycle_configuration.rb +472 -0
  89. data/lib/mss/s3/bucket_region_cache.rb +51 -0
  90. data/lib/mss/s3/bucket_tag_collection.rb +110 -0
  91. data/lib/mss/s3/bucket_version_collection.rb +78 -0
  92. data/lib/mss/s3/cipher_io.rb +119 -0
  93. data/lib/mss/s3/client/xml.rb +265 -0
  94. data/lib/mss/s3/client.rb +2076 -0
  95. data/lib/mss/s3/config.rb +60 -0
  96. data/lib/mss/s3/cors_rule.rb +107 -0
  97. data/lib/mss/s3/cors_rule_collection.rb +193 -0
  98. data/lib/mss/s3/data_options.rb +190 -0
  99. data/lib/mss/s3/encryption_utils.rb +145 -0
  100. data/lib/mss/s3/errors.rb +93 -0
  101. data/lib/mss/s3/multipart_upload.rb +353 -0
  102. data/lib/mss/s3/multipart_upload_collection.rb +75 -0
  103. data/lib/mss/s3/object_collection.rb +355 -0
  104. data/lib/mss/s3/object_metadata.rb +102 -0
  105. data/lib/mss/s3/object_upload_collection.rb +76 -0
  106. data/lib/mss/s3/object_version.rb +153 -0
  107. data/lib/mss/s3/object_version_collection.rb +88 -0
  108. data/lib/mss/s3/paginated_collection.rb +74 -0
  109. data/lib/mss/s3/policy.rb +73 -0
  110. data/lib/mss/s3/prefix_and_delimiter_collection.rb +46 -0
  111. data/lib/mss/s3/prefixed_collection.rb +84 -0
  112. data/lib/mss/s3/presign_v4.rb +135 -0
  113. data/lib/mss/s3/presigned_post.rb +574 -0
  114. data/lib/mss/s3/region_detection.rb +75 -0
  115. data/lib/mss/s3/request.rb +61 -0
  116. data/lib/mss/s3/s3_object.rb +1795 -0
  117. data/lib/mss/s3/tree/branch_node.rb +67 -0
  118. data/lib/mss/s3/tree/child_collection.rb +103 -0
  119. data/lib/mss/s3/tree/leaf_node.rb +93 -0
  120. data/lib/mss/s3/tree/node.rb +21 -0
  121. data/lib/mss/s3/tree/parent.rb +86 -0
  122. data/lib/mss/s3/tree.rb +115 -0
  123. data/lib/mss/s3/uploaded_part.rb +81 -0
  124. data/lib/mss/s3/uploaded_part_collection.rb +83 -0
  125. data/lib/mss/s3/website_configuration.rb +101 -0
  126. data/lib/mss/s3.rb +161 -0
  127. data/lib/mss/version.rb +16 -0
  128. data/lib/mss-sdk.rb +2 -0
  129. data/lib/mss.rb +14 -0
  130. data/rails/init.rb +14 -0
  131. metadata +201 -0
@@ -0,0 +1,251 @@
1
+ # Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ #
8
+ # or in the "license" file accompanying this file. This file is
9
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
10
+ # ANY KIND, either express or implied. See the License for the specific
11
+ # language governing permissions and limitations under the License.
12
+
13
+ module MSS
14
+ module Core
15
+
16
+ # Data is a light wrapper around a Ruby hash that provides
17
+ # method missing access to the hash contents.
18
+ #
19
+ # ## Method Missing Access
20
+ #
21
+ # You can access hash content with methods if their keys
22
+ # are symbols.
23
+ #
24
+ # data = MSS::Core::Data.new({ :a => 1, :b => 2, :c => true })
25
+ # data.a #=> 1
26
+ # data.b #=> 2
27
+ # data.c #=> true
28
+ # data.d #=> raises NoMethodError
29
+ #
30
+ # ## Boolean Methods
31
+ #
32
+ # Given the structure above you can also use question-mark methods.
33
+ #
34
+ # data.c? #=> true
35
+ # data.d? #=> raises NoMethodError
36
+ #
37
+ # ## Nested Hashes
38
+ #
39
+ # If the data contains nested hashes you can chain methods into
40
+ # the structure.
41
+ #
42
+ # data = MSS::Core::Data.new(:a => { :b => { :c => 'abc' }})
43
+ # data.a.b.c #=> 'abc'
44
+ #
45
+ # ## Nested Arrays
46
+ #
47
+ # Arrays are wrapped in {Data::List} objects. They ensure any
48
+ # data returned is correctly wrapped so you can continue using
49
+ # method-missing access.
50
+ #
51
+ # data = MSS::Core::Data.new(
52
+ # :people => [
53
+ # {:name => 'john'},
54
+ # {:name => 'jane'},
55
+ # ]})
56
+ #
57
+ # data.people[0].name #=> 'john'
58
+ # data.people[1].name #=> 'jane'
59
+ #
60
+ # data.people.map(&:name) #=> ['john','jane']
61
+ #
62
+ class Data
63
+
64
+ module MethodMissingProxy
65
+
66
+ # @api private
67
+ def id
68
+ self[:id] || self.id
69
+ end
70
+
71
+ def [] index_or_key
72
+ Data.cast(@data[index_or_key])
73
+ end
74
+
75
+ # @return [Boolean] Returns true if the passed object equals
76
+ # the wrapped array.
77
+ def eql? other
78
+ if other.is_a?(MethodMissingProxy)
79
+ @data == other._data
80
+ else
81
+ @data == other
82
+ end
83
+ end
84
+ alias_method :==, :eql?
85
+
86
+ def dup
87
+ Data.cast(@data.dup)
88
+ end
89
+ alias_method :clone, :dup
90
+
91
+ protected
92
+
93
+ def method_missing *args, &block
94
+ if block_given?
95
+ return_value = @data.send(*args) do |*values|
96
+ yield(*values.flatten.map{|v| Data.cast(v) })
97
+ end
98
+ Data.cast(return_value)
99
+ else
100
+ Data.cast(@data.send(*args))
101
+ end
102
+ end
103
+
104
+ def _data
105
+ @data
106
+ end
107
+
108
+ end
109
+
110
+ include MethodMissingProxy
111
+
112
+ def method_missing method_name, *args, &block
113
+ if
114
+ args.empty? and !block_given? and
115
+ key = _remove_question_mark(method_name) and
116
+ @data.has_key?(key)
117
+ then
118
+ Data.cast(@data[key])
119
+ else
120
+ super
121
+ end
122
+ end
123
+
124
+ # @param [Hash] data The ruby hash of data you need wrapped.
125
+ def initialize data
126
+ @data = data
127
+ end
128
+
129
+ # @return [Hash] Returns contents of this Data object as a raw hash.
130
+ def to_hash
131
+ @data
132
+ end
133
+ alias_method :to_h, :to_hash
134
+
135
+ # @return [Array]
136
+ def to_a
137
+ @data.to_a
138
+ end
139
+ alias_method :to_ary, :to_a
140
+
141
+ # @param [String,Symbol] method_name
142
+ # @return [Boolean] Returns true if this data object will
143
+ # respond to the given method name.
144
+ def respond_to? method_name
145
+ @data.key?(_remove_question_mark(method_name)) or
146
+ @data.respond_to?(method_name)
147
+ end
148
+
149
+ # Returns an inspection string from the wrapped data.
150
+ #
151
+ # data = MSS::Core::Data.new({ :a => 1, :b => 2, :c => true })
152
+ # data.inspect #=> '{:a=>1, :b=>2, :c=>true}'
153
+ #
154
+ # @return [String]
155
+ #
156
+ def inspect
157
+ @data.inspect
158
+ end
159
+
160
+ # @api private
161
+ def kind_of? klass
162
+ if klass == Hash
163
+ true
164
+ else
165
+ super
166
+ end
167
+ end
168
+ alias_method :is_a?, :kind_of?
169
+
170
+ protected
171
+
172
+ def _remove_question_mark method_name
173
+ case method_name
174
+ when Symbol then method_name.to_s.sub(/\?$/, '').to_sym
175
+ when String then method_name.sub(/\?$/, '')
176
+ else method_name
177
+ end
178
+ end
179
+
180
+ class << self
181
+
182
+ # Given a hash, this method returns a {Data} object. Given
183
+ # an Array, this method returns a {Data::List} object. Everything
184
+ # else is returned as is.
185
+ #
186
+ # @param [Object] value The value to conditionally wrap.
187
+ #
188
+ # @return [Data,Data::List,Object] Wraps hashes and lists with
189
+ # Data and List objects, all other objects are returned as
190
+ # is.
191
+ #
192
+ def cast value
193
+ case value
194
+ when Hash then Data.new(value)
195
+ when Array then Data::List.new(value)
196
+ else value
197
+ end
198
+ end
199
+
200
+ end
201
+
202
+ class List
203
+
204
+ include MethodMissingProxy
205
+
206
+ # @param [Array] array
207
+ def initialize array
208
+ @data = array
209
+ end
210
+
211
+ # @return [String] Returns the inspection string for the
212
+ # wrapped array.
213
+ def inspect
214
+ @data.inspect
215
+ end
216
+
217
+ # @return [Array] Returns the contents of this Data::List as
218
+ # a raw array.
219
+ def to_ary
220
+ @data
221
+ end
222
+ alias_method :to_a, :to_ary
223
+
224
+ # #inject works on Core::Data::List in in 1.8.7 and 1.9.3, but not
225
+ # in 1.9.2 unless we define it like so.
226
+ # @api private
227
+ def inject *args, &block
228
+ @data.inject(*args) do |obj,value|
229
+ yield(Data.cast(obj),Data.cast(value))
230
+ end
231
+ end
232
+
233
+ # @api private
234
+ def kind_of? klass
235
+ if klass == Array
236
+ true
237
+ else
238
+ super
239
+ end
240
+ end
241
+ alias_method :is_a?, :kind_of?
242
+
243
+ # @api private
244
+ def empty?
245
+ @data.empty?
246
+ end
247
+
248
+ end
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,83 @@
1
+ # Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ #
8
+ # or in the "license" file accompanying this file. This file is
9
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
10
+ # ANY KIND, either express or implied. See the License for the specific
11
+ # language governing permissions and limitations under the License.
12
+
13
+ module MSS
14
+ module Core
15
+
16
+ # A utility module that provides a class method that wraps
17
+ # a method such that it generates a deprecation warning when called.
18
+ # Given the following class:
19
+ #
20
+ # class Example
21
+ #
22
+ # def do_something
23
+ # end
24
+ #
25
+ # end
26
+ #
27
+ # If you want to deprecate the `#do_something` method, you can extend
28
+ # this module and then call `deprecated` on the method (after it
29
+ # has been defined).
30
+ #
31
+ # class Example
32
+ #
33
+ # extend MSS::Core::Deprecations
34
+ #
35
+ # def do_something
36
+ # end
37
+ #
38
+ # def do_something_else
39
+ # end
40
+ #
41
+ # deprecated :do_something
42
+ #
43
+ # end
44
+ #
45
+ # The `#do_something` method will continue to function, but will
46
+ # generate a deprecation warning when called.
47
+ #
48
+ # @api private
49
+ module Deprecations
50
+
51
+ # @param [Symbol] method The name of the deprecated method.
52
+ #
53
+ # @option options [String] :message The warning message to issue
54
+ # when the deprecated method is called.
55
+ #
56
+ # @option options [Symbol] :use The name of an use
57
+ # method that should be used.
58
+ #
59
+ def deprecated method, options = {}
60
+
61
+ deprecation_msg = options[:message] || begin
62
+ msg = "DEPRECATION WARNING: called deprecated method `#{method}' "
63
+ msg << "of #{self.name}"
64
+ msg << ", try calling #{options[:use]} instead" if options[:use]
65
+ msg
66
+ end
67
+
68
+ alias_method(:"deprecated_#{method}", method)
69
+
70
+ warned = false # we only want to issue this warning once
71
+
72
+ define_method(method) do |*args,&block|
73
+ unless warned
74
+ warn(deprecation_msg)
75
+ warned = true
76
+ end
77
+ send("deprecated_#{method}", *args, &block)
78
+ end
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,36 @@
1
+ # Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ #
8
+ # or in the "license" file accompanying this file. This file is
9
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
10
+ # ANY KIND, either express or implied. See the License for the specific
11
+ # language governing permissions and limitations under the License.
12
+
13
+ require 'json'
14
+
15
+ module MSS
16
+ module Core
17
+ # Provides a read-only interface to the bundled endpoints.json file.
18
+ module Endpoints
19
+
20
+ def hostname(region, endpoint_prefix)
21
+ region = endpoints["regions"][region] || {}
22
+ endpoint = region[endpoint_prefix] || {}
23
+ endpoint["hostname"]
24
+ end
25
+ module_function :hostname
26
+
27
+ def endpoints
28
+ @endpoints ||= begin
29
+ JSON.parse(File.read(File.join(MSS::ROOT, 'endpoints.json')))
30
+ end
31
+ end
32
+ module_function :endpoints
33
+
34
+ end
35
+ end
36
+ end