aws-sdk 1.1.3 → 1.1.4
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.
- data/ca-bundle.crt +2 -348
- data/lib/aws.rb +24 -49
- data/lib/aws/{common.rb → core.rb} +120 -9
- data/lib/aws/{api_config.rb → core/api_config.rb} +19 -20
- data/lib/aws/core/api_config_transform.rb +36 -0
- data/lib/aws/core/async_handle.rb +91 -0
- data/lib/aws/core/authorize_v2.rb +39 -0
- data/lib/aws/{authorize_v3.rb → core/authorize_v3.rb} +16 -15
- data/lib/aws/{api_config_transform.rb → core/authorize_with_session_token.rb} +9 -12
- data/lib/aws/core/autoloader.rb +64 -0
- data/lib/aws/core/cacheable.rb +78 -0
- data/lib/aws/core/client.rb +471 -0
- data/lib/aws/core/client_logging.rb +125 -0
- data/lib/aws/core/collections.rb +229 -0
- data/lib/aws/core/configuration.rb +358 -0
- data/lib/aws/core/configured_client_methods.rb +76 -0
- data/lib/aws/core/configured_grammars.rb +63 -0
- data/lib/aws/{configured_option_grammars.rb → core/configured_option_grammars.rb} +18 -20
- data/lib/aws/{configured_xml_grammars.rb → core/configured_xml_grammars.rb} +19 -21
- data/lib/aws/core/default_signer.rb +67 -0
- data/lib/aws/core/http/curb_handler.rb +129 -0
- data/lib/aws/core/http/handler.rb +77 -0
- data/lib/aws/core/http/httparty_handler.rb +113 -0
- data/lib/aws/core/http/net_http_handler.rb +124 -0
- data/lib/aws/core/http/request.rb +207 -0
- data/lib/aws/core/http/response.rb +73 -0
- data/lib/aws/{ignore_result_element.rb → core/ignore_result_element.rb} +14 -18
- data/lib/aws/core/indifferent_hash.rb +88 -0
- data/lib/aws/core/inflection.rb +47 -0
- data/lib/aws/core/lazy_error_classes.rb +62 -0
- data/lib/aws/{uri_escape.rb → core/meta_utils.rb} +24 -23
- data/lib/aws/core/model.rb +57 -0
- data/lib/aws/{authorize_with_session_token.rb → core/naming.rb} +9 -8
- data/lib/aws/core/option_grammar.rb +562 -0
- data/lib/aws/core/policy.rb +914 -0
- data/lib/aws/core/resource.rb +380 -0
- data/lib/aws/core/resource_cache.rb +40 -0
- data/lib/aws/core/response.rb +125 -0
- data/lib/aws/core/response_cache.rb +50 -0
- data/lib/aws/core/service_interface.rb +60 -0
- data/lib/aws/core/uri_escape.rb +46 -0
- data/lib/aws/core/xml_grammar.rb +926 -0
- data/lib/aws/ec2.rb +47 -16
- data/lib/aws/ec2/attachment.rb +0 -2
- data/lib/aws/ec2/attachment_collection.rb +1 -6
- data/lib/aws/ec2/availability_zone.rb +0 -2
- data/lib/aws/ec2/availability_zone_collection.rb +0 -3
- data/lib/aws/ec2/client.rb +6 -9
- data/lib/aws/ec2/client/xml.rb +3 -6
- data/lib/aws/ec2/collection.rb +1 -4
- data/lib/aws/ec2/config.rb +18 -0
- data/lib/aws/ec2/elastic_ip.rb +0 -2
- data/lib/aws/ec2/elastic_ip_collection.rb +0 -4
- data/lib/aws/ec2/errors.rb +1 -4
- data/lib/aws/ec2/has_permissions.rb +0 -2
- data/lib/aws/ec2/image.rb +0 -5
- data/lib/aws/ec2/image_collection.rb +0 -6
- data/lib/aws/ec2/instance.rb +23 -9
- data/lib/aws/ec2/instance_collection.rb +85 -22
- data/lib/aws/ec2/key_pair.rb +0 -2
- data/lib/aws/ec2/key_pair_collection.rb +1 -4
- data/lib/aws/ec2/permission_collection.rb +2 -5
- data/lib/aws/ec2/region.rb +0 -2
- data/lib/aws/ec2/region_collection.rb +0 -4
- data/lib/aws/ec2/request.rb +4 -9
- data/lib/aws/ec2/reserved_instances.rb +0 -3
- data/lib/aws/ec2/reserved_instances_collection.rb +0 -4
- data/lib/aws/ec2/reserved_instances_offering.rb +0 -3
- data/lib/aws/ec2/reserved_instances_offering_collection.rb +0 -4
- data/lib/aws/ec2/resource.rb +3 -5
- data/lib/aws/ec2/resource_tag_collection.rb +1 -6
- data/lib/aws/ec2/security_group.rb +204 -72
- data/lib/aws/ec2/security_group/egress_ip_permission_collection.rb +53 -0
- data/lib/aws/ec2/security_group/ip_permission.rb +92 -10
- data/lib/aws/ec2/security_group/ip_permission_collection.rb +14 -15
- data/lib/aws/ec2/security_group_collection.rb +11 -8
- data/lib/aws/ec2/snapshot.rb +0 -4
- data/lib/aws/ec2/snapshot_collection.rb +0 -4
- data/lib/aws/ec2/tag.rb +0 -3
- data/lib/aws/ec2/tag_collection.rb +1 -8
- data/lib/aws/ec2/tagged_item.rb +1 -3
- data/lib/aws/ec2/volume.rb +0 -6
- data/lib/aws/ec2/volume_collection.rb +0 -4
- data/lib/aws/errors.rb +0 -3
- data/lib/aws/iam.rb +33 -12
- data/lib/aws/iam/access_key.rb +0 -3
- data/lib/aws/iam/access_key_collection.rb +0 -3
- data/lib/aws/iam/account_alias_collection.rb +0 -2
- data/lib/aws/iam/client.rb +6 -8
- data/lib/aws/iam/client/xml.rb +4 -8
- data/lib/aws/iam/collection.rb +2 -5
- data/lib/aws/iam/config.rb +18 -0
- data/lib/aws/iam/errors.rb +2 -4
- data/lib/aws/iam/group.rb +0 -5
- data/lib/aws/iam/group_collection.rb +0 -3
- data/lib/aws/iam/group_policy_collection.rb +0 -2
- data/lib/aws/iam/group_user_collection.rb +1 -4
- data/lib/aws/iam/login_profile.rb +0 -2
- data/lib/aws/iam/mfa_device.rb +1 -3
- data/lib/aws/iam/mfa_device_collection.rb +0 -3
- data/lib/aws/iam/policy.rb +2 -4
- data/lib/aws/iam/policy_collection.rb +0 -3
- data/lib/aws/iam/request.rb +3 -7
- data/lib/aws/iam/resource.rb +1 -4
- data/lib/aws/iam/server_certificate.rb +0 -2
- data/lib/aws/iam/server_certificate_collection.rb +0 -3
- data/lib/aws/iam/signing_certificate.rb +0 -2
- data/lib/aws/iam/signing_certificate_collection.rb +0 -3
- data/lib/aws/iam/user.rb +0 -7
- data/lib/aws/iam/user_collection.rb +0 -3
- data/lib/aws/iam/user_group_collection.rb +0 -3
- data/lib/aws/iam/user_policy.rb +0 -2
- data/lib/aws/iam/user_policy_collection.rb +0 -3
- data/lib/aws/rails.rb +5 -4
- data/lib/aws/record.rb +4 -1
- data/lib/aws/record/base.rb +3 -2
- data/lib/aws/record/errors.rb +1 -3
- data/lib/aws/s3.rb +31 -6
- data/lib/aws/s3/access_control_list.rb +0 -2
- data/lib/aws/s3/acl_object.rb +10 -12
- data/lib/aws/s3/bucket.rb +1 -9
- data/lib/aws/s3/bucket_collection.rb +2 -5
- data/lib/aws/s3/bucket_version_collection.rb +1 -5
- data/lib/aws/s3/client.rb +34 -37
- data/lib/aws/s3/client/xml.rb +11 -14
- data/lib/aws/{resource_cache.rb → s3/config.rb} +6 -20
- data/lib/aws/s3/errors.rb +6 -7
- data/lib/aws/s3/multipart_upload.rb +1 -4
- data/lib/aws/s3/multipart_upload_collection.rb +1 -6
- data/lib/aws/s3/object_collection.rb +1 -5
- data/lib/aws/s3/object_metadata.rb +1 -3
- data/lib/aws/s3/object_upload_collection.rb +1 -7
- data/lib/aws/s3/object_version.rb +1 -4
- data/lib/aws/s3/object_version_collection.rb +1 -4
- data/lib/aws/s3/policy.rb +3 -5
- data/lib/aws/s3/prefix_and_delimiter_collection.rb +0 -2
- data/lib/aws/s3/prefixed_collection.rb +0 -2
- data/lib/aws/s3/presigned_post.rb +1 -3
- data/lib/aws/s3/request.rb +2 -5
- data/lib/aws/s3/s3_object.rb +1 -8
- data/lib/aws/s3/tree.rb +8 -6
- data/lib/aws/s3/tree/branch_node.rb +0 -3
- data/lib/aws/s3/tree/child_collection.rb +1 -5
- data/lib/aws/s3/tree/leaf_node.rb +0 -5
- data/lib/aws/s3/tree/parent.rb +1 -4
- data/lib/aws/s3/uploaded_part.rb +1 -3
- data/lib/aws/s3/uploaded_part_collection.rb +1 -5
- data/lib/aws/simple_db.rb +21 -6
- data/lib/aws/simple_db/attribute.rb +1 -6
- data/lib/aws/simple_db/attribute_collection.rb +1 -7
- data/lib/aws/simple_db/client.rb +7 -9
- data/lib/aws/simple_db/client/options.rb +2 -4
- data/lib/aws/simple_db/client/xml.rb +5 -10
- data/lib/aws/{naming.rb → simple_db/config.rb} +3 -14
- data/lib/aws/simple_db/delete_attributes.rb +0 -2
- data/lib/aws/simple_db/domain.rb +1 -6
- data/lib/aws/simple_db/domain_collection.rb +1 -4
- data/lib/aws/simple_db/domain_metadata.rb +1 -3
- data/lib/aws/simple_db/errors.rb +1 -4
- data/lib/aws/simple_db/item.rb +1 -7
- data/lib/aws/simple_db/item_collection.rb +22 -23
- data/lib/aws/simple_db/put_attributes.rb +0 -2
- data/lib/aws/simple_db/request.rb +3 -7
- data/lib/aws/simple_email_service.rb +11 -6
- data/lib/aws/simple_email_service/client.rb +7 -9
- data/lib/aws/simple_email_service/client/options.rb +3 -6
- data/lib/aws/simple_email_service/client/xml.rb +4 -8
- data/lib/aws/simple_email_service/config.rb +19 -0
- data/lib/aws/simple_email_service/email_address_collection.rb +1 -3
- data/lib/aws/simple_email_service/errors.rb +1 -4
- data/lib/aws/simple_email_service/quotas.rb +1 -3
- data/lib/aws/simple_email_service/request.rb +3 -7
- data/lib/aws/sns.rb +15 -8
- data/lib/aws/sns/client.rb +7 -8
- data/lib/aws/sns/client/options.rb +3 -6
- data/lib/aws/sns/client/xml.rb +4 -8
- data/lib/aws/sns/config.rb +18 -0
- data/lib/aws/sns/errors.rb +1 -4
- data/lib/aws/sns/policy.rb +3 -5
- data/lib/aws/sns/request.rb +4 -9
- data/lib/aws/sns/subscription.rb +1 -5
- data/lib/aws/sns/subscription_collection.rb +1 -5
- data/lib/aws/sns/topic.rb +1 -6
- data/lib/aws/sns/topic_collection.rb +1 -4
- data/lib/aws/sns/topic_subscription_collection.rb +1 -4
- data/lib/aws/sqs.rb +14 -5
- data/lib/aws/sqs/client.rb +6 -9
- data/lib/aws/sqs/client/xml.rb +4 -7
- data/lib/aws/sqs/config.rb +18 -0
- data/lib/aws/sqs/errors.rb +1 -4
- data/lib/aws/sqs/policy.rb +3 -5
- data/lib/aws/sqs/queue.rb +2 -7
- data/lib/aws/sqs/queue_collection.rb +4 -5
- data/lib/aws/sqs/received_message.rb +1 -3
- data/lib/aws/sqs/received_sns_message.rb +2 -2
- data/lib/aws/sqs/request.rb +4 -7
- data/lib/aws/sts.rb +12 -6
- data/lib/aws/sts/client.rb +6 -8
- data/lib/aws/sts/client/xml.rb +4 -8
- data/lib/aws/sts/config.rb +18 -0
- data/lib/aws/sts/errors.rb +1 -4
- data/lib/aws/sts/federated_session.rb +0 -2
- data/lib/aws/sts/policy.rb +3 -5
- data/lib/aws/sts/request.rb +3 -7
- metadata +60 -50
- data/lib/aws/async_handle.rb +0 -90
- data/lib/aws/authorize_v2.rb +0 -37
- data/lib/aws/base_client.rb +0 -488
- data/lib/aws/cacheable.rb +0 -79
- data/lib/aws/client_logging.rb +0 -122
- data/lib/aws/collections.rb +0 -230
- data/lib/aws/configuration.rb +0 -357
- data/lib/aws/configured_client_methods.rb +0 -81
- data/lib/aws/configured_grammars.rb +0 -65
- data/lib/aws/default_signer.rb +0 -65
- data/lib/aws/http/curb_handler.rb +0 -127
- data/lib/aws/http/handler.rb +0 -77
- data/lib/aws/http/httparty_handler.rb +0 -103
- data/lib/aws/http/request.rb +0 -165
- data/lib/aws/http/request_param.rb +0 -64
- data/lib/aws/http/response.rb +0 -72
- data/lib/aws/indifferent_hash.rb +0 -86
- data/lib/aws/inflection.rb +0 -46
- data/lib/aws/lazy_error_classes.rb +0 -64
- data/lib/aws/meta_utils.rb +0 -43
- data/lib/aws/model.rb +0 -57
- data/lib/aws/option_grammar.rb +0 -565
- data/lib/aws/policy.rb +0 -914
- data/lib/aws/resource.rb +0 -381
- data/lib/aws/response.rb +0 -125
- data/lib/aws/response_cache.rb +0 -50
- data/lib/aws/service_interface.rb +0 -60
- data/lib/aws/xml_grammar.rb +0 -925
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Copyright 2011 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
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'benchmark'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
module Core
|
|
18
|
+
|
|
19
|
+
# @private
|
|
20
|
+
module ClientLogging
|
|
21
|
+
|
|
22
|
+
MAX_STRING_LENGTH = 50
|
|
23
|
+
|
|
24
|
+
def log_client_request(name, options)
|
|
25
|
+
response = nil
|
|
26
|
+
time = Benchmark.measure do
|
|
27
|
+
response = yield
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if options[:async]
|
|
31
|
+
response.on_complete do
|
|
32
|
+
log_client_request_on_success(name, options, response, time)
|
|
33
|
+
end
|
|
34
|
+
else
|
|
35
|
+
log_client_request_on_success(name, options, response, time)
|
|
36
|
+
end
|
|
37
|
+
response
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Summarizes long strings and adds file size information
|
|
41
|
+
# @private
|
|
42
|
+
def sanitize_options(options)
|
|
43
|
+
sanitize_hash(options)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
protected
|
|
47
|
+
def log severity, message
|
|
48
|
+
config.logger.send(severity, message + "\n") if config.logger
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
protected
|
|
52
|
+
def log_client_request_on_success(method_name, options, response, time)
|
|
53
|
+
status = response.http_response.status
|
|
54
|
+
service = self.class.service_name
|
|
55
|
+
|
|
56
|
+
pattern = "[AWS %s %s %.06f] %s(%s)"
|
|
57
|
+
parts = [service, status, time.real, method_name, sanitize_options(options)]
|
|
58
|
+
severity = :info
|
|
59
|
+
|
|
60
|
+
if response.error
|
|
61
|
+
pattern += " %s: %s"
|
|
62
|
+
parts << response.error.class
|
|
63
|
+
parts << response.error.message
|
|
64
|
+
severity = :error
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
if response.cached
|
|
68
|
+
pattern << " [CACHED]"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
log(severity, pattern % parts)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
protected
|
|
75
|
+
def sanitize_value(value)
|
|
76
|
+
case value
|
|
77
|
+
when Hash
|
|
78
|
+
'{' + sanitize_hash(value) + '}'
|
|
79
|
+
when Array
|
|
80
|
+
sanitize_array(value)
|
|
81
|
+
when File
|
|
82
|
+
sanitize_file(value)
|
|
83
|
+
when String
|
|
84
|
+
sanitize_string(value)
|
|
85
|
+
else
|
|
86
|
+
value.inspect
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
protected
|
|
91
|
+
def sanitize_string str
|
|
92
|
+
summary = summarize_string(str)
|
|
93
|
+
inspected = str.inspect
|
|
94
|
+
if inspected.size > summary.size
|
|
95
|
+
summary
|
|
96
|
+
else
|
|
97
|
+
inspected
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
protected
|
|
102
|
+
def summarize_string str
|
|
103
|
+
"#<String #{str[0,6].inspect} ... #{str[-6,6].inspect} (#{str.size} characters)>"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
protected
|
|
107
|
+
def sanitize_file file
|
|
108
|
+
"#<File:#{file.path} (#{File.size(file.path)} bytes)>"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
protected
|
|
112
|
+
def sanitize_array array
|
|
113
|
+
"[" + array.map { |v| sanitize_value(v) }.join(",") + "]"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
protected
|
|
117
|
+
def sanitize_hash hash
|
|
118
|
+
hash.map do |k,v|
|
|
119
|
+
"#{sanitize_value(k)}=>#{sanitize_value(v)}"
|
|
120
|
+
end.sort.join(",")
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Copyright 2011 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
|
+
# http://aws.amazon.com/apache2.0/
|
|
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 AWS
|
|
14
|
+
module Core
|
|
15
|
+
|
|
16
|
+
# There are 3 collection modules:
|
|
17
|
+
#
|
|
18
|
+
# AWS::Collections::Basic
|
|
19
|
+
# - single request returns all items
|
|
20
|
+
# - (sqs, ec2, ses)
|
|
21
|
+
#
|
|
22
|
+
# AWS::Collections::Paged
|
|
23
|
+
# - responses may be truncated
|
|
24
|
+
# - truncated responses return a "next token"
|
|
25
|
+
# - (sns, sdb)
|
|
26
|
+
#
|
|
27
|
+
# AWS::Collections::PagedWithLimits
|
|
28
|
+
# - requests accept a "max items"
|
|
29
|
+
# - responses may be "truncated"
|
|
30
|
+
# - truncated responses return a "next token"
|
|
31
|
+
# - (s3, iam)
|
|
32
|
+
#
|
|
33
|
+
# @private
|
|
34
|
+
module Collections
|
|
35
|
+
|
|
36
|
+
# @private
|
|
37
|
+
module Basic
|
|
38
|
+
|
|
39
|
+
include Model
|
|
40
|
+
include Enumerable
|
|
41
|
+
|
|
42
|
+
def enumerator options = {}
|
|
43
|
+
Enumerator.new(self, :each, options)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def each options = {}, &block
|
|
47
|
+
each_batch(options) do |batch|
|
|
48
|
+
batch.each(&block)
|
|
49
|
+
end
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def each_batch options = {}, &block
|
|
54
|
+
|
|
55
|
+
options = options.dup
|
|
56
|
+
|
|
57
|
+
limit = options.delete(:limit)
|
|
58
|
+
batch_size = options.delete(:batch_size)
|
|
59
|
+
|
|
60
|
+
total = 0 # count of items yeileded across all batches
|
|
61
|
+
|
|
62
|
+
each_response(options, limit, batch_size) do |response|
|
|
63
|
+
|
|
64
|
+
batch = []
|
|
65
|
+
each_item(response) do |item|
|
|
66
|
+
batch << item
|
|
67
|
+
if limit and (total += 1) == limit
|
|
68
|
+
yield(batch)
|
|
69
|
+
return
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
yield(batch)
|
|
74
|
+
|
|
75
|
+
batch.size
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
nil
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def in_groups_of size, options = {}, &block
|
|
84
|
+
|
|
85
|
+
group = []
|
|
86
|
+
|
|
87
|
+
each_batch(options) do |batch|
|
|
88
|
+
batch.each do |item|
|
|
89
|
+
group << item
|
|
90
|
+
if group.size == size
|
|
91
|
+
yield(group)
|
|
92
|
+
group = []
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
yield(group) unless group.empty?
|
|
98
|
+
|
|
99
|
+
nil
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# @note +limit+ has no effect, simply ignored
|
|
104
|
+
# @note +batch_size+ has no effect, simply ignored
|
|
105
|
+
# @private
|
|
106
|
+
protected
|
|
107
|
+
def each_response options, limit, batch_size, &block
|
|
108
|
+
response = client.send(request_method, options)
|
|
109
|
+
yield(response)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# @note Define this method in classes including this module.
|
|
113
|
+
# @private
|
|
114
|
+
protected
|
|
115
|
+
def request_method
|
|
116
|
+
raise NotImplementedError
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# @note Define this method in classes including this module.
|
|
120
|
+
# @private
|
|
121
|
+
protected
|
|
122
|
+
def each_item response
|
|
123
|
+
raise NotImplementedError
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# @private
|
|
129
|
+
module Paged
|
|
130
|
+
|
|
131
|
+
include Basic
|
|
132
|
+
|
|
133
|
+
# @note +limit+ has no effect, simply ignored
|
|
134
|
+
# @note +batch_size+ has no effect, simply ignored
|
|
135
|
+
protected
|
|
136
|
+
def each_response options, limit, batch_size, &block
|
|
137
|
+
|
|
138
|
+
next_token = nil
|
|
139
|
+
|
|
140
|
+
begin
|
|
141
|
+
|
|
142
|
+
page_opts = {}
|
|
143
|
+
page_opts[next_token_key] = next_token if next_token
|
|
144
|
+
|
|
145
|
+
response = client.send(request_method, options.merge(page_opts))
|
|
146
|
+
|
|
147
|
+
yield(response)
|
|
148
|
+
|
|
149
|
+
next_token = next_token_for(response)
|
|
150
|
+
|
|
151
|
+
end until next_token.nil?
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Override this methid in collections that use a different name
|
|
156
|
+
# for the param that offsets the find (e.g. :marker, :next_key, etc).
|
|
157
|
+
# @private
|
|
158
|
+
protected
|
|
159
|
+
def next_token_key
|
|
160
|
+
raise NotImplementedError
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Override this method in collections that have an alternate method
|
|
164
|
+
# for finding the next token.
|
|
165
|
+
# @private
|
|
166
|
+
protected
|
|
167
|
+
def next_token_for response
|
|
168
|
+
method = next_token_key
|
|
169
|
+
response.respond_to?(method) ? response.send(method) : nil
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# @private
|
|
175
|
+
module PagedWithLimits
|
|
176
|
+
|
|
177
|
+
include Paged
|
|
178
|
+
|
|
179
|
+
# A custom first method makes getting exactly one item much more
|
|
180
|
+
# efficient. Without the :limit => 1, an entire page of items
|
|
181
|
+
# is received and then only one is grabbed.
|
|
182
|
+
# @private
|
|
183
|
+
def first
|
|
184
|
+
enumerator(:limit => 1).first
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# @private
|
|
188
|
+
protected
|
|
189
|
+
def each_response options, limit, batch_size, &block
|
|
190
|
+
|
|
191
|
+
total = 0
|
|
192
|
+
next_token = nil
|
|
193
|
+
|
|
194
|
+
begin
|
|
195
|
+
|
|
196
|
+
page_opts = {}
|
|
197
|
+
|
|
198
|
+
page_opts[next_token_key] = next_token if next_token
|
|
199
|
+
|
|
200
|
+
if limit or batch_size
|
|
201
|
+
max_items = []
|
|
202
|
+
max_items << (limit - total) if limit
|
|
203
|
+
max_items << batch_size if batch_size
|
|
204
|
+
page_opts[limit_key] = max_items.min
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
response = client.send(request_method, options.merge(page_opts))
|
|
208
|
+
|
|
209
|
+
total += yield(response)
|
|
210
|
+
|
|
211
|
+
next_token = next_token_for(response)
|
|
212
|
+
|
|
213
|
+
end until next_token.nil? or (limit and limit == total)
|
|
214
|
+
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Override this methid in collections that use a different name
|
|
218
|
+
# for the param that offsets the find (e.g. :marker, :next_key, etc).
|
|
219
|
+
# @private
|
|
220
|
+
protected
|
|
221
|
+
def limit_key
|
|
222
|
+
raise NotImplementedError
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
# Copyright 2011 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
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
require 'set'
|
|
15
|
+
require 'uri'
|
|
16
|
+
|
|
17
|
+
module AWS
|
|
18
|
+
module Core
|
|
19
|
+
|
|
20
|
+
# A configuration object for AWS interfaces and clients.
|
|
21
|
+
#
|
|
22
|
+
# == Configuring Credential
|
|
23
|
+
#
|
|
24
|
+
# In order to do anything with AWS you will need to assign credentials.
|
|
25
|
+
# The simplest method is to assing your credentials into the default
|
|
26
|
+
# configuration:
|
|
27
|
+
#
|
|
28
|
+
# AWS.config(:access_key_id => 'KEY', :secret_access_key => 'SECRET')
|
|
29
|
+
#
|
|
30
|
+
# You can also export them into your environment and they will be picked up
|
|
31
|
+
# automatically:
|
|
32
|
+
#
|
|
33
|
+
# export AWS_ACCESS_KEY_ID='YOUR_KEY_ID_HERE'
|
|
34
|
+
# export AWS_SECRET_ACCESS_KEY='YOUR_SECRET_KEY_HERE'
|
|
35
|
+
#
|
|
36
|
+
# For compatability with other AWS gems, the credentials can also be
|
|
37
|
+
# exported like:
|
|
38
|
+
#
|
|
39
|
+
# export AMAZON_ACCESS_KEY_ID='YOUR_KEY_ID_HERE'
|
|
40
|
+
# export AMAZON_SECRET_ACCESS_KEY='YOUR_SECRET_KEY_HERE'
|
|
41
|
+
#
|
|
42
|
+
# == Modifying a Configuration
|
|
43
|
+
#
|
|
44
|
+
# Configuration objects are read-only. If you need a different set of
|
|
45
|
+
# configuration values, call {#with}, passing in the updates
|
|
46
|
+
# and a new configuration object will be returned.
|
|
47
|
+
#
|
|
48
|
+
# config = Configuration.new(:max_retires => 3)
|
|
49
|
+
# new_config = config.with(:max_retries => 2)
|
|
50
|
+
#
|
|
51
|
+
# config.max_retries #=> 3
|
|
52
|
+
# new_config.max_retries #=> 2
|
|
53
|
+
#
|
|
54
|
+
# == Global Configuration
|
|
55
|
+
#
|
|
56
|
+
# The global default configuration can be found at {AWS.config}
|
|
57
|
+
#
|
|
58
|
+
# @attr_reader [String,nil] access_key_id AWS access key id credential.
|
|
59
|
+
# Defaults to +nil+.
|
|
60
|
+
#
|
|
61
|
+
# @attr_reader [String] ec2_endpoint The service endpoint for Amazon EC2.
|
|
62
|
+
# Defaults to 'ec2.amazonaws.com'.
|
|
63
|
+
#
|
|
64
|
+
# @attr_reader [Object] http_handler The http handler that sends requests
|
|
65
|
+
# to AWS. Defaults to an HTTP handler built on net/http.
|
|
66
|
+
#
|
|
67
|
+
# @attr_reader [String] iam_endpoint The service endpoint for AWS Idenity
|
|
68
|
+
# Access Management (IAM). Defaults to 'iam.amazonaws.com'.
|
|
69
|
+
#
|
|
70
|
+
# @attr_reader [Object,nil] logger A logger instance that
|
|
71
|
+
# should receive log messages generated by service requets.
|
|
72
|
+
# A logger needs to respond to #log and must accept a
|
|
73
|
+
# severity (e.g. :info, :error, etc) and a string message.
|
|
74
|
+
# Defaults to +nil+.
|
|
75
|
+
#
|
|
76
|
+
# @attr_reader [Integer] max_retries The maximum number of times
|
|
77
|
+
# service errors (500) should be retried. There is an exponential
|
|
78
|
+
# backoff in between service request retries, so the more retries the
|
|
79
|
+
# longer it can take to fail. Defautls to 3.
|
|
80
|
+
#
|
|
81
|
+
# @attr_reader [String, URI, nil] proxy_uri The URI of the proxy
|
|
82
|
+
# to send service requests through. You can pass a URI object or a
|
|
83
|
+
# URI string. Defautls to +nil+.
|
|
84
|
+
#
|
|
85
|
+
# AWS.config(:proxy_uri => 'https://user:pass@my.proxy:443/path?query')
|
|
86
|
+
#
|
|
87
|
+
# @attr_reader [String] s3_endpoint The service endpoint for Amazon S3.
|
|
88
|
+
# Defaults to 's3.amazonaws.com'.
|
|
89
|
+
#
|
|
90
|
+
# @attr_reader [Integer] s3_multipart_max_parts The maximum number of
|
|
91
|
+
# parts to split a file into when uploading in parts to S3.
|
|
92
|
+
# Defaults to 1000.
|
|
93
|
+
#
|
|
94
|
+
# @attr_reader [Integer] s3_multipart_threshold (16777216) When uploading
|
|
95
|
+
# data to S3, if the number of bytes to send exceedes
|
|
96
|
+
# +:s3_multipart_threshold+ then a multi part session is automatically
|
|
97
|
+
# started and the data is sent up in chunks. The size of each part
|
|
98
|
+
# is specified by +:s3_multipart_min_part_size+. Defaults to
|
|
99
|
+
# 16777216 (16MB).
|
|
100
|
+
#
|
|
101
|
+
# @attr_reader [Integer] s3_multipart_min_part_size The absolute minimum
|
|
102
|
+
# size (in bytes) each S3 multipart segment should be.
|
|
103
|
+
# Defaults to 5242880 (5MB).
|
|
104
|
+
#
|
|
105
|
+
# @attr_reader [String,nil] secret_access_key AWS secret access key
|
|
106
|
+
# credential. Defaults to +nil+.
|
|
107
|
+
#
|
|
108
|
+
# @attr_reader [String,nil] session_token AWS secret token credential.
|
|
109
|
+
# Defaults to +nil+.
|
|
110
|
+
#
|
|
111
|
+
# @attr_reader [String] simple_db_endpoint The service endpoint for Amazon
|
|
112
|
+
# SimpleDB. Defaults to 'sdb.amazonaws.com'.
|
|
113
|
+
#
|
|
114
|
+
# @attr_reader [Boolean] simple_db_consistent_reads Determines
|
|
115
|
+
# if all SimpleDB read requests should be done consistently.
|
|
116
|
+
# Consistent reads are slower, but reflect all changes to SDB.
|
|
117
|
+
# Defaults to +false+.
|
|
118
|
+
#
|
|
119
|
+
# @attr_reader [String] simple_email_service_endpoint The service endpoint
|
|
120
|
+
# for Amazon Simple Email Service. Defaults to
|
|
121
|
+
# 'email.us-east-1.amazonaws.com'.
|
|
122
|
+
#
|
|
123
|
+
# @attr_reader [Object] signer The request signer. Defaults to
|
|
124
|
+
# a default request signer implementation.
|
|
125
|
+
#
|
|
126
|
+
# @attr_reader [String] ssl_ca_file The path to a CA cert bundle in
|
|
127
|
+
# PEM format.
|
|
128
|
+
#
|
|
129
|
+
# If +ssl_verify_peer+ is true (the default) this bundle will be
|
|
130
|
+
# used to validate the server certificate in each HTTPS request.
|
|
131
|
+
# The AWS SDK for Ruby ships with a CA cert bundle, which is the
|
|
132
|
+
# default value for this option.
|
|
133
|
+
#
|
|
134
|
+
# @attr_reader [Boolean] ssl_verify_peer When +true+
|
|
135
|
+
# the HTTP handler validate server certificates for HTTPS requests.
|
|
136
|
+
# Defaults to +true+.
|
|
137
|
+
#
|
|
138
|
+
# This option should only be disabled for diagnostic purposes;
|
|
139
|
+
# leaving this option set to +false+ exposes your application to
|
|
140
|
+
# man-in-the-middle attacks and can pose a serious security
|
|
141
|
+
# risk.
|
|
142
|
+
#
|
|
143
|
+
# @attr_reader [Boolean] stub_requests When +true+ requests are not
|
|
144
|
+
# sent to AWS, instead empty reponses are generated and returned to
|
|
145
|
+
# each service request.
|
|
146
|
+
#
|
|
147
|
+
# @attr_reader [String] sns_endpoint The service endpoint for Amazon SNS.
|
|
148
|
+
# Defaults to 'sns.us-east-1.amazonaws.com'.
|
|
149
|
+
#
|
|
150
|
+
# @attr_reader [String] sqs_endpoint The service endpoint for Amazon SQS.
|
|
151
|
+
# Defaults to 'sqs.us-east-1.amazonaws.com'.
|
|
152
|
+
#
|
|
153
|
+
# @attr_reader [String] sts_endpoint The service endpoint for AWS
|
|
154
|
+
# Security Token Service. Defaults to 'sts.amazonaws.com'.
|
|
155
|
+
#
|
|
156
|
+
# @attr_reader [Boolean] use_ssl When +true+, all requests
|
|
157
|
+
# to AWS are sent using HTTPS instead vanilla HTTP.
|
|
158
|
+
# Defaults to +true+.
|
|
159
|
+
#
|
|
160
|
+
# @attr_reader [String] user_agent_prefix A string prefix to
|
|
161
|
+
# append to all requets against AWS services. This should be set
|
|
162
|
+
# for clients and applications built ontop of the aws-sdk gem.
|
|
163
|
+
# Defaults to +nil+.
|
|
164
|
+
#
|
|
165
|
+
class Configuration
|
|
166
|
+
|
|
167
|
+
# Creates a new Configuration object.
|
|
168
|
+
# @param options (see AWS.config)
|
|
169
|
+
# @option options (see AWS.config)
|
|
170
|
+
def initialize options = {}
|
|
171
|
+
|
|
172
|
+
@created = options.delete(:__created__) || {}
|
|
173
|
+
|
|
174
|
+
options.each_pair do |opt_name, value|
|
|
175
|
+
opt_name = opt_name.to_sym
|
|
176
|
+
if self.class.accepted_options.include?(opt_name)
|
|
177
|
+
supplied[opt_name] = value
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Used to create a new Configuration object with the given modifications.
|
|
184
|
+
# The current configuration object is not modified.
|
|
185
|
+
#
|
|
186
|
+
# AWS.config(:max_retries => 2)
|
|
187
|
+
#
|
|
188
|
+
# no_retries_config = AWS.config.with(:max_retries => 0)
|
|
189
|
+
#
|
|
190
|
+
# AWS.config.max_retries #=> 2
|
|
191
|
+
# no_retries_config.max_retries #=> 0
|
|
192
|
+
#
|
|
193
|
+
# You can use these configuration objects returned by #with to create
|
|
194
|
+
# AWS objects:
|
|
195
|
+
#
|
|
196
|
+
# AWS::S3.new(:config => no_retries_config)
|
|
197
|
+
# AWS::SQS.new(:config => no_retries_config)
|
|
198
|
+
#
|
|
199
|
+
# @param options (see AWS.config)
|
|
200
|
+
# @option options (see AWS.config)
|
|
201
|
+
# @return [Configuration] Copies the current configuration and returns
|
|
202
|
+
# a new one with modifications as provided in +:options+.
|
|
203
|
+
def with options = {}
|
|
204
|
+
|
|
205
|
+
# symbolize option keys
|
|
206
|
+
options = options.inject({}) {|h,kv| h[kv.first.to_sym] = kv.last; h }
|
|
207
|
+
|
|
208
|
+
values = supplied.merge(options)
|
|
209
|
+
|
|
210
|
+
if supplied == values
|
|
211
|
+
self # nothing changed
|
|
212
|
+
else
|
|
213
|
+
self.class.new(values.merge(:__created__ => @created.dup))
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# @return [Hash] Returns a hash of all configuration values.
|
|
219
|
+
def to_h
|
|
220
|
+
self.class.accepted_options.inject({}) do |h,k|
|
|
221
|
+
h[k] = send(k)
|
|
222
|
+
h
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# @return [Boolean] Returns true if the two configuration objects have
|
|
227
|
+
# the same values.
|
|
228
|
+
def == other
|
|
229
|
+
other.is_a?(self.class) and self.supplied == other.supplied
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
alias_method :eql, :==
|
|
233
|
+
|
|
234
|
+
# @private
|
|
235
|
+
def inspect
|
|
236
|
+
"<#{self.class.name}>"
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
protected
|
|
240
|
+
def supplied
|
|
241
|
+
@supplied ||= {}
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
class << self
|
|
245
|
+
|
|
246
|
+
# @private
|
|
247
|
+
def accepted_options
|
|
248
|
+
@options ||= Set.new
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# @private
|
|
252
|
+
def add_option name, default_value = nil, options = {}, &transform
|
|
253
|
+
|
|
254
|
+
accepted_options << name
|
|
255
|
+
|
|
256
|
+
define_method(name) do
|
|
257
|
+
value = supplied.has_key?(name) ? supplied[name] : default_value
|
|
258
|
+
transform ? transform.call(value) : value
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
alias_method("#{name}?", name) if options[:boolean]
|
|
262
|
+
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# Configuration options that have dependencies are re-recreated
|
|
266
|
+
# anytime one of their dependendent configuration values are
|
|
267
|
+
# changed.
|
|
268
|
+
# @private
|
|
269
|
+
def add_option_with_needs name, needs, &create_block
|
|
270
|
+
|
|
271
|
+
accepted_options << name
|
|
272
|
+
|
|
273
|
+
define_method(name) do
|
|
274
|
+
|
|
275
|
+
return supplied[name] if supplied.has_key?(name)
|
|
276
|
+
|
|
277
|
+
needed = needs.collect{|need| send(need) }
|
|
278
|
+
|
|
279
|
+
unless @created.key?(name) and @created[name][:needed] == needed
|
|
280
|
+
@created[name] = {}
|
|
281
|
+
@created[name][:object] = create_block.call(self)
|
|
282
|
+
@created[name][:needed] = needed
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
@created[name][:object]
|
|
286
|
+
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def add_service name, ruby_name, default_endpoint
|
|
292
|
+
|
|
293
|
+
create_block = lambda do |config|
|
|
294
|
+
AWS.const_get(name)::Client.new(:config => config)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
needs = [
|
|
298
|
+
:signer,
|
|
299
|
+
:http_handler,
|
|
300
|
+
:"#{ruby_name}_endpoint",
|
|
301
|
+
:max_retries,
|
|
302
|
+
:stub_requests?,
|
|
303
|
+
:proxy_uri,
|
|
304
|
+
:use_ssl?,
|
|
305
|
+
:ssl_verify_peer?,
|
|
306
|
+
:ssl_ca_file,
|
|
307
|
+
:user_agent_prefix,
|
|
308
|
+
:logger,
|
|
309
|
+
]
|
|
310
|
+
|
|
311
|
+
add_option :"#{ruby_name}_endpoint", default_endpoint
|
|
312
|
+
|
|
313
|
+
add_option_with_needs :"#{ruby_name}_client", needs, &create_block
|
|
314
|
+
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
add_option :access_key_id,
|
|
320
|
+
ENV['AWS_ACCESS_KEY_ID'] || ENV['AMAZON_ACCESS_KEY_ID']
|
|
321
|
+
|
|
322
|
+
add_option :http_handler, Core::Http::NetHttpHandler.new
|
|
323
|
+
|
|
324
|
+
add_option :logger
|
|
325
|
+
|
|
326
|
+
add_option :max_retries, 3
|
|
327
|
+
|
|
328
|
+
add_option :proxy_uri do |uri| uri ? URI.parse(uri.to_s) : nil end
|
|
329
|
+
|
|
330
|
+
add_option :secret_access_key,
|
|
331
|
+
ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AMAZON_SECRET_ACCESS_KEY']
|
|
332
|
+
|
|
333
|
+
add_option :session_token
|
|
334
|
+
|
|
335
|
+
add_option_with_needs :signer,
|
|
336
|
+
[:access_key_id, :secret_access_key, :session_token] do |config|
|
|
337
|
+
|
|
338
|
+
DefaultSigner.new(
|
|
339
|
+
config.access_key_id,
|
|
340
|
+
config.secret_access_key,
|
|
341
|
+
config.session_token)
|
|
342
|
+
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
add_option :ssl_verify_peer, true, :boolean => true
|
|
346
|
+
|
|
347
|
+
add_option :ssl_ca_file,
|
|
348
|
+
File.expand_path(File.dirname(__FILE__) + "/../../../ca-bundle.crt")
|
|
349
|
+
|
|
350
|
+
add_option :stub_requests, false, :boolean => true
|
|
351
|
+
|
|
352
|
+
add_option :use_ssl, true, :boolean => true
|
|
353
|
+
|
|
354
|
+
add_option :user_agent_prefix
|
|
355
|
+
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
end
|