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,426 @@
|
|
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 'pathname'
|
14
|
+
|
15
|
+
module MSS
|
16
|
+
module Core
|
17
|
+
|
18
|
+
# # Log Formatters
|
19
|
+
#
|
20
|
+
# Log formatters receive a {MSS::Core::Response} object and return
|
21
|
+
# a log message. When you construct a {LogFormatter}, you provide
|
22
|
+
# a pattern string with substitutions.
|
23
|
+
#
|
24
|
+
# pattern = '[MSS :http_response_status] :service :operation :duration'
|
25
|
+
# formatter = MSS::Core::LogFormatter.new(pattern)
|
26
|
+
# formatter.format(response)
|
27
|
+
# #=> '[MSS 200] EC2 get_bucket 0.0352'
|
28
|
+
#
|
29
|
+
# # MSS Configuration
|
30
|
+
#
|
31
|
+
# MSS.config provides a {LogFormatter.default} log formatter. You can
|
32
|
+
# repace this formatter by building your own and then passing it
|
33
|
+
# to {MSS.config}.
|
34
|
+
#
|
35
|
+
# pattern = '[MSS :http_response_status] :service :operation :duration'
|
36
|
+
# MSS.config(:log_formatter => MSS::Core::LogFormatter.new(pattern)
|
37
|
+
#
|
38
|
+
# ## Canned Formatters
|
39
|
+
#
|
40
|
+
# Instead of providing your own pattern, you can choose a canned log
|
41
|
+
# formatter.
|
42
|
+
#
|
43
|
+
# MSS.config(:log_formatter => MSS::Core::LogFormatter.colored)
|
44
|
+
#
|
45
|
+
# Here is the list of canned formatters.
|
46
|
+
#
|
47
|
+
# * {LogFormatter.default}
|
48
|
+
# * {LogFormatter.short}
|
49
|
+
# * {LogFormatter.debug}
|
50
|
+
# * {LogFormatter.colored}
|
51
|
+
#
|
52
|
+
# # Pattern Substitutions
|
53
|
+
#
|
54
|
+
# You can put any of these placeholders into you pattern.
|
55
|
+
#
|
56
|
+
# * `:service` - The MSS service name (e.g. 'S3', 'EC2', 'SimpleDB', etc)
|
57
|
+
# * `:region` - The MSS region name (e.g. 'us-west-1', 'us-west-2', etc)
|
58
|
+
# * `:operation` - The name of the client request method. This maps to
|
59
|
+
# the name of the serivce API operation (e.g. :describe_instances).
|
60
|
+
# * `:options` - The hash of options passed to the client request method.
|
61
|
+
# Long strings are truncated/summarized if they excede the log
|
62
|
+
# formatters {#max_string_size}. Other objects are inspected.
|
63
|
+
# * `:retry_count` - The number of times a client request was retried.
|
64
|
+
# Throttlings and service errors trigger the automatic retry logic.
|
65
|
+
# This value indicates how many extra attempts were made before
|
66
|
+
# getting a successful response or giving up.
|
67
|
+
# * `:duration` - The time it took to generate a response, expressed
|
68
|
+
# in decimal seconds. This time includes everything from
|
69
|
+
# calling the client request method, until that method returns
|
70
|
+
# a value (event retries and retry delays).
|
71
|
+
# * `:error_class` - The class name of the error returned by the
|
72
|
+
# service. If no error was returned, this will be replcaed by
|
73
|
+
# an empty string.
|
74
|
+
# * `:error_message` - The message of the error returned. If
|
75
|
+
# no error was returned by the service, this will be an empty
|
76
|
+
# string.
|
77
|
+
# * `:http_request_method` - The HTTP request verb (e.g. 'POST',
|
78
|
+
# 'PUT', 'GET', etc).
|
79
|
+
# * `:http_request_protocol` - This is replaced by 'http' or 'https'.
|
80
|
+
# * `:http_request_host` - The host name of the http request
|
81
|
+
# * `:http_request_port` - The port number (e.g. '443' or '80').
|
82
|
+
# * `:http_request_uri` - The http request uri folling the host (e.g.
|
83
|
+
# '/bucket_name/objects/key?versions').
|
84
|
+
# * `:http_request_body` - The http request payload.
|
85
|
+
# * `:http_request_headers` - The http request headers, inspected.
|
86
|
+
# * `:http_request_proxy_uri` - The proxy uri used, or an empty string.
|
87
|
+
# * `:http_response_status` - The http response status
|
88
|
+
# code (e.g. '200', '404', '500', etc).
|
89
|
+
# * `:http_response_headers` - The http response headers, inspected.
|
90
|
+
# * `:http_response_body` - The http response body contents.
|
91
|
+
#
|
92
|
+
class LogFormatter
|
93
|
+
|
94
|
+
# @param [String] pattern The log format pattern should be a string
|
95
|
+
# and may contain any of the following placeholders:
|
96
|
+
#
|
97
|
+
# * `:service`
|
98
|
+
# * `:region`
|
99
|
+
# * `:operation`
|
100
|
+
# * `:options`
|
101
|
+
# * `:retry_count`
|
102
|
+
# * `:duration`
|
103
|
+
# * `:error_class`
|
104
|
+
# * `:error_message`
|
105
|
+
# * `:http_request_method`
|
106
|
+
# * `:http_request_protocol`
|
107
|
+
# * `:http_request_host`
|
108
|
+
# * `:http_request_port`
|
109
|
+
# * `:http_request_uri`
|
110
|
+
# * `:http_request_body`
|
111
|
+
# * `:http_request_headers`
|
112
|
+
# * `:http_request_proxy_uri`
|
113
|
+
# * `:http_response_status`
|
114
|
+
# * `:http_response_headers`
|
115
|
+
# * `:http_response_body`
|
116
|
+
#
|
117
|
+
# @param [Hash] options
|
118
|
+
#
|
119
|
+
# @option options [Integer] :max_string_size (1000)
|
120
|
+
#
|
121
|
+
def initialize pattern, options = {}
|
122
|
+
@pattern = pattern
|
123
|
+
@max_string_size = options[:max_string_size] || 1000
|
124
|
+
end
|
125
|
+
|
126
|
+
# @return [String]
|
127
|
+
attr_reader :pattern
|
128
|
+
|
129
|
+
# @return [Integer]
|
130
|
+
attr_reader :max_string_size
|
131
|
+
|
132
|
+
# @param [Response] response
|
133
|
+
# @return [String]
|
134
|
+
def format response
|
135
|
+
pattern.gsub(/:(\w+)/) {|sym| send("_#{sym[1..-1]}", response) }
|
136
|
+
end
|
137
|
+
|
138
|
+
# @api private
|
139
|
+
def eql? other
|
140
|
+
other.is_a?(self.class) and other.pattern == self.pattern
|
141
|
+
end
|
142
|
+
alias_method :==, :eql?
|
143
|
+
|
144
|
+
protected
|
145
|
+
|
146
|
+
def method_missing method_name, *args
|
147
|
+
if method_name.to_s.chars.first == '_'
|
148
|
+
":#{method_name.to_s[1..-1]}"
|
149
|
+
else
|
150
|
+
super
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def _service response
|
155
|
+
response.http_request.service
|
156
|
+
end
|
157
|
+
|
158
|
+
def _region response
|
159
|
+
response.http_request.region
|
160
|
+
end
|
161
|
+
|
162
|
+
def _operation response
|
163
|
+
response.request_type
|
164
|
+
end
|
165
|
+
|
166
|
+
def _options response
|
167
|
+
summarize_hash(response.request_options) if response.request_options
|
168
|
+
end
|
169
|
+
|
170
|
+
def _retry_count response
|
171
|
+
response.retry_count
|
172
|
+
end
|
173
|
+
|
174
|
+
def _duration response
|
175
|
+
("%.06f" % response.duration).sub(/0+$/, '')
|
176
|
+
end
|
177
|
+
|
178
|
+
def _error_class response
|
179
|
+
response.error.class.name if response.error
|
180
|
+
end
|
181
|
+
|
182
|
+
def _error_message response
|
183
|
+
response.error.message if response.error
|
184
|
+
end
|
185
|
+
|
186
|
+
def _http_request_method response
|
187
|
+
response.http_request.http_method
|
188
|
+
end
|
189
|
+
|
190
|
+
def _http_request_protocol response
|
191
|
+
response.http_request.use_ssl? ? 'https' : 'http'
|
192
|
+
end
|
193
|
+
|
194
|
+
def _http_request_host response
|
195
|
+
response.http_request.host
|
196
|
+
end
|
197
|
+
|
198
|
+
def _http_request_port response
|
199
|
+
response.http_request.port
|
200
|
+
end
|
201
|
+
|
202
|
+
def _http_request_uri response
|
203
|
+
response.http_request.uri
|
204
|
+
end
|
205
|
+
|
206
|
+
def _http_request_headers response
|
207
|
+
response.http_request.headers.inspect
|
208
|
+
end
|
209
|
+
|
210
|
+
def _http_request_body response
|
211
|
+
response.http_request.body
|
212
|
+
end
|
213
|
+
|
214
|
+
def _http_request_proxy_uri response
|
215
|
+
response.config.proxy_uri
|
216
|
+
end
|
217
|
+
|
218
|
+
def _http_response_status response
|
219
|
+
response.http_response.status
|
220
|
+
end
|
221
|
+
|
222
|
+
def _http_response_headers response
|
223
|
+
response.http_response.headers.inspect
|
224
|
+
end
|
225
|
+
|
226
|
+
def _http_response_body response
|
227
|
+
response.http_response.body
|
228
|
+
end
|
229
|
+
|
230
|
+
# The following methods are for summarizing request options that have
|
231
|
+
# symbolized keys and a mix of values. The summarizing is important
|
232
|
+
# because large request options (e.g. s3 data) can cause memory usage
|
233
|
+
# to spike if it is inspected.
|
234
|
+
|
235
|
+
# @param [Hash] hash
|
236
|
+
# @return [String]
|
237
|
+
def summarize_hash hash
|
238
|
+
hash.map do |key,v|
|
239
|
+
"#{key.inspect}=>#{summarize_value(v)}"
|
240
|
+
end.sort.join(",")
|
241
|
+
end
|
242
|
+
|
243
|
+
# @param [Object] value
|
244
|
+
# @return [String]
|
245
|
+
def summarize_value value
|
246
|
+
case value
|
247
|
+
when String then summarize_string(value)
|
248
|
+
when Hash then '{' + summarize_hash(value) + '}'
|
249
|
+
when Array then summarize_array(value)
|
250
|
+
when File then summarize_file(value.path)
|
251
|
+
when Pathname then summarize_file(value)
|
252
|
+
else value.inspect
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
# @param [String] str
|
257
|
+
# @return [String]
|
258
|
+
def summarize_string str
|
259
|
+
max = max_string_size
|
260
|
+
if str.size > max
|
261
|
+
"#<String #{str[0...max].inspect} ... (#{str.size} bytes)>"
|
262
|
+
else
|
263
|
+
str.inspect
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
# Given the path to a file on disk, this method returns a summarized
|
268
|
+
# inspecton string that includes the file size.
|
269
|
+
# @param [String] path
|
270
|
+
# @return [String]
|
271
|
+
def summarize_file path
|
272
|
+
"#<File:#{path} (#{File.size(path)} bytes)>"
|
273
|
+
end
|
274
|
+
|
275
|
+
# @param [Array] array
|
276
|
+
# @return [String]
|
277
|
+
def summarize_array array
|
278
|
+
"[" + array.map{|v| summarize_value(v) }.join(",") + "]"
|
279
|
+
end
|
280
|
+
|
281
|
+
class << self
|
282
|
+
|
283
|
+
# The default log format.
|
284
|
+
#
|
285
|
+
# @example A sample of the default format.
|
286
|
+
#
|
287
|
+
# [MSS SimpleEmailService 200 0.580066 0 retries] list_verified_email_addresses()
|
288
|
+
#
|
289
|
+
# @return [LogFormatter]
|
290
|
+
#
|
291
|
+
def default
|
292
|
+
|
293
|
+
pattern = []
|
294
|
+
pattern << "[MSS"
|
295
|
+
pattern << ":service"
|
296
|
+
pattern << ":http_response_status"
|
297
|
+
pattern << ":duration"
|
298
|
+
pattern << ":retry_count retries]"
|
299
|
+
pattern << ":operation(:options)"
|
300
|
+
pattern << ":error_class"
|
301
|
+
pattern << ":error_message"
|
302
|
+
|
303
|
+
LogFormatter.new(pattern.join(' ') + "\n")
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
# The short log format. Similar to default, but it does not
|
308
|
+
# inspect the request params or report on retries.
|
309
|
+
#
|
310
|
+
# @example A sample of the short format
|
311
|
+
#
|
312
|
+
# [MSS SimpleEmailService 200 0.494532] list_verified_email_addresses
|
313
|
+
#
|
314
|
+
# @return [LogFormatter]
|
315
|
+
#
|
316
|
+
def short
|
317
|
+
|
318
|
+
pattern = []
|
319
|
+
pattern << "[MSS"
|
320
|
+
pattern << ":service"
|
321
|
+
pattern << ":http_response_status"
|
322
|
+
pattern << ":duration]"
|
323
|
+
pattern << ":operation"
|
324
|
+
pattern << ":error_class"
|
325
|
+
|
326
|
+
LogFormatter.new(pattern.join(' ') + "\n")
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
# A debug format that dumps most of the http request and response
|
331
|
+
# data.
|
332
|
+
#
|
333
|
+
# @example A truncated sample of the debug format.
|
334
|
+
#
|
335
|
+
# +-------------------------------------------------------------------------------
|
336
|
+
# | MSS us-east-1 SimpleEmailService list_verified_email_addresses 0.429189 0 retries
|
337
|
+
# +-------------------------------------------------------------------------------
|
338
|
+
# | REQUEST
|
339
|
+
# +-------------------------------------------------------------------------------
|
340
|
+
# | METHOD: POST
|
341
|
+
# | URL: https://email.us-east-1.amazonmss.com::443:/
|
342
|
+
# | HEADERS: {"content-type"=>"application/x-www-form-urlencoded" ...
|
343
|
+
# | BODY: Action=ListVerifiedEmailAddresses&Timestamp= ...
|
344
|
+
# +-------------------------------------------------------------------------------
|
345
|
+
# | RESPONSE
|
346
|
+
# +-------------------------------------------------------------------------------
|
347
|
+
# | STATUS: 200
|
348
|
+
# | HEADERS: {"x-amzn-requestid"=>["..."], ...
|
349
|
+
# | BODY: <ListVerifiedEmailAddressesResponse ...
|
350
|
+
#
|
351
|
+
# @return [LogFormatter]
|
352
|
+
#
|
353
|
+
def debug
|
354
|
+
|
355
|
+
sig_pattern = []
|
356
|
+
sig_pattern << ':region'
|
357
|
+
sig_pattern << ':service'
|
358
|
+
sig_pattern << ':operation'
|
359
|
+
sig_pattern << ':duration'
|
360
|
+
sig_pattern << ':retry_count retries'
|
361
|
+
|
362
|
+
uri_pattern = []
|
363
|
+
uri_pattern << ':http_request_protocol'
|
364
|
+
uri_pattern << '://'
|
365
|
+
uri_pattern << ':http_request_host'
|
366
|
+
uri_pattern << '::'
|
367
|
+
uri_pattern << ':http_request_port'
|
368
|
+
uri_pattern << ':'
|
369
|
+
uri_pattern << ':http_request_uri'
|
370
|
+
|
371
|
+
line = "+" + '-' * 79
|
372
|
+
|
373
|
+
pattern = []
|
374
|
+
pattern << line
|
375
|
+
pattern << "| MSS #{sig_pattern.join(' ')}"
|
376
|
+
pattern << line
|
377
|
+
pattern << "| REQUEST"
|
378
|
+
pattern << line
|
379
|
+
pattern << "| METHOD: :http_request_method"
|
380
|
+
pattern << "| URL: #{uri_pattern.join}"
|
381
|
+
pattern << "| HEADERS: :http_request_headers"
|
382
|
+
pattern << "| BODY: :http_request_body"
|
383
|
+
pattern << line
|
384
|
+
pattern << "| RESPONSE"
|
385
|
+
pattern << line
|
386
|
+
pattern << "| STATUS: :http_response_status"
|
387
|
+
pattern << "| HEADERS: :http_response_headers"
|
388
|
+
pattern << "| BODY: :http_response_body"
|
389
|
+
|
390
|
+
LogFormatter.new(pattern.join("\n") + "\n")
|
391
|
+
|
392
|
+
end
|
393
|
+
|
394
|
+
# The default log format with ANSI colors.
|
395
|
+
#
|
396
|
+
# @example A sample of the colored format (sans the ansi colors).
|
397
|
+
#
|
398
|
+
# [MSS SimpleEmailService 200 0.580066 0 retries] list_verified_email_addresses()
|
399
|
+
#
|
400
|
+
# @return [LogFormatter]
|
401
|
+
#
|
402
|
+
def colored
|
403
|
+
|
404
|
+
bold = "\x1b[1m"
|
405
|
+
color = "\x1b[34m"
|
406
|
+
reset = "\x1b[0m"
|
407
|
+
|
408
|
+
pattern = []
|
409
|
+
pattern << "#{bold}#{color}[MSS"
|
410
|
+
pattern << ":service"
|
411
|
+
pattern << ":http_response_status"
|
412
|
+
pattern << ":duration"
|
413
|
+
pattern << ":retry_count retries]#{reset}#{bold}"
|
414
|
+
pattern << ":operation(:options)"
|
415
|
+
pattern << ":error_class"
|
416
|
+
pattern << ":error_message#{reset}"
|
417
|
+
|
418
|
+
LogFormatter.new(pattern.join(' ') + "\n")
|
419
|
+
|
420
|
+
end
|
421
|
+
|
422
|
+
end
|
423
|
+
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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
|
+
# This trival wrapper around File provides an easy way for the client to know when
|
17
|
+
# the file that it just streamed over HTTP should be closed after receiving the
|
18
|
+
# response. This should only be used internally to track files that we opened.
|
19
|
+
# Open files passed into upload methods should be closed by the user.
|
20
|
+
# @api private
|
21
|
+
class ManagedFile < File
|
22
|
+
|
23
|
+
def self.open path
|
24
|
+
file_opts = ['rb']
|
25
|
+
file_opts << { :encoding => "BINARY" } if Object.const_defined?(:Encoding)
|
26
|
+
super(path.to_s, *file_opts)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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
|
+
# @api private
|
17
|
+
module MetaUtils
|
18
|
+
|
19
|
+
def extend_method(object, name, &block)
|
20
|
+
object.extend(
|
21
|
+
Module.new do
|
22
|
+
define_method(name, &block)
|
23
|
+
end
|
24
|
+
)
|
25
|
+
end
|
26
|
+
module_function :extend_method
|
27
|
+
|
28
|
+
def class_extend_method(klass, name, &block)
|
29
|
+
klass.send(:include,
|
30
|
+
Module.new do
|
31
|
+
define_method(name, &block)
|
32
|
+
end
|
33
|
+
)
|
34
|
+
end
|
35
|
+
module_function :class_extend_method
|
36
|
+
|
37
|
+
def extend(object, &block)
|
38
|
+
object.extend(Module.new(&block))
|
39
|
+
end
|
40
|
+
module_function :extend
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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
|
+
# @api private
|
17
|
+
module Model
|
18
|
+
|
19
|
+
# @api private
|
20
|
+
def initialize(*args)
|
21
|
+
options = args.last.kind_of?(Hash) ? args.last : {}
|
22
|
+
@config = case
|
23
|
+
when options[:config] then options[:config]
|
24
|
+
when args.first.respond_to?(:config) then args.first.config
|
25
|
+
else MSS.config
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Configuration] Returns the configuration for this object.
|
30
|
+
attr_reader :config
|
31
|
+
|
32
|
+
# Each class including this module has its own client class.
|
33
|
+
# Generally it is the service namespace suffixed by client:
|
34
|
+
#
|
35
|
+
# * s3_client
|
36
|
+
# * simple_db_client
|
37
|
+
#
|
38
|
+
# @return Retruns the proper client class for the given model.
|
39
|
+
def client
|
40
|
+
@config.send("#{config_prefix}_client")
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [String] The short name of the service as used in coniguration.
|
44
|
+
# (e.g. SimpleDB::Client.config_prefix #=> 'simple_db')
|
45
|
+
def config_prefix
|
46
|
+
Inflection.ruby_name(self.class.to_s.split(/::/)[1])
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [String] A sensible default inspect string.
|
50
|
+
def inspect
|
51
|
+
"<#{self.class}>"
|
52
|
+
end
|
53
|
+
|
54
|
+
# @api private
|
55
|
+
def to_yaml_properties
|
56
|
+
instance_variables.map(&:to_s) - %w(@config)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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
|
+
# @api private
|
17
|
+
module Naming
|
18
|
+
|
19
|
+
def service_name
|
20
|
+
self.name.split(/::/)[1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def service_ruby_name
|
24
|
+
@service_ruby_name ||= Inflection.ruby_name(service_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|