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
@@ -0,0 +1,527 @@
|
|
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 'set'
|
14
|
+
require 'uri'
|
15
|
+
|
16
|
+
module MSS
|
17
|
+
module Core
|
18
|
+
|
19
|
+
# A configuration object for MSS interfaces and clients.
|
20
|
+
#
|
21
|
+
# ## Configuring Credentials
|
22
|
+
#
|
23
|
+
# In order to do anything with MSS you will need to assign credentials.
|
24
|
+
# The simplest method is to assign your credentials into the default
|
25
|
+
# configuration:
|
26
|
+
#
|
27
|
+
# MSS.config(:access_key_id => 'KEY', :secret_access_key => 'SECRET')
|
28
|
+
#
|
29
|
+
# You can also export them into your environment and they will be picked up
|
30
|
+
# automatically:
|
31
|
+
#
|
32
|
+
# export MSS_ACCESS_KEY_ID='YOUR_KEY_ID_HERE'
|
33
|
+
# export MSS_SECRET_ACCESS_KEY='YOUR_SECRET_KEY_HERE'
|
34
|
+
#
|
35
|
+
# For compatability with other MSS gems, the credentials can also be
|
36
|
+
# exported like:
|
37
|
+
#
|
38
|
+
# export AMAZON_ACCESS_KEY_ID='YOUR_KEY_ID_HERE'
|
39
|
+
# export AMAZON_SECRET_ACCESS_KEY='YOUR_SECRET_KEY_HERE'
|
40
|
+
#
|
41
|
+
# ## Modifying a Configuration
|
42
|
+
#
|
43
|
+
# Configuration objects are read-only. If you need a different set of
|
44
|
+
# configuration values, call {#with}, passing in the updates
|
45
|
+
# and a new configuration object will be returned.
|
46
|
+
#
|
47
|
+
# config = Configuration.new(:max_retries => 3)
|
48
|
+
# new_config = config.with(:max_retries => 2)
|
49
|
+
#
|
50
|
+
# config.max_retries #=> 3
|
51
|
+
# new_config.max_retries #=> 2
|
52
|
+
#
|
53
|
+
# ## Global Configuration
|
54
|
+
#
|
55
|
+
# The global default configuration can be found at {MSS.config}
|
56
|
+
#
|
57
|
+
# @attr_reader [String,nil] access_key_id (nil)
|
58
|
+
# MSS access key id credential.
|
59
|
+
#
|
60
|
+
# @attr_reader [String,nil] secret_access_key (nil)
|
61
|
+
# MSS secret access key credential.
|
62
|
+
#
|
63
|
+
# @attr_reader [String,nil] session_token (nil) MSS secret token credential.
|
64
|
+
#
|
65
|
+
# @attr_reader [String] region
|
66
|
+
# The MSS region used for requests. The default is `us-east-1`.
|
67
|
+
#
|
68
|
+
# @attr_reader [Boolean] dynamo_db_big_decimals (true) When `true`,
|
69
|
+
# {DynamoDB} will convert number values returned by {DynamoDB::Client}
|
70
|
+
# from strings to BigDecimal objects. If you set this to `false`,
|
71
|
+
# they will be converted from strings into floats (with a potential
|
72
|
+
# loss of precision).
|
73
|
+
#
|
74
|
+
# @attr_reader [Boolean] dynamo_db_retry_throughput_errors (true) When
|
75
|
+
# true, MSS::DynamoDB::Errors::ProvisionedThroughputExceededException
|
76
|
+
# errors will be retried.
|
77
|
+
#
|
78
|
+
# @attr_reader [Object] http_handler The http handler that sends requests
|
79
|
+
# to MSS. Defaults to an HTTP handler built on net/http.
|
80
|
+
#
|
81
|
+
# @attr_reader [Integer] http_idle_timeout The number of seconds a
|
82
|
+
# persistent connection is allowed to sit idle before it should no
|
83
|
+
# longer be used.
|
84
|
+
#
|
85
|
+
# @attr_reader [Integer] http_open_timeout The number of seconds before
|
86
|
+
# the `http_handler` should timeout while trying to open a new HTTP
|
87
|
+
# session.
|
88
|
+
#
|
89
|
+
# @attr_reader [Integer] http_read_timeout The number of seconds before
|
90
|
+
# the `http_handler` should timeout while waiting for a HTTP
|
91
|
+
# response.
|
92
|
+
#
|
93
|
+
# @attr_reader [Boolean] http_wire_trace When `true`, the http handler
|
94
|
+
# will log all wire traces to the `:logger`. If a `:logger` is not
|
95
|
+
# configured, then wire traces will be sent to standard out.
|
96
|
+
#
|
97
|
+
# @attr_reader [Logger,nil] logger (nil) The logging interface.
|
98
|
+
#
|
99
|
+
# @attr_reader [Symbol] log_level (:info) The log level to use when
|
100
|
+
# logging every API call. Does not set the `:logger`'s log_level.
|
101
|
+
#
|
102
|
+
# @attr_reader [LogFormatter] log_formatter The log message formatter.
|
103
|
+
#
|
104
|
+
# @attr_reader [Integer] max_retries (3) The maximum number of times
|
105
|
+
# service errors (500) and throttling errors should be retried. There is
|
106
|
+
# an exponential backoff in between retries, so the more retries the
|
107
|
+
# longer it can take to fail.
|
108
|
+
#
|
109
|
+
# @attr_reader [URI,nil] proxy_uri (nil) The URI of the proxy
|
110
|
+
# to send service requests through.
|
111
|
+
#
|
112
|
+
# @attr_reader [Boolean] s3_force_path_style (false) When
|
113
|
+
# `true`, requests will always use path style. This can be useful
|
114
|
+
# for testing environments.
|
115
|
+
#
|
116
|
+
# @attr_reader [Integer] s3_multipart_max_parts (10000)
|
117
|
+
# The maximum number of parts to split a file into when uploading
|
118
|
+
# in parts to S3.
|
119
|
+
#
|
120
|
+
# @attr_reader [Integer] s3_multipart_threshold (16777216) When uploading
|
121
|
+
# data to S3, if the number of bytes to send exceeds
|
122
|
+
# `:s3_multipart_threshold` then a multi part session is automatically
|
123
|
+
# started and the data is sent up in chunks. The size of each part
|
124
|
+
# is specified by `:s3_multipart_min_part_size`. Defaults to
|
125
|
+
# 16777216 (16MB).
|
126
|
+
#
|
127
|
+
# @attr_reader [Integer] s3_multipart_min_part_size (5242880)
|
128
|
+
# The absolute minimum size (in bytes) each S3 multipart
|
129
|
+
# segment should be defaults to 5242880 (5MB).
|
130
|
+
#
|
131
|
+
# @attr_reader [Symbol] s3_server_side_encryption The algorithm to
|
132
|
+
# use when encrypting object data on the server side. The only
|
133
|
+
# valid value is `:aes256`, which specifies that the object
|
134
|
+
# should be stored using the AES encryption algorithm with 256
|
135
|
+
# bit keys. Defaults to `nil`, meaning server side encryption
|
136
|
+
# is not used unless specified on each individual call to upload
|
137
|
+
# an object. This option controls the default behavior for the
|
138
|
+
# following method:
|
139
|
+
#
|
140
|
+
# * {S3::S3Object#write}
|
141
|
+
# * {S3::S3Object#multipart_upload}
|
142
|
+
# * {S3::S3Object#copy_from} and {S3::S3Object#copy_to}
|
143
|
+
# * {S3::S3Object#presigned_post}
|
144
|
+
# * {S3::Bucket#presigned_post}
|
145
|
+
#
|
146
|
+
# You can construct an interface to Amazon S3 which always
|
147
|
+
# stores data using server side encryption as follows:
|
148
|
+
#
|
149
|
+
# s3 = MSS::S3.new(:s3_server_side_encryption => :aes256)
|
150
|
+
#
|
151
|
+
# @attr_reader [OpenSSL::PKey::RSA, String] s3_encryption_key
|
152
|
+
# If this is set, MSS::S3::S3Object #read and #write methods will always
|
153
|
+
# perform client-side encryption with this key. The key can be overridden
|
154
|
+
# at runtime by using the :encryption_key option. A value of nil
|
155
|
+
# means that client-side encryption will not be used.
|
156
|
+
#
|
157
|
+
# @attr_reader [Symbol] s3_encryption_materials_location
|
158
|
+
# When set to `:instruction_file`, MSS::S3::S3Object will store
|
159
|
+
# encryption materials in a separate object, instead of the object
|
160
|
+
# metadata.
|
161
|
+
#
|
162
|
+
# @attr_reader [Boolean] simple_db_consistent_reads (false) Determines
|
163
|
+
# if all SimpleDB read requests should be done consistently.
|
164
|
+
# Consistent reads are slower, but reflect all changes to SDB.
|
165
|
+
#
|
166
|
+
# @attr_reader [Boolean] sqs_verify_checksums (true)
|
167
|
+
# When `true` all SQS operations will check body content against
|
168
|
+
# MD5 checksums, raising an exception if there is a mismatch.
|
169
|
+
#
|
170
|
+
# @attr_reader [CredentialProvider::Provider] credential_provider
|
171
|
+
# Returns the object that is responsible for loading credentials.
|
172
|
+
#
|
173
|
+
# @attr_reader [String] ssl_ca_file The path to a CA cert bundle in
|
174
|
+
# PEM format.
|
175
|
+
#
|
176
|
+
# If `ssl_verify_peer` is true (the default) this bundle will be
|
177
|
+
# used to validate the server certificate in each HTTPS request.
|
178
|
+
# The MSS SDK for Ruby ships with a CA cert bundle, which is the
|
179
|
+
# default value for this option.
|
180
|
+
#
|
181
|
+
# @attr_reader [String] ssl_ca_path (nil)
|
182
|
+
# The path the a CA cert directory.
|
183
|
+
#
|
184
|
+
# @attr_reader [String] ssl_cert_store (nil)
|
185
|
+
#
|
186
|
+
# @attr_reader [Boolean] ssl_verify_peer (true) When `true`
|
187
|
+
# the HTTP handler validate server certificates for HTTPS requests.
|
188
|
+
#
|
189
|
+
# This option should only be disabled for diagnostic purposes;
|
190
|
+
# leaving this option set to `false` exposes your application to
|
191
|
+
# man-in-the-middle attacks and can pose a serious security
|
192
|
+
# risk.
|
193
|
+
#
|
194
|
+
# @attr_reader [Boolean] stub_requests (false) When `true` requests are not
|
195
|
+
# sent to MSS, instead empty responses are generated and returned to
|
196
|
+
# each service request.
|
197
|
+
#
|
198
|
+
# @attr_reader [Boolean] use_ssl (true) When `true`, all requests
|
199
|
+
# to MSS are sent using HTTPS instead vanilla HTTP.
|
200
|
+
#
|
201
|
+
# @attr_reader [String] user_agent_prefix (nil) A string prefix to
|
202
|
+
# append to all requests against MSS services. This should be set
|
203
|
+
# for clients and applications built on top of the mss-sdk gem.
|
204
|
+
#
|
205
|
+
# @attr_reader [Boolean] verify_response_body_content_length (true)
|
206
|
+
# When `true` all HTTP handlers will perform a check to ensure
|
207
|
+
# that response bodies match the content-length specified in the
|
208
|
+
# response header, if present. Note that some HTTP handlers will
|
209
|
+
# always do this whether or not this value is true.
|
210
|
+
#
|
211
|
+
class Configuration
|
212
|
+
|
213
|
+
# Creates a new Configuration object.
|
214
|
+
# @param options (see MSS.config)
|
215
|
+
# @option options (see MSS.config)
|
216
|
+
def initialize options = {}
|
217
|
+
|
218
|
+
@created = options.delete(:__created__) || {}
|
219
|
+
|
220
|
+
# :signer is now a deprecated option, this ensures it will still
|
221
|
+
# work, but its now preferred to set :credential_provider instead.
|
222
|
+
# Credential providers don't have to provide a #sign method.
|
223
|
+
if signer = options.delete(:signer)
|
224
|
+
options[:credential_provider] = signer
|
225
|
+
end
|
226
|
+
|
227
|
+
options.each_pair do |opt_name, value|
|
228
|
+
opt_name = opt_name.to_sym
|
229
|
+
if self.class.accepted_options.include?(opt_name)
|
230
|
+
#if opt_name.to_s =~ /_endpoint$/
|
231
|
+
# warning = ":#{opt_name} is a deprecated MSS configuration option, "
|
232
|
+
# warning << "use :region instead"
|
233
|
+
# warn(warning)
|
234
|
+
#end
|
235
|
+
supplied[opt_name] = value
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
# @return [Hash] Returns a hash with your configured credentials.
|
242
|
+
def credentials
|
243
|
+
credentials = {}
|
244
|
+
[:access_key_id, :secret_access_key, :session_token].each do |opt|
|
245
|
+
if value = credential_provider.send(opt)
|
246
|
+
credentials[opt] = value
|
247
|
+
end
|
248
|
+
end
|
249
|
+
credentials
|
250
|
+
end
|
251
|
+
|
252
|
+
# Used to create a new Configuration object with the given modifications.
|
253
|
+
# The current configuration object is not modified.
|
254
|
+
#
|
255
|
+
# MSS.config(:max_retries => 2)
|
256
|
+
#
|
257
|
+
# no_retries_config = MSS.config.with(:max_retries => 0)
|
258
|
+
#
|
259
|
+
# MSS.config.max_retries #=> 2
|
260
|
+
# no_retries_config.max_retries #=> 0
|
261
|
+
#
|
262
|
+
# You can use these configuration objects returned by #with to create
|
263
|
+
# MSS objects:
|
264
|
+
#
|
265
|
+
# MSS::S3.new(:config => no_retries_config)
|
266
|
+
# MSS::SQS.new(:config => no_retries_config)
|
267
|
+
#
|
268
|
+
# @param options (see MSS.config)
|
269
|
+
# @option options (see MSS.config)
|
270
|
+
# @return [Configuration] Copies the current configuration and returns
|
271
|
+
# a new one with modifications as provided in `:options`.
|
272
|
+
def with options = {}
|
273
|
+
|
274
|
+
# symbolize option keys
|
275
|
+
options = options.inject({}) {|h,kv| h[kv.first.to_sym] = kv.last; h }
|
276
|
+
|
277
|
+
values = supplied.merge(options)
|
278
|
+
|
279
|
+
if supplied == values
|
280
|
+
self # nothing changed
|
281
|
+
else
|
282
|
+
self.class.new(values.merge(:__created__ => @created.dup))
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
# @return [Hash] Returns a hash of all configuration values.
|
288
|
+
def to_h
|
289
|
+
self.class.accepted_options.inject({}) do |h,k|
|
290
|
+
h.merge(k => send(k))
|
291
|
+
end
|
292
|
+
end
|
293
|
+
alias_method :to_hash, :to_h
|
294
|
+
|
295
|
+
# @return [Boolean] Returns true if the two configuration objects have
|
296
|
+
# the same values.
|
297
|
+
def eql? other
|
298
|
+
other.is_a?(self.class) and self.supplied == other.supplied
|
299
|
+
end
|
300
|
+
alias_method :==, :eql?
|
301
|
+
|
302
|
+
# @api private
|
303
|
+
def inspect
|
304
|
+
"<#{self.class.name}>"
|
305
|
+
end
|
306
|
+
|
307
|
+
# @api private
|
308
|
+
def endpoint_region(svc)
|
309
|
+
(supplied[svc.method_name] || {})[:region] or
|
310
|
+
supplied[:"#{svc.old_name}_region"] or
|
311
|
+
region
|
312
|
+
end
|
313
|
+
|
314
|
+
protected
|
315
|
+
|
316
|
+
def supplied
|
317
|
+
@supplied ||= {}
|
318
|
+
end
|
319
|
+
|
320
|
+
class << self
|
321
|
+
|
322
|
+
# @api private
|
323
|
+
def accepted_options
|
324
|
+
@options ||= Set.new
|
325
|
+
end
|
326
|
+
|
327
|
+
# @api private
|
328
|
+
def add_option name, default_value = nil, options = {}, &transform
|
329
|
+
|
330
|
+
accepted_options << name
|
331
|
+
|
332
|
+
define_method(name) do |&default_override|
|
333
|
+
|
334
|
+
value =
|
335
|
+
if supplied.has_key?(name)
|
336
|
+
supplied[name]
|
337
|
+
elsif default_override
|
338
|
+
default_override.call
|
339
|
+
else
|
340
|
+
default_value
|
341
|
+
end
|
342
|
+
|
343
|
+
transform ? transform.call(self, value) : value
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
alias_method("#{name}?", name) if options[:boolean]
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
# Configuration options that have dependencies are re-recreated
|
352
|
+
# anytime one of their dependent configuration values are
|
353
|
+
# changed.
|
354
|
+
# @api private
|
355
|
+
def add_option_with_needs name, needs, &create_block
|
356
|
+
|
357
|
+
accepted_options << name
|
358
|
+
|
359
|
+
define_method(name) do
|
360
|
+
|
361
|
+
return supplied[name] if supplied.has_key?(name)
|
362
|
+
|
363
|
+
needed = needs.inject({}) {|h,need| h.merge(need => send(need)) }
|
364
|
+
|
365
|
+
unless @created.key?(name) and @created[name][:needed] == needed
|
366
|
+
created = {}
|
367
|
+
created[:object] = create_block.call(self,needed)
|
368
|
+
created[:needed] = needed
|
369
|
+
@created[name] = created
|
370
|
+
end
|
371
|
+
|
372
|
+
@created[name][:object]
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
end
|
377
|
+
|
378
|
+
def add_service name, ruby_name, endpoint_prefix
|
379
|
+
|
380
|
+
svc = SERVICES[name]
|
381
|
+
svc_opt = svc.method_name
|
382
|
+
ruby_name = svc.old_name
|
383
|
+
|
384
|
+
add_option(svc_opt, {})
|
385
|
+
|
386
|
+
add_option :"#{ruby_name}_endpoint" do |config,value|
|
387
|
+
region = config.endpoint_region(svc)
|
388
|
+
endpoint = value
|
389
|
+
endpoint ||= config.send(svc_opt)[:endpoint]
|
390
|
+
endpoint ||= Endpoints.hostname(region, endpoint_prefix)
|
391
|
+
endpoint ||= "#{endpoint_prefix}.#{region}.amazonmss.com"
|
392
|
+
endpoint
|
393
|
+
end
|
394
|
+
|
395
|
+
add_option(:"#{ruby_name}_port") do |config,value|
|
396
|
+
if value
|
397
|
+
value
|
398
|
+
elsif port = config.send(svc_opt)[:port]
|
399
|
+
port
|
400
|
+
else
|
401
|
+
config.use_ssl? ? 443 : 80
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
# users only need to specify service regions when they use
|
406
|
+
# a test endpoint with a sigv4 service
|
407
|
+
add_option(:"#{ruby_name}_region") do |config,value|
|
408
|
+
if value
|
409
|
+
value
|
410
|
+
elsif region = config.send(svc_opt)[:region]
|
411
|
+
region
|
412
|
+
else
|
413
|
+
endpoint = config.send("#{ruby_name}_endpoint")
|
414
|
+
if endpoint =~ /us-gov/
|
415
|
+
if matches = endpoint.match(/(us-gov-west-\d+)/)
|
416
|
+
matches[1]
|
417
|
+
else
|
418
|
+
'us-gov-west-1' # e.g. iam.us-gov.amazonmss.com
|
419
|
+
end
|
420
|
+
elsif matches = endpoint.match(/^.+?[.-](.+)\.amazonmss.com/)
|
421
|
+
matches[1]
|
422
|
+
else
|
423
|
+
MSS.const_get(name).global_endpoint? ? 'us-east-1' : config.region
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
needs = [
|
429
|
+
:"#{svc_opt}",
|
430
|
+
:"#{ruby_name}_endpoint",
|
431
|
+
:"#{ruby_name}_port",
|
432
|
+
:"#{ruby_name}_region",
|
433
|
+
:credential_provider,
|
434
|
+
:http_handler,
|
435
|
+
:http_read_timeout,
|
436
|
+
:http_continue_timeout,
|
437
|
+
:http_continue_threshold,
|
438
|
+
:log_formatter,
|
439
|
+
:log_level,
|
440
|
+
:logger,
|
441
|
+
:proxy_uri,
|
442
|
+
:max_retries,
|
443
|
+
:stub_requests?,
|
444
|
+
:ssl_verify_peer?,
|
445
|
+
:ssl_ca_file,
|
446
|
+
:ssl_ca_path,
|
447
|
+
:ssl_cert_store,
|
448
|
+
:use_ssl?,
|
449
|
+
:user_agent_prefix,
|
450
|
+
]
|
451
|
+
|
452
|
+
create_block = lambda do |config,client_options|
|
453
|
+
options = client_options[:"#{svc_opt}"]
|
454
|
+
MSS.const_get(name)::Client.new(options.merge(:config => config))
|
455
|
+
end
|
456
|
+
|
457
|
+
add_option_with_needs :"#{ruby_name}_client", needs, &create_block
|
458
|
+
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
462
|
+
|
463
|
+
add_option :access_key_id
|
464
|
+
|
465
|
+
add_option :secret_access_key
|
466
|
+
|
467
|
+
add_option :session_token
|
468
|
+
|
469
|
+
add_option :region do |cfg,region|
|
470
|
+
region || ENV['MSS_REGION'] || ENV['AMAZON_REGION'] || ENV['MSS_DEFAULT_REGION'] || 'us-east-1'
|
471
|
+
end
|
472
|
+
|
473
|
+
add_option_with_needs :credential_provider,
|
474
|
+
[:access_key_id, :secret_access_key, :session_token] do |cfg,static_creds|
|
475
|
+
|
476
|
+
CredentialProviders::DefaultProvider.new(static_creds)
|
477
|
+
|
478
|
+
end
|
479
|
+
|
480
|
+
add_option :http_open_timeout, 15
|
481
|
+
|
482
|
+
add_option :http_read_timeout, 60
|
483
|
+
|
484
|
+
add_option :http_continue_timeout, 1
|
485
|
+
|
486
|
+
add_option :http_continue_threshold, false
|
487
|
+
|
488
|
+
add_option :http_idle_timeout, 5
|
489
|
+
|
490
|
+
add_option :http_wire_trace, false, :boolean => true
|
491
|
+
|
492
|
+
add_option_with_needs(:http_handler,
|
493
|
+
MSS::Core::Http::ConnectionPool::OPTIONS + [:verify_response_body_content_length]
|
494
|
+
) do |config,options|
|
495
|
+
MSS::Core::Http::NetHttpHandler.new(options)
|
496
|
+
end
|
497
|
+
|
498
|
+
add_option :logger
|
499
|
+
|
500
|
+
add_option :log_level, :info
|
501
|
+
|
502
|
+
add_option :log_formatter, LogFormatter.default
|
503
|
+
|
504
|
+
add_option :max_retries, 3
|
505
|
+
|
506
|
+
add_option :proxy_uri do |config,uri| uri ? URI.parse(uri.to_s) : nil end
|
507
|
+
|
508
|
+
add_option :ssl_verify_peer, true, :boolean => true
|
509
|
+
|
510
|
+
add_option :ssl_ca_file,
|
511
|
+
File.expand_path(File.dirname(__FILE__) + "/../../../ca-bundle.crt")
|
512
|
+
|
513
|
+
add_option :ssl_ca_path
|
514
|
+
|
515
|
+
add_option :ssl_cert_store
|
516
|
+
|
517
|
+
add_option :stub_requests, false, :boolean => true
|
518
|
+
|
519
|
+
add_option :use_ssl, true, :boolean => true
|
520
|
+
|
521
|
+
add_option :user_agent_prefix
|
522
|
+
|
523
|
+
add_option :verify_response_body_content_length, true, :boolean => true
|
524
|
+
|
525
|
+
end
|
526
|
+
end
|
527
|
+
end
|