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,81 @@
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
+ module Collection
16
+
17
+ # MSS::Core::Collection::Simple is used by collections that always
18
+ # recieve every matching items in a single response.
19
+ #
20
+ # This means:
21
+ #
22
+ # * Paging methods are simulated
23
+ #
24
+ # * Next tokens are artificial (guessable numeric offsets)
25
+ #
26
+ # MSS services generally return all items only for requests with a
27
+ # small maximum number of results.
28
+ #
29
+ # See {MSS::Core::Collection} for documentation on the available
30
+ # collection methods.
31
+ module Simple
32
+
33
+ include Model
34
+ include Enumerable
35
+ include Collection
36
+
37
+ protected
38
+
39
+ def _each_batch options = {}, &block
40
+
41
+ limit = _extract_limit(options)
42
+ next_token = _extract_next_token(options)
43
+ offset = next_token ? next_token.to_i - 1 : 0
44
+
45
+ total = 0
46
+ skipped = 0
47
+ simulated_next_token = nil
48
+
49
+ batch = []
50
+ _each_item(options.dup) do |item|
51
+
52
+ total += 1
53
+
54
+ # skip until we reach our offset (derived from the "next token")
55
+ if skipped < offset
56
+ skipped += 1
57
+ next
58
+ end
59
+
60
+ if limit
61
+ if batch.size < limit
62
+ batch << item
63
+ else
64
+ simulated_next_token = total
65
+ break
66
+ end
67
+ else
68
+ batch << item
69
+ end
70
+
71
+ end
72
+
73
+ yield(batch)
74
+
75
+ simulated_next_token
76
+
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,70 @@
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
+ module Collection
16
+
17
+ # # Collection::WithLimitAndNextToken
18
+ #
19
+ # This module is used by collections where the service may truncate
20
+ # responses but that also accept a upper limit of results to
21
+ # return in a single request.
22
+ #
23
+ # See {MSS::Core::Collection} for documentation on the available
24
+ # methods.
25
+ #
26
+ module WithLimitAndNextToken
27
+
28
+ include Model
29
+ include Collection
30
+ include Enumerable
31
+
32
+ protected
33
+
34
+ def _each_batch options = {}, &block
35
+
36
+ limit = _extract_limit(options)
37
+ batch_size = _extract_batch_size(options)
38
+ next_token = _extract_next_token(options)
39
+
40
+ total = 0 # count of items yeilded across all batches
41
+
42
+ begin
43
+
44
+ max = nil
45
+ if limit or batch_size
46
+ max = []
47
+ max << (limit - total) if limit
48
+ max << batch_size if batch_size
49
+ max = max.min
50
+ end
51
+
52
+ batch = []
53
+ next_token = _each_item(next_token, max, options.dup) do |item|
54
+
55
+ total += 1
56
+ batch << item
57
+
58
+ end
59
+
60
+ yield(batch)
61
+
62
+ end until next_token.nil? or (limit and limit == total)
63
+
64
+ next_token
65
+
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,96 @@
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
+ module Collection
16
+
17
+ # # Collection::WithNextToken
18
+ #
19
+ # When making a request to list elements from one of these
20
+ # collections, the response may return a next token. This indicates
21
+ # there are more results than were returned. You can not control
22
+ # the number of elements returned with each response.
23
+ #
24
+ # See {MSS::Core::Collection} for documentation on the available
25
+ # collection methods.
26
+ #
27
+ module WithNextToken
28
+
29
+ include Model
30
+ include Enumerable
31
+ include Collection
32
+
33
+ protected
34
+
35
+ def _each_batch options = {}, &block
36
+
37
+ limit = _extract_limit(options)
38
+
39
+ next_token, skip_count = _extract_next_token(options)
40
+
41
+ skipped = 0
42
+ collected = 0
43
+
44
+ begin
45
+
46
+ offset = 0
47
+ batch = []
48
+
49
+ next_token = _each_item(next_token, options.dup) do |item|
50
+
51
+ if skipped < skip_count
52
+ skipped += 1
53
+ next
54
+ end
55
+
56
+ if limit
57
+ if collected < limit
58
+ batch << item
59
+ collected += 1
60
+ else
61
+ yield(batch)
62
+ simulated_next_token = {}
63
+ simulated_next_token[:token] = next_token if next_token
64
+ simulated_next_token[:offset] = offset + skipped
65
+ return simulated_next_token
66
+ end
67
+ else
68
+ batch << item
69
+ collected += 1
70
+ end
71
+
72
+ offset += 1
73
+
74
+ end # _each_item
75
+
76
+ yield(batch)
77
+
78
+ end until next_token.nil? or (limit and limit == collected)
79
+
80
+ next_token.nil? ? nil : { :token => next_token }
81
+
82
+ end
83
+
84
+ def _extract_next_token options
85
+ next_token = super
86
+ case next_token
87
+ when nil then [nil, 0]
88
+ when Hash then [next_token[:token], next_token[:offset] || 0]
89
+ else [next_token, 0]
90
+ end
91
+ end
92
+
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,262 @@
1
+ # Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
3
+ # may not use this file except in compliance with the License. A copy of
4
+ # the License is located at
5
+ #
6
+ #
7
+ # or in the "license" file accompanying this file. This file is
8
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
9
+ # ANY KIND, either express or implied. See the License for the specific
10
+ # language governing permissions and limitations under the License.
11
+
12
+ module MSS
13
+ module Core
14
+
15
+ # Provides useful methods for enumerating items in a collection.
16
+ module Collection
17
+
18
+ autoload :Simple, 'mss/core/collection/simple'
19
+ autoload :WithNextToken, 'mss/core/collection/with_next_token'
20
+ autoload :WithLimitAndNextToken, 'mss/core/collection/with_limit_and_next_token'
21
+
22
+ include Enumerable
23
+
24
+ # Yields once for every item in this collection.
25
+ #
26
+ # collection.each {|item| ... }
27
+ #
28
+ # @note If you want fewer than all items, it is generally better
29
+ # to call {#page} than {#each} with a `:limit`.
30
+ #
31
+ # @param [Hash] options
32
+ #
33
+ # @option options [Integer] :limit (nil) The maximum number of
34
+ # items to enumerate from this collection.
35
+ #
36
+ # @option options [next_token] :next_token (nil)
37
+ # Acts as an offset. `:next_token` may be returned by {#each} and
38
+ # {#each_batch} when a `:limit` is provided.
39
+ #
40
+ # @return [nil_or_next_token] Returns nil if all items were enumerated.
41
+ # If some items were excluded because of a `:limit` option then
42
+ # a `next_token` is returned. Calling an enumerable method on
43
+ # the same collection with the `next_token` acts like an offset.
44
+ #
45
+ def each options = {}, &block
46
+ each_batch(options) do |batch|
47
+ batch.each(&block)
48
+ end
49
+ end
50
+
51
+ # Yields items from this collection in batches.
52
+ #
53
+ # collection.each_batch do |batch|
54
+ # batch.each do |item|
55
+ # # ...
56
+ # end
57
+ # end
58
+ #
59
+ # ## Variable Batch Sizes
60
+ #
61
+ # Each MSS service has its own rules on how it returns results.
62
+ # Because of this batch size may very based on:
63
+ #
64
+ # * Service limits (e.g. S3 limits keys to 1000 per response)
65
+ #
66
+ # * The size of response objects (SimpleDB limits responses to 1MB)
67
+ #
68
+ # * Time to process the request
69
+ #
70
+ # Because of these variables, batch sizes may not be consistent for
71
+ # a single collection. Each batch represents all of the items returned
72
+ # in a single resopnse.
73
+ #
74
+ # @note If you require fixed batch sizes, see {#in_groups_of}.
75
+ # @param (see #each)
76
+ # @option (see #each)
77
+ # @return (see #each)
78
+ def each_batch options = {}, &block
79
+ _each_batch(options.dup, &block)
80
+ end
81
+
82
+ # Use this method when you want to call a method provided by
83
+ # Enumerable, but you need to pass options:
84
+ #
85
+ # # raises an error because collect does not accept arguments
86
+ # collection.collect(:limit => 10) {|i| i.name }
87
+ #
88
+ # # not an issue with the enum method
89
+ # collection.enum(:limit => 10).collect(&:name)
90
+ #
91
+ # @param (see #each)
92
+ # @option (see #each)
93
+ # @return [Enumerable::Enumerator] Returns an enumerator for this
94
+ # collection.
95
+ #
96
+ def enum options = {}
97
+ to_enum(:each, options)
98
+ end
99
+ alias_method :enumerator, :enum
100
+
101
+ # Returns the first item from this collection.
102
+ #
103
+ # @return [item_or_nil] Returns the first item from this collection or
104
+ # nil if the collection is empty.
105
+ #
106
+ def first options = {}
107
+ enum(options.merge(:limit => 1)).first
108
+ end
109
+
110
+ # Yields items from this collection in groups of an exact
111
+ # size (except for perhaps the last group).
112
+ #
113
+ # collection.in_groups_of (10, :limit => 30) do |group|
114
+ #
115
+ # # each group should be exactly 10 items unless
116
+ # # fewer than 30 items are returned by the service
117
+ # group.each do |item|
118
+ # #...
119
+ # end
120
+ #
121
+ # end
122
+ #
123
+ # @param [Integer] size Size each each group of objects
124
+ # should be yielded in.
125
+ # @param [Hash] options
126
+ # @option (see #each)
127
+ # @return (see #each)
128
+ def in_groups_of size, options = {}, &block
129
+
130
+ group = []
131
+
132
+ nil_or_next_token = each_batch(options) do |batch|
133
+ batch.each do |item|
134
+ group << item
135
+ if group.size == size
136
+ yield(group)
137
+ group = []
138
+ end
139
+ end
140
+ end
141
+
142
+ yield(group) unless group.empty?
143
+
144
+ nil_or_next_token
145
+
146
+ end
147
+
148
+ # Returns a single page of results in a kind-of array ({PageResult}).
149
+ #
150
+ # items = collection.page(:per_page => 10) # defaults to 10 items
151
+ # items.is_a?(Array) # => true
152
+ # items.size # => 8
153
+ # items.per_page # => 10
154
+ # items.last_page? # => true
155
+ #
156
+ # If you need to display a "next page" link in a web view you can
157
+ # use the #more? method. Just make sure the generated link
158
+ # contains the `next_token`.
159
+ #
160
+ # <% if items.more? %>
161
+ # <%= link_to('Next Page', params.merge(:next_token => items.next_token) %>
162
+ # <% end %>
163
+ #
164
+ # Then in your controller you can find the next page of results:
165
+ #
166
+ # items = collection.page(:next_token => params[:next_token])
167
+ #
168
+ # Given a {PageResult} you can also get more results directly:
169
+ #
170
+ # more_items = items.next_page
171
+ #
172
+ # @note This method does not accept a `:page` option, which means you
173
+ # can only start at the begining of the collection and request
174
+ # the next page of results. You can not choose an offset
175
+ # or know how many pages of results there will be.
176
+ #
177
+ # @param [Hash] options A hash of options that modifies the
178
+ # items returned in the page of results.
179
+ #
180
+ # @option options [Integer] :per_page (10) The number of results
181
+ # to return for each page.
182
+ #
183
+ # @option options [String] :next_token (nil) A token that indicates
184
+ # an offset to use when paging items. Next tokens are returned
185
+ # by {PageResult#next_token}.
186
+ #
187
+ # Next tokens should only be consumed by the same collection that
188
+ # created them.
189
+ #
190
+ def page options = {}
191
+
192
+ each_opts = options.dup
193
+
194
+ per_page = each_opts.delete(:per_page)
195
+ per_page = [nil,''].include?(per_page) ? 10 : per_page.to_i
196
+
197
+ each_opts[:limit] = per_page
198
+
199
+ items = []
200
+ next_token = each(each_opts) do |item|
201
+ items << item
202
+ end
203
+
204
+ Core::PageResult.new(self, items, per_page, next_token)
205
+
206
+ end
207
+
208
+ protected
209
+
210
+ def _each_batch options, &block
211
+ # should be defined in the collection modules
212
+ raise NotImplementedError
213
+ end
214
+
215
+ def _each_item next_token, options = {}, &block
216
+ # should be defined in classes included the collection modules
217
+ raise NotImplementedError
218
+ end
219
+
220
+ def _extract_next_token options
221
+ next_token = options.delete(:next_token)
222
+ next_token = nil if next_token == ''
223
+ next_token
224
+ end
225
+
226
+ def _extract_batch_size options
227
+ batch_size = options.delete(:batch_size)
228
+ batch_size = nil if batch_size == ''
229
+ batch_size = batch_size.to_i if batch_size
230
+ batch_size
231
+ end
232
+
233
+ def _extract_limit options
234
+ limit = options.delete(:limit) || _limit
235
+ limit = nil if limit == ''
236
+ limit = limit.to_i if limit
237
+ limit
238
+ end
239
+
240
+ # Override this method in collection classes that provide
241
+ # an alternative way to provide the limit than passinging
242
+ # it to the enumerable method as :limit.
243
+ #
244
+ # An example of when this would be useful:
245
+ #
246
+ # collection.limit(10).each {|item| ... }
247
+ #
248
+ # The collection class including this module should define _limit
249
+ # and return the cached limit value (of 10 from this example).
250
+ # This value may still be overridden by a locally passed
251
+ # `:limit` option:
252
+ #
253
+ # # limit 5 wins out
254
+ # collection.limit(10).each(:limit => 5) {|item| ... }
255
+ #
256
+ def _limit
257
+ nil
258
+ end
259
+
260
+ end
261
+ end
262
+ end