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.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/LICENSE.txt +0 -0
- data/README.md +192 -0
- data/bin/mss-rb +178 -0
- data/ca-bundle.crt +3554 -0
- data/lib/mss/core/async_handle.rb +89 -0
- data/lib/mss/core/cacheable.rb +76 -0
- data/lib/mss/core/client.rb +786 -0
- data/lib/mss/core/collection/simple.rb +81 -0
- data/lib/mss/core/collection/with_limit_and_next_token.rb +70 -0
- data/lib/mss/core/collection/with_next_token.rb +96 -0
- data/lib/mss/core/collection.rb +262 -0
- data/lib/mss/core/configuration.rb +527 -0
- data/lib/mss/core/credential_providers.rb +653 -0
- data/lib/mss/core/data.rb +251 -0
- data/lib/mss/core/deprecations.rb +83 -0
- data/lib/mss/core/endpoints.rb +36 -0
- data/lib/mss/core/http/connection_pool.rb +374 -0
- data/lib/mss/core/http/curb_handler.rb +150 -0
- data/lib/mss/core/http/handler.rb +88 -0
- data/lib/mss/core/http/net_http_handler.rb +144 -0
- data/lib/mss/core/http/patch.rb +98 -0
- data/lib/mss/core/http/request.rb +258 -0
- data/lib/mss/core/http/response.rb +80 -0
- data/lib/mss/core/indifferent_hash.rb +87 -0
- data/lib/mss/core/inflection.rb +55 -0
- data/lib/mss/core/ini_parser.rb +41 -0
- data/lib/mss/core/json_client.rb +46 -0
- data/lib/mss/core/json_parser.rb +75 -0
- data/lib/mss/core/json_request_builder.rb +34 -0
- data/lib/mss/core/json_response_parser.rb +78 -0
- data/lib/mss/core/lazy_error_classes.rb +107 -0
- data/lib/mss/core/log_formatter.rb +426 -0
- data/lib/mss/core/managed_file.rb +31 -0
- data/lib/mss/core/meta_utils.rb +44 -0
- data/lib/mss/core/model.rb +61 -0
- data/lib/mss/core/naming.rb +29 -0
- data/lib/mss/core/option_grammar.rb +737 -0
- data/lib/mss/core/options/json_serializer.rb +81 -0
- data/lib/mss/core/options/validator.rb +154 -0
- data/lib/mss/core/options/xml_serializer.rb +117 -0
- data/lib/mss/core/page_result.rb +74 -0
- data/lib/mss/core/policy.rb +938 -0
- data/lib/mss/core/query_client.rb +40 -0
- data/lib/mss/core/query_error_parser.rb +23 -0
- data/lib/mss/core/query_request_builder.rb +46 -0
- data/lib/mss/core/query_response_parser.rb +34 -0
- data/lib/mss/core/region.rb +84 -0
- data/lib/mss/core/region_collection.rb +79 -0
- data/lib/mss/core/resource.rb +412 -0
- data/lib/mss/core/resource_cache.rb +39 -0
- data/lib/mss/core/response.rb +214 -0
- data/lib/mss/core/response_cache.rb +49 -0
- data/lib/mss/core/rest_error_parser.rb +23 -0
- data/lib/mss/core/rest_json_client.rb +39 -0
- data/lib/mss/core/rest_request_builder.rb +153 -0
- data/lib/mss/core/rest_response_parser.rb +65 -0
- data/lib/mss/core/rest_xml_client.rb +46 -0
- data/lib/mss/core/service_interface.rb +82 -0
- data/lib/mss/core/signers/base.rb +45 -0
- data/lib/mss/core/signers/cloud_front.rb +55 -0
- data/lib/mss/core/signers/s3.rb +158 -0
- data/lib/mss/core/signers/version_2.rb +71 -0
- data/lib/mss/core/signers/version_3.rb +85 -0
- data/lib/mss/core/signers/version_3_https.rb +60 -0
- data/lib/mss/core/signers/version_4/chunk_signed_stream.rb +190 -0
- data/lib/mss/core/signers/version_4.rb +227 -0
- data/lib/mss/core/uri_escape.rb +43 -0
- data/lib/mss/core/xml/frame.rb +245 -0
- data/lib/mss/core/xml/frame_stack.rb +84 -0
- data/lib/mss/core/xml/grammar.rb +306 -0
- data/lib/mss/core/xml/parser.rb +69 -0
- data/lib/mss/core/xml/root_frame.rb +64 -0
- data/lib/mss/core/xml/sax_handlers/libxml.rb +46 -0
- data/lib/mss/core/xml/sax_handlers/nokogiri.rb +55 -0
- data/lib/mss/core/xml/sax_handlers/ox.rb +40 -0
- data/lib/mss/core/xml/sax_handlers/rexml.rb +46 -0
- data/lib/mss/core/xml/stub.rb +122 -0
- data/lib/mss/core.rb +602 -0
- data/lib/mss/errors.rb +161 -0
- data/lib/mss/rails.rb +194 -0
- data/lib/mss/s3/access_control_list.rb +262 -0
- data/lib/mss/s3/acl_object.rb +263 -0
- data/lib/mss/s3/acl_options.rb +200 -0
- data/lib/mss/s3/bucket.rb +757 -0
- data/lib/mss/s3/bucket_collection.rb +161 -0
- data/lib/mss/s3/bucket_lifecycle_configuration.rb +472 -0
- data/lib/mss/s3/bucket_region_cache.rb +51 -0
- data/lib/mss/s3/bucket_tag_collection.rb +110 -0
- data/lib/mss/s3/bucket_version_collection.rb +78 -0
- data/lib/mss/s3/cipher_io.rb +119 -0
- data/lib/mss/s3/client/xml.rb +265 -0
- data/lib/mss/s3/client.rb +2076 -0
- data/lib/mss/s3/config.rb +60 -0
- data/lib/mss/s3/cors_rule.rb +107 -0
- data/lib/mss/s3/cors_rule_collection.rb +193 -0
- data/lib/mss/s3/data_options.rb +190 -0
- data/lib/mss/s3/encryption_utils.rb +145 -0
- data/lib/mss/s3/errors.rb +93 -0
- data/lib/mss/s3/multipart_upload.rb +353 -0
- data/lib/mss/s3/multipart_upload_collection.rb +75 -0
- data/lib/mss/s3/object_collection.rb +355 -0
- data/lib/mss/s3/object_metadata.rb +102 -0
- data/lib/mss/s3/object_upload_collection.rb +76 -0
- data/lib/mss/s3/object_version.rb +153 -0
- data/lib/mss/s3/object_version_collection.rb +88 -0
- data/lib/mss/s3/paginated_collection.rb +74 -0
- data/lib/mss/s3/policy.rb +73 -0
- data/lib/mss/s3/prefix_and_delimiter_collection.rb +46 -0
- data/lib/mss/s3/prefixed_collection.rb +84 -0
- data/lib/mss/s3/presign_v4.rb +135 -0
- data/lib/mss/s3/presigned_post.rb +574 -0
- data/lib/mss/s3/region_detection.rb +75 -0
- data/lib/mss/s3/request.rb +61 -0
- data/lib/mss/s3/s3_object.rb +1795 -0
- data/lib/mss/s3/tree/branch_node.rb +67 -0
- data/lib/mss/s3/tree/child_collection.rb +103 -0
- data/lib/mss/s3/tree/leaf_node.rb +93 -0
- data/lib/mss/s3/tree/node.rb +21 -0
- data/lib/mss/s3/tree/parent.rb +86 -0
- data/lib/mss/s3/tree.rb +115 -0
- data/lib/mss/s3/uploaded_part.rb +81 -0
- data/lib/mss/s3/uploaded_part_collection.rb +83 -0
- data/lib/mss/s3/website_configuration.rb +101 -0
- data/lib/mss/s3.rb +161 -0
- data/lib/mss/version.rb +16 -0
- data/lib/mss-sdk.rb +2 -0
- data/lib/mss.rb +14 -0
- data/rails/init.rb +14 -0
- metadata +201 -0
data/lib/mss/core.rb
ADDED
@@ -0,0 +1,602 @@
|
|
1
|
+
# Copyright 2011-2014 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 'set'
|
14
|
+
require 'securerandom'
|
15
|
+
|
16
|
+
# MSS is the root module for all of the Amazon Web Services. It is also
|
17
|
+
# where you can configure you access to MSS.
|
18
|
+
#
|
19
|
+
# # Configuration
|
20
|
+
#
|
21
|
+
# Call {MSS.config} with a hash of options to configure your
|
22
|
+
# access to the Amazon Web Services.
|
23
|
+
#
|
24
|
+
# At a minimum you need to set your access credentials. See {MSS.config}
|
25
|
+
# for additional configuration options.
|
26
|
+
#
|
27
|
+
# MSS.config(
|
28
|
+
# :access_key_id => 'ACCESS_KEY_ID',
|
29
|
+
# :secret_access_key => 'SECRET_ACCESS_KEY',
|
30
|
+
# :region => 'us-west-2')
|
31
|
+
#
|
32
|
+
module MSS
|
33
|
+
|
34
|
+
# @api private
|
35
|
+
class SvcDetails
|
36
|
+
def initialize class_name, options
|
37
|
+
@class_name = class_name
|
38
|
+
@full_name = options[:full_name]
|
39
|
+
@method_name = options[:method_name]
|
40
|
+
@method_alias = options[:method_alias]
|
41
|
+
@old_name = @method_alias || @method_name
|
42
|
+
end
|
43
|
+
attr_reader :class_name, :full_name, :method_name, :method_alias, :old_name
|
44
|
+
end
|
45
|
+
|
46
|
+
# @api private
|
47
|
+
SERVICES = [
|
48
|
+
SvcDetails.new("S3",
|
49
|
+
:full_name => "Meituan Simple Storage Service",
|
50
|
+
:method_name => :s3)
|
51
|
+
].inject({}) { |h,svc| h[svc.class_name] = svc; h }
|
52
|
+
|
53
|
+
# @api private
|
54
|
+
ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
55
|
+
|
56
|
+
SRC = ROOT + '/lib/mss'
|
57
|
+
|
58
|
+
autoload :Errors, "#{SRC}/errors"
|
59
|
+
autoload :Record, "#{SRC}/record"
|
60
|
+
autoload :VERSION, "#{SRC}/version"
|
61
|
+
|
62
|
+
module Core
|
63
|
+
|
64
|
+
autoload :AsyncHandle, "#{SRC}/core/async_handle"
|
65
|
+
autoload :Cacheable, "#{SRC}/core/cacheable"
|
66
|
+
autoload :Client, "#{SRC}/core/client"
|
67
|
+
autoload :Collection, "#{SRC}/core/collection"
|
68
|
+
autoload :Configuration, "#{SRC}/core/configuration"
|
69
|
+
autoload :CredentialProviders, "#{SRC}/core/credential_providers"
|
70
|
+
autoload :Data, "#{SRC}/core/data"
|
71
|
+
autoload :Deprecations, "#{SRC}/core/deprecations"
|
72
|
+
autoload :Endpoints, "#{SRC}/core/endpoints"
|
73
|
+
autoload :IndifferentHash, "#{SRC}/core/indifferent_hash"
|
74
|
+
autoload :Inflection, "#{SRC}/core/inflection"
|
75
|
+
autoload :IniParser, "#{SRC}/core/ini_parser"
|
76
|
+
autoload :JSONParser, "#{SRC}/core/json_parser"
|
77
|
+
|
78
|
+
autoload :JSONClient, "#{SRC}/core/json_client"
|
79
|
+
autoload :JSONRequestBuilder, "#{SRC}/core/json_request_builder"
|
80
|
+
autoload :JSONResponseParser, "#{SRC}/core/json_response_parser"
|
81
|
+
|
82
|
+
autoload :LazyErrorClasses, "#{SRC}/core/lazy_error_classes"
|
83
|
+
autoload :LogFormatter, "#{SRC}/core/log_formatter"
|
84
|
+
autoload :MetaUtils, "#{SRC}/core/meta_utils"
|
85
|
+
autoload :ManagedFile, "#{SRC}/core/managed_file"
|
86
|
+
autoload :Model, "#{SRC}/core/model"
|
87
|
+
autoload :Naming, "#{SRC}/core/naming"
|
88
|
+
autoload :OptionGrammar, "#{SRC}/core/option_grammar"
|
89
|
+
autoload :PageResult, "#{SRC}/core/page_result"
|
90
|
+
autoload :Policy, "#{SRC}/core/policy"
|
91
|
+
|
92
|
+
autoload :QueryClient, "#{SRC}/core/query_client"
|
93
|
+
autoload :QueryRequestBuilder, "#{SRC}/core/query_request_builder"
|
94
|
+
autoload :QueryResponseParser, "#{SRC}/core/query_response_parser"
|
95
|
+
|
96
|
+
autoload :Region, "#{SRC}/core/region"
|
97
|
+
autoload :RegionCollection, "#{SRC}/core/region_collection"
|
98
|
+
|
99
|
+
autoload :Resource, "#{SRC}/core/resource"
|
100
|
+
autoload :ResourceCache, "#{SRC}/core/resource_cache"
|
101
|
+
autoload :Response, "#{SRC}/core/response"
|
102
|
+
autoload :ResponseCache, "#{SRC}/core/response_cache"
|
103
|
+
|
104
|
+
autoload :RESTClient, "#{SRC}/core/rest_xml_client"
|
105
|
+
autoload :RESTJSONClient, "#{SRC}/core/rest_json_client"
|
106
|
+
autoload :RESTXMLClient, "#{SRC}/core/rest_xml_client"
|
107
|
+
autoload :RESTRequestBuilder, "#{SRC}/core/rest_request_builder"
|
108
|
+
autoload :RESTResponseParser, "#{SRC}/core/rest_response_parser"
|
109
|
+
|
110
|
+
autoload :ServiceInterface, "#{SRC}/core/service_interface"
|
111
|
+
autoload :UriEscape, "#{SRC}/core/uri_escape"
|
112
|
+
|
113
|
+
module Options
|
114
|
+
autoload :JSONSerializer, "#{SRC}/core/options/json_serializer"
|
115
|
+
autoload :XMLSerializer, "#{SRC}/core/options/xml_serializer"
|
116
|
+
autoload :Validator, "#{SRC}/core/options/validator"
|
117
|
+
end
|
118
|
+
|
119
|
+
module Signers
|
120
|
+
autoload :Base, "#{SRC}/core/signers/base"
|
121
|
+
autoload :CloudFront, "#{SRC}/core/signers/cloud_front"
|
122
|
+
autoload :S3, "#{SRC}/core/signers/s3"
|
123
|
+
autoload :Version2, "#{SRC}/core/signers/version_2"
|
124
|
+
autoload :Version3, "#{SRC}/core/signers/version_3"
|
125
|
+
autoload :Version3Https, "#{SRC}/core/signers/version_3_https"
|
126
|
+
autoload :Version4, "#{SRC}/core/signers/version_4"
|
127
|
+
end
|
128
|
+
|
129
|
+
module XML
|
130
|
+
|
131
|
+
autoload :Parser, "#{SRC}/core/xml/parser"
|
132
|
+
autoload :Grammar, "#{SRC}/core/xml/grammar"
|
133
|
+
autoload :Stub, "#{SRC}/core/xml/stub"
|
134
|
+
autoload :Frame, "#{SRC}/core/xml/frame"
|
135
|
+
autoload :RootFrame, "#{SRC}/core/xml/root_frame"
|
136
|
+
autoload :FrameStack, "#{SRC}/core/xml/frame_stack"
|
137
|
+
|
138
|
+
module SaxHandlers
|
139
|
+
autoload :Nokogiri, "#{SRC}/core/xml/sax_handlers/nokogiri"
|
140
|
+
autoload :REXML, "#{SRC}/core/xml/sax_handlers/rexml"
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
module Http
|
146
|
+
autoload :ConnectionPool, "#{SRC}/core/http/connection_pool"
|
147
|
+
autoload :Handler, "#{SRC}/core/http/handler"
|
148
|
+
autoload :NetHttpHandler, "#{SRC}/core/http/net_http_handler"
|
149
|
+
autoload :Request, "#{SRC}/core/http/request"
|
150
|
+
autoload :Response, "#{SRC}/core/http/response"
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
class << self
|
156
|
+
|
157
|
+
SERVICES.values.each do |svc|
|
158
|
+
define_method(svc.method_name) do |*args|
|
159
|
+
MSS.const_get(svc.class_name).new(args.first || {})
|
160
|
+
end
|
161
|
+
alias_method(svc.method_alias, svc.method_name) if svc.method_alias
|
162
|
+
end
|
163
|
+
|
164
|
+
# @api private
|
165
|
+
@@config = nil
|
166
|
+
|
167
|
+
# The global configuration for MSS. Generally you set your preferred
|
168
|
+
# configuration operations once after loading the mss-sdk gem.
|
169
|
+
#
|
170
|
+
# MSS.config({
|
171
|
+
# :access_key_id => 'ACCESS_KEY_ID',
|
172
|
+
# :secret_access_key => 'SECRET_ACCESS_KEY',
|
173
|
+
# :region => 'us-west-2',
|
174
|
+
# })
|
175
|
+
#
|
176
|
+
# When using MSS classes they will always default to use configuration
|
177
|
+
# values defined in {MSS.config}.
|
178
|
+
#
|
179
|
+
# MSS.config(:max_retries => 2)
|
180
|
+
#
|
181
|
+
# sqs = MSS::SQS.new
|
182
|
+
# sqs.config.max_retries #=> 2
|
183
|
+
#
|
184
|
+
# If you want to change a configuration value for a single instance you
|
185
|
+
# pass the new configuration value to that object's initializer:
|
186
|
+
#
|
187
|
+
# MSS::SQS.new(:max_retries => 0)
|
188
|
+
#
|
189
|
+
# @note Changing the global configuration does not affect objects
|
190
|
+
# that have already been constructed.
|
191
|
+
#
|
192
|
+
# @param [Hash] options
|
193
|
+
#
|
194
|
+
# @option options [String] :access_key_id MSS access key id
|
195
|
+
# credential.
|
196
|
+
#
|
197
|
+
# @option options [String] :secret_access_key MSS secret access
|
198
|
+
# key credential.
|
199
|
+
#
|
200
|
+
# @option options [String,nil] :session_token MSS secret token
|
201
|
+
# credential.
|
202
|
+
#
|
203
|
+
# @option options [String] :region ('us-east-1') The default MSS region.
|
204
|
+
#
|
205
|
+
# @option options [Boolean] :dynamo_db_big_decimals (true) When `true`,
|
206
|
+
# {DynamoDB} will convert number values returned by {DynamoDB::Client}
|
207
|
+
# from strings to BigDecimal objects. If you set this to `false`,
|
208
|
+
# they will be converted from strings into floats (with a potential
|
209
|
+
# loss of precision).
|
210
|
+
#
|
211
|
+
# @option options [Boolean] :dynamo_db_retry_throughput_errors (true) When
|
212
|
+
# true, MSS::DynamoDB::Errors::ProvisionedThroughputExceededException
|
213
|
+
# errors will be retried.
|
214
|
+
#
|
215
|
+
# @option options [Object] :http_handler (MSS::Core::Http::NetHttpHandler)
|
216
|
+
# The http handler that sends requests to MSS.
|
217
|
+
#
|
218
|
+
# @option options [Integer] :http_idle_timeout (60) The number of seconds
|
219
|
+
# a persistent connection is allowed to sit idle before it should no
|
220
|
+
# longer be used.
|
221
|
+
#
|
222
|
+
# @option options [Integer] :http_open_timeout (15) The number of seconds
|
223
|
+
# before the `:http_handler` should timeout while trying to open a new
|
224
|
+
# HTTP session.
|
225
|
+
#
|
226
|
+
# @option options [Integer] :http_read_timeout (60) The number of seconds
|
227
|
+
# before the `:http_handler` should timeout while waiting for a HTTP
|
228
|
+
# response.
|
229
|
+
#
|
230
|
+
# @option options [Boolean] :http_wire_trace (false) When `true`, the
|
231
|
+
# http handler will log all wire traces to the `:logger`. If a
|
232
|
+
# `:logger` is not configured, then wire traces will be sent to
|
233
|
+
# standard out.
|
234
|
+
#
|
235
|
+
# @option options [Logger,nil] :logger (nil) A logger to send
|
236
|
+
# log messages to. Here is an example that logs to standard out.
|
237
|
+
#
|
238
|
+
# require 'logger'
|
239
|
+
# MSS.config(:logger => Logger.new($stdout))
|
240
|
+
#
|
241
|
+
# @option options [Symbol] :log_level (:info) The level log messages are
|
242
|
+
# sent to the logger with (e.g. `:notice`, `:info`, `:warn`,
|
243
|
+
# `:debug`, etc).
|
244
|
+
#
|
245
|
+
# @option options [Object] :log_formatter The log formatter is responsible
|
246
|
+
# for building log messages from responses. You can quickly change
|
247
|
+
# log formats by providing a pre-configured log formatter.
|
248
|
+
#
|
249
|
+
# MSS.config(:log_formatter => MSS::Core::LogFormatter.colored)
|
250
|
+
#
|
251
|
+
# Here is a list of pre-configured log formatters:
|
252
|
+
#
|
253
|
+
# * `MSS::Core::LogFormatter.default`
|
254
|
+
# * `MSS::Core::LogFormatter.short`
|
255
|
+
# * `MSS::Core::LogFormatter.debug`
|
256
|
+
# * `MSS::Core::LogFormatter.colored`
|
257
|
+
#
|
258
|
+
# You can also create an instance of MSS::Core::LogFormatter
|
259
|
+
# with a custom log message pattern. See {Core::LogFormatter} for
|
260
|
+
# a complete list of pattern substitutions.
|
261
|
+
#
|
262
|
+
# pattern = "[MSS :operation :duration] :error_message"
|
263
|
+
# MSS.config(:log_formatter => MSS::Core::LogFormatter.new(pattern))
|
264
|
+
#
|
265
|
+
# Lastly you can pass any object that responds to `#format` accepting
|
266
|
+
# and instance of {Core::Response} and returns a string.
|
267
|
+
#
|
268
|
+
# @option options [Integer] :max_retries (3) The maximum number of times
|
269
|
+
# service errors (500) and throttling errors should be retried. There is
|
270
|
+
# an exponential backoff in between retries, so the more retries the
|
271
|
+
# longer it can take to fail.
|
272
|
+
#
|
273
|
+
# @option options [String, URI, nil] :proxy_uri (nil) The URI of the proxy
|
274
|
+
# to send service requests through. You can pass a URI object or a
|
275
|
+
# URI string:
|
276
|
+
#
|
277
|
+
# MSS.config(:proxy_uri => 'https://user:password@my.proxy:443/path?query')
|
278
|
+
#
|
279
|
+
# @option options [Boolean] :s3_force_path_style (false) When
|
280
|
+
# `true`, requests will always use path style. This can be useful
|
281
|
+
# for testing environments.
|
282
|
+
#
|
283
|
+
# @option options [Integer] :s3_multipart_max_parts (10000) The maximum
|
284
|
+
# number of parts to split a file into when uploading in parts to S3.
|
285
|
+
#
|
286
|
+
# @option options [Integer] :s3_multipart_threshold (16777216) When
|
287
|
+
# uploading data to S3, if the number of bytes to send exceeds
|
288
|
+
# `:s3_multipart_threshold` then a multi part session is automatically
|
289
|
+
# started and the data is sent up in chunks. The size of each part
|
290
|
+
# is specified by `:s3_multipart_min_part_size`. Defaults to
|
291
|
+
# 16777216 (16MB).
|
292
|
+
#
|
293
|
+
# @option options [Integer] :s3_multipart_min_part_size (5242880) The
|
294
|
+
# absolute minimum size (in bytes) each S3 multipart segment should be.
|
295
|
+
# Defaults to 5242880 (5MB).
|
296
|
+
#
|
297
|
+
# @option options [Symbol] :s3_server_side_encryption (nil) The
|
298
|
+
# algorithm to use when encrypting object data on the server
|
299
|
+
# side. The only valid value is `:aes256`, which specifies that
|
300
|
+
# the object should be stored using the AES encryption algorithm
|
301
|
+
# with 256 bit keys. Defaults to `nil`, meaning server side
|
302
|
+
# encryption is not used unless specified on each individual
|
303
|
+
# call to upload an object. This option controls the default
|
304
|
+
# behavior for the following methods:
|
305
|
+
#
|
306
|
+
# * {S3::S3Object#write}
|
307
|
+
# * {S3::S3Object#multipart_upload}
|
308
|
+
# * {S3::S3Object#copy_from} and {S3::S3Object#copy_to}
|
309
|
+
# * {S3::S3Object#presigned_post}
|
310
|
+
# * {S3::Bucket#presigned_post}
|
311
|
+
#
|
312
|
+
# @option options [OpenSSL::PKey::RSA, String] :s3_encryption_key (nil)
|
313
|
+
# If this is set, MSS::S3::S3Object #read and #write methods will always
|
314
|
+
# perform client-side encryption with this key. The key can be overridden
|
315
|
+
# at runtime by using the :encryption_key option. A value of nil
|
316
|
+
# means that client-side encryption will not be used.
|
317
|
+
#
|
318
|
+
# @option options [Symbol] :s3_encryption_materials_location (:metadata)
|
319
|
+
# When set to `:instruction_file`, MSS::S3::S3Object will store
|
320
|
+
# encryption materials in a separate object, instead of the object
|
321
|
+
# metadata.
|
322
|
+
#
|
323
|
+
# @option options [Boolean] :simple_db_consistent_reads (false) Determines
|
324
|
+
# if all SimpleDB read requests should be done consistently.
|
325
|
+
# Consistent reads are slower, but reflect all changes to SDB.
|
326
|
+
#
|
327
|
+
# @option options [CredentialProviders::Provider] :credential_provider (MSS::Core::CredentialProviders::DefaultProvider.new)
|
328
|
+
# Returns the credential provider. The default credential provider
|
329
|
+
# attempts to check for statically assigned credentials, ENV credentials
|
330
|
+
# and credentials in the metadata service of EC2.
|
331
|
+
#
|
332
|
+
# @option options [String] :ssl_ca_file The path to a CA cert bundle in
|
333
|
+
# PEM format.
|
334
|
+
#
|
335
|
+
# If `:ssl_verify_peer` is `true` (the default) this bundle will be
|
336
|
+
# used to validate the server certificate in each HTTPS request.
|
337
|
+
# The MSS SDK for Ruby ships with a CA cert bundle, which is the
|
338
|
+
# default value for this option.
|
339
|
+
#
|
340
|
+
# @option options [String] :ssl_ca_path (nil)
|
341
|
+
# The path the a CA cert directory.
|
342
|
+
#
|
343
|
+
# @option options [Boolean] :ssl_verify_peer (true) When `true`
|
344
|
+
# the HTTP handler validate server certificates for HTTPS requests.
|
345
|
+
#
|
346
|
+
# This option should only be disabled for diagnostic purposes;
|
347
|
+
# leaving this option set to `false` exposes your application to
|
348
|
+
# man-in-the-middle attacks and can pose a serious security
|
349
|
+
# risk.
|
350
|
+
#
|
351
|
+
# @option options [Boolean] :stub_requests (false) When `true` requests
|
352
|
+
# are not sent to MSS, instead empty responses are generated and
|
353
|
+
# returned to each service request.
|
354
|
+
#
|
355
|
+
# @option options [Boolean] :use_ssl (true) When `true`, all requests
|
356
|
+
# to MSS are sent using HTTPS instead vanilla HTTP.
|
357
|
+
#
|
358
|
+
# @option options [String] :user_agent_prefix (nil) A string prefix to
|
359
|
+
# append to all requests against MSS services. This should be set
|
360
|
+
# for clients and applications built ontop of the mss-sdk gem.
|
361
|
+
#
|
362
|
+
# @option options [Boolean] :verify_response_body_content_length (true)
|
363
|
+
# When `true` all HTTP handlers will perform a check to ensure
|
364
|
+
# that response bodies match the content-length specified in the
|
365
|
+
# response header, if present. Note that some HTTP handlers will
|
366
|
+
# always do this whether or not this value is true.
|
367
|
+
#
|
368
|
+
# @option options [Boolean] :sqs_verify_checksums (true)
|
369
|
+
# When `true` all SQS operations will check body content against
|
370
|
+
# MD5 checksums, raising an exception if there is a mismatch.
|
371
|
+
#
|
372
|
+
# @return [Core::Configuration] Returns the new configuration.
|
373
|
+
#
|
374
|
+
def config options = {}
|
375
|
+
@@config ||= Core::Configuration.new
|
376
|
+
@@config = @@config.with(options) unless options.empty?
|
377
|
+
@@config
|
378
|
+
end
|
379
|
+
|
380
|
+
# Returns a collection that represents public (non-gov-cloud) MSS
|
381
|
+
# regions. You can use this collection to get a specific region by name
|
382
|
+
# or to enumerate all regions.
|
383
|
+
#
|
384
|
+
# When enumerating regions, a single HTTP request is made to get a current
|
385
|
+
# list of regions (this is cached). When getting a region by name
|
386
|
+
# no requests are made.
|
387
|
+
#
|
388
|
+
# @example Getting a region by name
|
389
|
+
#
|
390
|
+
# region = MSS.regions['us-west-1']
|
391
|
+
# region.dynamo_db.tables.map(&:name)
|
392
|
+
#
|
393
|
+
# @example Enumerating all regions
|
394
|
+
#
|
395
|
+
# MSS.regions.each do |region|
|
396
|
+
# puts "EC2 Instances in #{region.name}:"
|
397
|
+
# puts region.ec2.instances.map(&:id)
|
398
|
+
# end
|
399
|
+
#
|
400
|
+
# @return [Core::RegionCollection]
|
401
|
+
def regions
|
402
|
+
Core::RegionCollection.new
|
403
|
+
end
|
404
|
+
|
405
|
+
# @note Memoization is currently only supported for APIs which
|
406
|
+
# inherit from the "Resource" class; other APIs are unaffected
|
407
|
+
# by the status of memoization.
|
408
|
+
#
|
409
|
+
# Resets memoizing service requests made in the current thread.
|
410
|
+
# See {memoize} for a full discussion of the memoization feature.
|
411
|
+
# This has no effect if memoization is already enabled.
|
412
|
+
def reset_memoization
|
413
|
+
Thread.current[:mss_memoization] = {}
|
414
|
+
end
|
415
|
+
|
416
|
+
# @note Memoization is currently only supported for APIs which
|
417
|
+
# inherit from the "Resource" class; other APIs are unaffected
|
418
|
+
# by the status of memoization.
|
419
|
+
#
|
420
|
+
# Starts memoizing service requests made in the current thread.
|
421
|
+
# See {memoize} for a full discussion of the memoization feature.
|
422
|
+
# This has no effect if memoization is already enabled.
|
423
|
+
def start_memoizing
|
424
|
+
Thread.current[:mss_memoization] ||= {}
|
425
|
+
nil
|
426
|
+
end
|
427
|
+
|
428
|
+
# @note Memoization is currently only supported for APIs which
|
429
|
+
# inherit from the "Resource" class; other APIs are unaffected
|
430
|
+
# by the status of memoization.
|
431
|
+
#
|
432
|
+
# Stops memoizing service requests made in the current thread.
|
433
|
+
# See {memoize} for a full discussion of the memoization feature.
|
434
|
+
# This has no effect if memoization is already disabled.
|
435
|
+
def stop_memoizing
|
436
|
+
Thread.current[:mss_memoization] = nil
|
437
|
+
end
|
438
|
+
|
439
|
+
# @note Memoization is currently only supported for APIs which
|
440
|
+
# inherit from the "Resource" class; other APIs are unaffected
|
441
|
+
# by the status of memoization.
|
442
|
+
#
|
443
|
+
# @return [Boolean] True if memoization is enabled for the current
|
444
|
+
# thread. See {memoize} for a full discussion of the
|
445
|
+
# memoization feature.
|
446
|
+
def memoizing?
|
447
|
+
!Thread.current[:mss_memoization].nil?
|
448
|
+
end
|
449
|
+
|
450
|
+
# @note Memoization is currently only supported for APIs which
|
451
|
+
# inherit from the "Resource" class; other APIs are unaffected
|
452
|
+
# by the status of memoization.
|
453
|
+
#
|
454
|
+
# Enables memoization for the current thread, within a block.
|
455
|
+
# Memoization lets you avoid making multiple requests for the same
|
456
|
+
# data by reusing the responses which have already been received.
|
457
|
+
# For example, consider the following code to get the most
|
458
|
+
# recently launched EC2 instance:
|
459
|
+
#
|
460
|
+
# latest = ec2.instances.sort_by(&:launch_time).last
|
461
|
+
#
|
462
|
+
# The above code would make N+1 requests (where N is the number of
|
463
|
+
# instances in the account); iterating the collection of instances
|
464
|
+
# is one request, and `Enumerable#sort_by` calls
|
465
|
+
# {MSS::EC2::Instance#launch_time} for each instance, causing
|
466
|
+
# another request per instance. We can rewrite the code as
|
467
|
+
# follows to make only one request:
|
468
|
+
#
|
469
|
+
# latest = MSS.memoize do
|
470
|
+
# ec2.instances.sort_by(&:launch_time).last
|
471
|
+
# end
|
472
|
+
#
|
473
|
+
# Iterating the collection still causes a request, but each
|
474
|
+
# subsequent call to {MSS::EC2::Instance#launch_time} uses the
|
475
|
+
# results from that first request rather than making a new request
|
476
|
+
# for the same data.
|
477
|
+
#
|
478
|
+
# While memoization is enabled, every response that is received
|
479
|
+
# from the service is retained in memory. Therefore you should
|
480
|
+
# use memoization only for short-lived blocks of code that make
|
481
|
+
# relatively small numbers of requests. The cached responses are
|
482
|
+
# used in two ways while memoization is enabled:
|
483
|
+
#
|
484
|
+
# * Before making a request, the SDK checks the cache for a
|
485
|
+
# response to a request with the same signature (credentials,
|
486
|
+
# service endpoint, operation name, and parameters). If such a
|
487
|
+
# response is found, it is used instead of making a new
|
488
|
+
# request.
|
489
|
+
#
|
490
|
+
# * Before retrieving data for an attribute of a resource
|
491
|
+
# (e.g. {MSS::EC2::Instance#launch_time}), the SDK attempts to
|
492
|
+
# find a cached response that contains the requested data. If
|
493
|
+
# such a response is found, the cached data is returned instead
|
494
|
+
# of making a new request.
|
495
|
+
#
|
496
|
+
# When memoization is disabled, all previously cached responses
|
497
|
+
# are discarded.
|
498
|
+
def memoize
|
499
|
+
return yield if memoizing?
|
500
|
+
begin
|
501
|
+
start_memoizing
|
502
|
+
yield if block_given?
|
503
|
+
ensure
|
504
|
+
stop_memoizing
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
# @api private
|
509
|
+
def resource_cache
|
510
|
+
if memoizing?
|
511
|
+
Thread.current[:mss_memoization][:resource_cache] ||=
|
512
|
+
Core::ResourceCache.new
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
# @api private
|
517
|
+
def response_cache
|
518
|
+
if memoizing?
|
519
|
+
Thread.current[:mss_memoization][:response_cache] ||=
|
520
|
+
Core::ResponseCache.new
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
# Causes all requests to return empty responses without making any
|
525
|
+
# requests against the live services. This does not attempt to
|
526
|
+
# mock the services.
|
527
|
+
# @return [nil]
|
528
|
+
def stub!
|
529
|
+
config(:stub_requests => true)
|
530
|
+
nil
|
531
|
+
end
|
532
|
+
|
533
|
+
# Eagerly loads all MSS classes/modules registered with autoload.
|
534
|
+
# @return [void]
|
535
|
+
def eager_autoload! klass_or_module = MSS, visited = Set.new
|
536
|
+
klass_or_module.constants.each do |const_name|
|
537
|
+
path = klass_or_module.autoload?(const_name)
|
538
|
+
require(path) if path
|
539
|
+
const = klass_or_module.const_get(const_name)
|
540
|
+
if const.is_a?(Module)
|
541
|
+
unless visited.include?(const)
|
542
|
+
visited << const
|
543
|
+
eager_autoload!(const, visited)
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
547
|
+
visited
|
548
|
+
end
|
549
|
+
|
550
|
+
# Now deprecated, as the SDK will always patch Net::HTTP when loaded.
|
551
|
+
# @api private
|
552
|
+
def patch_net_http_100_continue!
|
553
|
+
nil
|
554
|
+
end
|
555
|
+
|
556
|
+
# @api private
|
557
|
+
# @return [Hash]
|
558
|
+
def api_versions
|
559
|
+
@versions ||= begin
|
560
|
+
# get a list of support services/apis from disk
|
561
|
+
versions = {}
|
562
|
+
pattern = File.join(File.dirname(__FILE__), 'api_config', '*.yml')
|
563
|
+
Dir.glob(pattern).each do |path|
|
564
|
+
path.match(/(\w+)-(\d{4}-\d{2}-\d{2})/)
|
565
|
+
svc = SERVICES[$1].full_name
|
566
|
+
versions[svc] ||= []
|
567
|
+
versions[svc] << $2
|
568
|
+
end
|
569
|
+
|
570
|
+
# s3 does not have an API configuration, so we have to add it manually
|
571
|
+
versions[SERVICES['S3'].full_name] = ['2006-03-01']
|
572
|
+
|
573
|
+
# sort the services alphabetically
|
574
|
+
versions.keys.sort_by(&:downcase).inject({}) do |hash,svc|
|
575
|
+
hash[svc] = versions[svc]
|
576
|
+
hash
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
580
|
+
end
|
581
|
+
|
582
|
+
SERVICES.values.each do |svc|
|
583
|
+
autoload(svc.class_name, "mss/#{svc.old_name}")
|
584
|
+
require "mss/#{svc.old_name}/config"
|
585
|
+
end
|
586
|
+
|
587
|
+
end
|
588
|
+
|
589
|
+
# Backport SecureRandom.uuid for Ruby 1.8
|
590
|
+
unless SecureRandom.respond_to?(:uuid)
|
591
|
+
module SecureRandom
|
592
|
+
def self.uuid
|
593
|
+
ary = random_bytes(16).unpack("NnnnnN")
|
594
|
+
ary[2] = (ary[2] & 0x0fff) | 0x4000
|
595
|
+
ary[3] = (ary[3] & 0x3fff) | 0x8000
|
596
|
+
"%08x-%04x-%04x-%04x-%04x%08x" % ary
|
597
|
+
end
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
require 'mss/core/http/patch'
|
602
|
+
MSS::Core::Http::Patches.apply!
|