aws-sdk-core 2.0.48 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/apis/autoscaling/2011-01-01/api-2.json +636 -33
- data/apis/cloudhsm/2014-05-30/api-2.json +3 -6
- data/apis/ec2/2014-10-01/api-2.json +10267 -0
- data/apis/ec2/2014-10-01/paginators-1.json +125 -0
- data/apis/ec2/2014-10-01/resources-1.json +2289 -0
- data/apis/ec2/2014-10-01/waiters-2.json +453 -0
- data/apis/ec2/2015-03-01/api-2.json +11245 -0
- data/apis/ec2/2015-03-01/paginators-1.json +125 -0
- data/apis/ec2/2015-03-01/resources-1.json +2479 -0
- data/apis/ec2/2015-03-01/waiters-2.json +458 -0
- data/apis/ec2/2015-04-15/api-2.json +182 -2
- data/apis/ecs/2014-11-13/api-2.json +316 -7
- data/apis/ecs/2014-11-13/paginators-1.json +40 -0
- data/apis/ecs/2014-11-13/waiters-2.json +93 -0
- data/apis/redshift/2012-12-01/waiters-2.json +19 -0
- data/apis/s3/2006-03-01/api-2.json +1 -2
- data/apis/sqs/2012-11-05/api-2.json +5 -6
- data/ca-bundle.crt +3554 -0
- data/lib/aws-sdk-core.rb +127 -44
- data/lib/aws-sdk-core/api/builder.rb +95 -0
- data/lib/aws-sdk-core/api/customizations.rb +152 -0
- data/lib/aws-sdk-core/api/docs/builder.rb +220 -0
- data/lib/aws-sdk-core/api/docs/client_type_documenter.rb +109 -0
- data/lib/aws-sdk-core/api/docs/docstring_provider.rb +66 -0
- data/lib/aws-sdk-core/api/docs/operation_documenter.rb +107 -0
- data/lib/aws-sdk-core/api/docs/param_formatter.rb +163 -0
- data/lib/aws-sdk-core/api/docs/request_syntax_example.rb +22 -0
- data/lib/aws-sdk-core/api/docs/response_structure_example.rb +91 -0
- data/lib/aws-sdk-core/api/docs/utils.rb +133 -0
- data/lib/aws-sdk-core/api/shape_map.rb +140 -0
- data/lib/aws-sdk-core/assume_role_credentials.rb +9 -6
- data/lib/aws-sdk-core/client.rb +9 -6
- data/lib/aws-sdk-core/client_stubs.rb +127 -133
- data/lib/aws-sdk-core/client_waiters.rb +1 -1
- data/lib/aws-sdk-core/credential_provider.rb +44 -0
- data/lib/aws-sdk-core/credential_provider_chain.rb +3 -2
- data/lib/aws-sdk-core/credentials.rb +5 -0
- data/lib/aws-sdk-core/deprecations.rb +69 -0
- data/lib/aws-sdk-core/dynamodb.rb +12 -0
- data/lib/aws-sdk-core/eager_loader.rb +31 -0
- data/lib/aws-sdk-core/ecs.rb +2 -0
- data/lib/aws-sdk-core/empty_structure.rb +1 -82
- data/lib/aws-sdk-core/endpoint_provider.rb +1 -1
- data/lib/aws-sdk-core/instance_profile_credentials.rb +9 -10
- data/lib/aws-sdk-core/json.rb +56 -0
- data/lib/aws-sdk-core/json/builder.rb +33 -34
- data/lib/aws-sdk-core/json/error_handler.rb +2 -2
- data/lib/aws-sdk-core/json/handler.rb +67 -0
- data/lib/aws-sdk-core/json/json_engine.rb +15 -0
- data/lib/aws-sdk-core/json/oj_engine.rb +15 -0
- data/lib/aws-sdk-core/json/parser.rb +30 -38
- data/lib/aws-sdk-core/pageable_response.rb +9 -12
- data/lib/aws-sdk-core/pager.rb +69 -0
- data/lib/aws-sdk-core/param_converter.rb +203 -0
- data/lib/aws-sdk-core/param_validator.rb +148 -0
- data/lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb +21 -18
- data/lib/aws-sdk-core/plugins/glacier_account_id.rb +9 -1
- data/lib/aws-sdk-core/plugins/glacier_checksums.rb +2 -3
- data/lib/aws-sdk-core/plugins/param_converter.rb +27 -0
- data/lib/aws-sdk-core/plugins/param_validator.rb +28 -0
- data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +3 -7
- data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +1 -2
- data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +1 -1
- data/lib/aws-sdk-core/plugins/regional_endpoint.rb +1 -1
- data/lib/aws-sdk-core/plugins/request_signer.rb +5 -5
- data/lib/aws-sdk-core/plugins/response_paging.rb +20 -11
- data/lib/aws-sdk-core/plugins/s3_get_bucket_location_fix.rb +1 -1
- data/lib/aws-sdk-core/plugins/s3_request_signer.rb +1 -2
- data/lib/aws-sdk-core/plugins/stub_responses.rb +25 -27
- data/lib/aws-sdk-core/query/ec2_param_builder.rb +29 -34
- data/lib/aws-sdk-core/query/handler.rb +32 -18
- data/lib/aws-sdk-core/query/param_builder.rb +45 -53
- data/lib/aws-sdk-core/refreshing_credentials.rb +3 -15
- data/lib/aws-sdk-core/rest/handler.rb +22 -0
- data/lib/aws-sdk-core/rest/request/body.rb +58 -0
- data/lib/aws-sdk-core/rest/request/builder.rb +50 -0
- data/lib/aws-sdk-core/rest/request/endpoint.rb +70 -0
- data/lib/aws-sdk-core/rest/request/headers.rb +48 -0
- data/lib/aws-sdk-core/rest/response/body.rb +43 -0
- data/lib/aws-sdk-core/rest/response/headers.rb +60 -0
- data/lib/aws-sdk-core/rest/response/parser.rb +47 -0
- data/lib/aws-sdk-core/rest/response/status_code.rb +24 -0
- data/lib/aws-sdk-core/shared_credentials.rb +11 -6
- data/lib/aws-sdk-core/signers/base.rb +1 -1
- data/lib/aws-sdk-core/signers/s3.rb +2 -3
- data/lib/aws-sdk-core/signers/v2.rb +7 -4
- data/lib/aws-sdk-core/signers/v4.rb +11 -22
- data/lib/aws-sdk-core/structure.rb +26 -145
- data/lib/aws-sdk-core/stubbing/data_applicator.rb +46 -0
- data/lib/aws-sdk-core/stubbing/empty_stub.rb +53 -0
- data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +49 -0
- data/lib/aws-sdk-core/stubbing/protocols/json.rb +40 -0
- data/lib/aws-sdk-core/stubbing/protocols/query.rb +40 -0
- data/lib/aws-sdk-core/stubbing/protocols/rest.rb +67 -0
- data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +25 -0
- data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +38 -0
- data/lib/aws-sdk-core/stubbing/stub_data.rb +34 -0
- data/lib/aws-sdk-core/version.rb +1 -1
- data/lib/aws-sdk-core/xml/builder.rb +58 -52
- data/lib/aws-sdk-core/xml/default_map.rb +10 -0
- data/lib/aws-sdk-core/xml/doc_builder.rb +86 -0
- data/lib/aws-sdk-core/xml/error_handler.rb +7 -2
- data/lib/aws-sdk-core/xml/parser.rb +4 -4
- data/lib/aws-sdk-core/xml/parser/frame.rb +75 -70
- data/lib/aws-sdk-core/xml/parser/stack.rb +4 -4
- data/lib/seahorse.rb +0 -11
- data/lib/seahorse/client/base.rb +3 -12
- data/lib/seahorse/client/http/request.rb +9 -5
- data/lib/seahorse/client/plugins/endpoint.rb +5 -56
- data/lib/seahorse/client/plugins/restful_bindings.rb +38 -31
- data/lib/seahorse/client/request_context.rb +2 -2
- data/lib/seahorse/client/response.rb +6 -5
- data/lib/seahorse/model/api.rb +18 -61
- data/lib/seahorse/model/operation.rb +24 -54
- data/lib/seahorse/model/shapes.rb +120 -364
- data/lib/seahorse/util.rb +2 -6
- metadata +56 -109
- data/apis/autoscaling/2011-01-01/docs-2.json +0 -1246
- data/apis/cloudformation/2010-05-15/docs-2.json +0 -725
- data/apis/cloudfront/2014-11-06/docs-2.json +0 -1125
- data/apis/cloudhsm/2014-05-30/docs-2.json +0 -472
- data/apis/cloudsearch/2013-01-01/docs-2.json +0 -865
- data/apis/cloudsearchdomain/2013-01-01/docs-2.json +0 -311
- data/apis/cloudtrail/2013-11-01/docs-2.json +0 -328
- data/apis/codedeploy/2014-10-06/docs-2.json +0 -1261
- data/apis/cognito-identity/2014-06-30/docs-2.json +0 -506
- data/apis/cognito-sync/2014-06-30/docs-2.json +0 -582
- data/apis/config/2014-10-17/docs-2.json +0 -513
- data/apis/config/2014-11-12/docs-2.json +0 -514
- data/apis/datapipeline/2012-10-29/docs-2.json +0 -607
- data/apis/directconnect/2012-10-25/docs-2.json +0 -494
- data/apis/ds/2015-04-16/docs-2.json +0 -753
- data/apis/dynamodb/2011-12-05/api-2.json +0 -949
- data/apis/dynamodb/2011-12-05/docs-2.json +0 -606
- data/apis/dynamodb/2011-12-05/paginators-1.json +0 -26
- data/apis/dynamodb/2011-12-05/waiters-2.json +0 -35
- data/apis/dynamodb/2012-08-10/docs-2.json +0 -977
- data/apis/ec2/2015-04-15/docs-2.json +0 -5368
- data/apis/ecs/2014-11-13/docs-2.json +0 -791
- data/apis/elasticache/2015-02-02/docs-2.json +0 -1390
- data/apis/elasticbeanstalk/2010-12-01/docs-2.json +0 -1114
- data/apis/elasticfilesystem/2015-02-01/docs-2.json +0 -414
- data/apis/elasticloadbalancing/2012-06-01/docs-2.json +0 -1078
- data/apis/elasticmapreduce/2009-03-31/docs-2.json +0 -969
- data/apis/elastictranscoder/2012-09-25/docs-2.json +0 -1152
- data/apis/email/2010-12-01/docs-2.json +0 -441
- data/apis/glacier/2012-06-01/docs-2.json +0 -575
- data/apis/iam/2010-05-08/docs-2.json +0 -2138
- data/apis/importexport/2010-06-01/docs-2.json +0 -432
- data/apis/kinesis/2013-12-02/docs-2.json +0 -424
- data/apis/kms/2014-11-01/docs-2.json +0 -628
- data/apis/lambda/2014-11-11/docs-2.json +0 -303
- data/apis/lambda/2015-03-31/docs-2.json +0 -490
- data/apis/logs/2014-03-28/docs-2.json +0 -599
- data/apis/machinelearning/2014-12-12/docs-2.json +0 -1034
- data/apis/monitoring/2010-08-01/docs-2.json +0 -514
- data/apis/opsworks/2013-02-18/docs-2.json +0 -1592
- data/apis/rds/2014-10-31/docs-2.json +0 -2074
- data/apis/redshift/2012-12-01/docs-2.json +0 -1890
- data/apis/route53/2013-04-01/docs-2.json +0 -1159
- data/apis/route53domains/2014-05-15/docs-2.json +0 -620
- data/apis/s3/2006-03-01/docs-2.json +0 -2213
- data/apis/sdb/2009-04-15/docs-2.json +0 -339
- data/apis/sns/2010-03-31/docs-2.json +0 -564
- data/apis/sqs/2012-11-05/docs-2.json +0 -503
- data/apis/ssm/2014-11-06/docs-2.json +0 -440
- data/apis/storagegateway/2013-06-30/docs-2.json +0 -1331
- data/apis/sts/2011-06-15/docs-2.json +0 -351
- data/apis/support/2013-04-15/docs-2.json +0 -680
- data/apis/swf/2012-01-25/docs-2.json +0 -1569
- data/apis/workspaces/2015-04-08/docs-2.json +0 -457
- data/lib/aws-sdk-core/api/customizer.rb +0 -75
- data/lib/aws-sdk-core/api/docstrings.rb +0 -38
- data/lib/aws-sdk-core/api/documenter.rb +0 -241
- data/lib/aws-sdk-core/api/operation_documenter.rb +0 -173
- data/lib/aws-sdk-core/api/operation_example.rb +0 -133
- data/lib/aws-sdk-core/api/service_customizations.rb +0 -140
- data/lib/aws-sdk-core/client_paging.rb +0 -31
- data/lib/aws-sdk-core/json/rest_handler.rb +0 -20
- data/lib/aws-sdk-core/json/rpc_body_handler.rb +0 -38
- data/lib/aws-sdk-core/json/rpc_headers_handler.rb +0 -34
- data/lib/aws-sdk-core/json/simple_body_handler.rb +0 -34
- data/lib/aws-sdk-core/paging/null_pager.rb +0 -20
- data/lib/aws-sdk-core/paging/null_provider.rb +0 -13
- data/lib/aws-sdk-core/paging/pager.rb +0 -70
- data/lib/aws-sdk-core/paging/provider.rb +0 -22
- data/lib/aws-sdk-core/rest_body_handler.rb +0 -111
- data/lib/aws-sdk-core/signers/handler.rb +0 -18
- data/lib/aws-sdk-core/xml/rest_handler.rb +0 -20
- data/lib/seahorse/client/param_converter.rb +0 -207
- data/lib/seahorse/client/param_validator.rb +0 -139
- data/lib/seahorse/client/plugins/json_simple.rb +0 -33
- data/lib/seahorse/client/plugins/param_conversion.rb +0 -29
- data/lib/seahorse/client/plugins/param_validation.rb +0 -30
- data/lib/seahorse/client/xml/builder.rb +0 -91
- data/lib/seahorse/model/shape_map.rb +0 -47
@@ -27,9 +27,9 @@ module Aws
|
|
27
27
|
).sign(context.http_request)
|
28
28
|
end
|
29
29
|
|
30
|
-
# @param [
|
30
|
+
# @param [CredentialProvider] credentials
|
31
31
|
def initialize(credentials, params, force_path_style)
|
32
|
-
@credentials = credentials
|
32
|
+
@credentials = credentials.credentials
|
33
33
|
@params = Query::ParamList.new
|
34
34
|
params.each_pair do |param_name, param_value|
|
35
35
|
@params.set(param_name, param_value)
|
@@ -51,7 +51,6 @@ module Aws
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def signature(request)
|
54
|
-
secret = credentials.secret_access_key
|
55
54
|
string_to_sign = string_to_sign(request)
|
56
55
|
signature = digest(credentials.secret_access_key, string_to_sign)
|
57
56
|
URI.escape(signature)
|
@@ -25,14 +25,13 @@ module Aws
|
|
25
25
|
def string_to_sign(http_request, params)
|
26
26
|
[
|
27
27
|
http_request.http_method,
|
28
|
-
host(http_request),
|
29
|
-
http_request.endpoint
|
28
|
+
host(http_request.endpoint),
|
29
|
+
path(http_request.endpoint),
|
30
30
|
params.to_s,
|
31
31
|
].join("\n")
|
32
32
|
end
|
33
33
|
|
34
|
-
def host(
|
35
|
-
endpoint = http_request.endpoint
|
34
|
+
def host(endpoint)
|
36
35
|
host = endpoint.host.downcase
|
37
36
|
if
|
38
37
|
(endpoint.scheme == 'http' && endpoint.port != 80) ||
|
@@ -43,6 +42,10 @@ module Aws
|
|
43
42
|
host
|
44
43
|
end
|
45
44
|
|
45
|
+
def path(endpoint)
|
46
|
+
endpoint.path == '' ? '/' : endpoint.path
|
47
|
+
end
|
48
|
+
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
@@ -21,7 +21,7 @@ module Aws
|
|
21
21
|
# will be made to.
|
22
22
|
def initialize(credentials, service_name, region)
|
23
23
|
@service_name = service_name
|
24
|
-
@credentials = credentials
|
24
|
+
@credentials = credentials.credentials
|
25
25
|
@region = region
|
26
26
|
end
|
27
27
|
|
@@ -32,8 +32,8 @@ module Aws
|
|
32
32
|
body_digest = req.headers['X-Amz-Content-Sha256'] || hexdigest(req.body)
|
33
33
|
req.headers['X-Amz-Date'] = datetime
|
34
34
|
req.headers['Host'] = req.endpoint.host
|
35
|
-
req.headers['X-Amz-Security-Token'] = credentials.session_token if
|
36
|
-
credentials.session_token
|
35
|
+
req.headers['X-Amz-Security-Token'] = @credentials.session_token if
|
36
|
+
@credentials.session_token
|
37
37
|
req.headers['X-Amz-Content-Sha256'] ||= body_digest
|
38
38
|
req.headers['Authorization'] = authorization(req, datetime, body_digest)
|
39
39
|
req
|
@@ -67,8 +67,8 @@ module Aws
|
|
67
67
|
params.set("X-Amz-Date", now)
|
68
68
|
params.set("X-Amz-Expires", options[:expires_in].to_s)
|
69
69
|
params.set("X-Amz-SignedHeaders", signed_headers(request))
|
70
|
-
params.set('X-Amz-Security-Token', credentials.session_token) if
|
71
|
-
credentials.session_token
|
70
|
+
params.set('X-Amz-Security-Token', @credentials.session_token) if
|
71
|
+
@credentials.session_token
|
72
72
|
|
73
73
|
endpoint = request.endpoint
|
74
74
|
if endpoint.query
|
@@ -88,14 +88,14 @@ module Aws
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def credential(datetime)
|
91
|
-
"#{credentials.access_key_id}/#{credential_scope(datetime)}"
|
91
|
+
"#{@credentials.access_key_id}/#{credential_scope(datetime)}"
|
92
92
|
end
|
93
93
|
|
94
94
|
def signature(request, datetime, body_digest)
|
95
|
-
k_secret = credentials.secret_access_key
|
95
|
+
k_secret = @credentials.secret_access_key
|
96
96
|
k_date = hmac("AWS4" + k_secret, datetime[0,8])
|
97
|
-
k_region = hmac(k_date, region)
|
98
|
-
k_service = hmac(k_region, service_name)
|
97
|
+
k_region = hmac(k_date, @region)
|
98
|
+
k_service = hmac(k_region, @service_name)
|
99
99
|
k_credentials = hmac(k_service, 'aws4_request')
|
100
100
|
hexhmac(k_credentials, string_to_sign(request, datetime, body_digest))
|
101
101
|
end
|
@@ -112,8 +112,8 @@ module Aws
|
|
112
112
|
def credential_scope(datetime)
|
113
113
|
parts = []
|
114
114
|
parts << datetime[0,8]
|
115
|
-
parts << region
|
116
|
-
parts << service_name
|
115
|
+
parts << @region
|
116
|
+
parts << @service_name
|
117
117
|
parts << 'aws4_request'
|
118
118
|
parts.join("/")
|
119
119
|
end
|
@@ -200,17 +200,6 @@ module Aws
|
|
200
200
|
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, value)
|
201
201
|
end
|
202
202
|
|
203
|
-
private
|
204
|
-
|
205
|
-
# @return [Credentials]
|
206
|
-
attr_reader :credentials
|
207
|
-
|
208
|
-
# @return [String]
|
209
|
-
attr_reader :service_name
|
210
|
-
|
211
|
-
# @return [String]
|
212
|
-
attr_reader :region
|
213
|
-
|
214
203
|
end
|
215
204
|
end
|
216
205
|
end
|
@@ -1,56 +1,28 @@
|
|
1
|
-
require 'thread'
|
2
|
-
|
3
1
|
module Aws
|
4
|
-
|
5
|
-
# A utilty class that makes it easier to work with Struct objects.
|
6
|
-
#
|
7
|
-
# ## Construction
|
8
|
-
#
|
9
|
-
# You can construct a Structure with a simple hash.
|
10
|
-
#
|
11
|
-
# person = Structure.new(name: 'John Doe', age: 40)
|
12
|
-
# #=> #<struct name="John Doe", age=40>
|
13
|
-
#
|
14
|
-
# ## Empty Structures
|
15
|
-
#
|
16
|
-
# The stdlib Struct class does not work with empty member lists.
|
17
|
-
# Structure solves this by introducing the EmptyStructure class.
|
18
|
-
#
|
19
|
-
# struct = Structure.new({})
|
20
|
-
# #=> #<struct>
|
21
|
-
#
|
22
|
-
# ## Structure Classes
|
23
|
-
#
|
24
|
-
# In addition to simpler object construction, struct classes are re-used
|
25
|
-
# automatically.
|
26
|
-
#
|
27
|
-
# person1 = Structure.new(name: 'John Doe', age: 40)
|
28
|
-
# person2 = Structure.new(name: 'Jane Doe', age: 40)
|
29
|
-
#
|
30
|
-
# person1.class == person2.class
|
31
|
-
#
|
32
|
-
# ## Hash Conversion
|
33
|
-
#
|
34
|
-
# Calling {#to_h} or {#to_hash} on a Structure object performs a deep
|
35
|
-
# conversion of Structure objects into hashes.
|
36
|
-
#
|
37
|
-
# person = Structure.new(
|
38
|
-
# name: "John",
|
39
|
-
# age: 40,
|
40
|
-
# friend: Structure.new(name: "Jane", age: 40, friend: nil)
|
41
|
-
# )
|
42
|
-
# person.to_h
|
43
|
-
# #=> {:name=>"John", :age=>40, :friend=>{:name=>"Jane", :age=>40}}
|
44
|
-
#
|
2
|
+
# @api private
|
45
3
|
class Structure < Struct
|
46
4
|
|
47
|
-
@@classes = {}
|
48
|
-
@@classes_mutex = Mutex.new
|
49
|
-
|
50
5
|
if Struct.instance_methods.include?(:to_h)
|
51
6
|
alias orig_to_h to_h
|
52
7
|
end
|
53
8
|
|
9
|
+
def initialize(values = {})
|
10
|
+
values.each do |k, v|
|
11
|
+
self[k] = v
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Boolean] Returns `true` if this structure has a value
|
16
|
+
# set for the given member.
|
17
|
+
def key?(member_name)
|
18
|
+
!self[member_name].nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [Boolean] Returns `true` if all of the member values are `nil`.
|
22
|
+
def empty?
|
23
|
+
values.compact == []
|
24
|
+
end
|
25
|
+
|
54
26
|
# Deeply converts the Structure into a hash. Structure members that
|
55
27
|
# are `nil` are omitted from the resultant hash.
|
56
28
|
#
|
@@ -77,109 +49,18 @@ module Aws
|
|
77
49
|
end
|
78
50
|
alias to_hash to_h
|
79
51
|
|
52
|
+
undef_method :each
|
53
|
+
|
80
54
|
class << self
|
81
55
|
|
82
|
-
#
|
83
|
-
# instance of that class with nil member values.
|
84
|
-
#
|
85
|
-
# struct = Structure.new([:name, :age])
|
86
|
-
# struct.members
|
87
|
-
# #=> [:name, :age]
|
88
|
-
#
|
89
|
-
# struct[:name] #=> nil
|
90
|
-
# struct[:age] #=> nil
|
91
|
-
#
|
92
|
-
# You can provide an ordered list of values to initialize structure
|
93
|
-
# members with:
|
94
|
-
#
|
95
|
-
# struct = Structure.new([:name, :age], ['John Doe', 40])
|
96
|
-
# struct.members
|
97
|
-
# #=> [:name, :age]
|
98
|
-
#
|
99
|
-
# struct[:name] #=> 'John Doe'
|
100
|
-
# struct[:age] #=> 40
|
101
|
-
#
|
102
|
-
# Calling {new} multiple times with the same list of members will
|
103
|
-
# reuse Struct classes.
|
104
|
-
#
|
105
|
-
# struct1 = Structure.new([:name, :age])
|
106
|
-
# struct2 = Structure.new([:name, :age])
|
107
|
-
#
|
108
|
-
# struct1.class.equal?(struct2.class)
|
109
|
-
# #=> true
|
110
|
-
#
|
111
|
-
# Calling {new} without members, or with an empty list of members
|
112
|
-
# will return an {EmptyStructure}:
|
113
|
-
#
|
114
|
-
# struct = Structure.new
|
115
|
-
# struct.members
|
116
|
-
# #=> []
|
117
|
-
#
|
118
|
-
# You can also create an empty Structure via {EmptyStructure}.
|
119
|
-
#
|
120
|
-
# @overload new(member_names)
|
121
|
-
# @param [Array<Symbol>] member_names An array of member names.
|
122
|
-
# @return [Struct]
|
123
|
-
#
|
124
|
-
# @overload new(*member_names)
|
125
|
-
# @param [Symbol] member_names A list of member names.
|
126
|
-
# @return [Struct]
|
127
|
-
#
|
128
|
-
# @overload new(members)
|
129
|
-
# @param [Hash<Symbol,Object>] members A hash of member names
|
130
|
-
# and values.
|
131
|
-
# @return [Struct]
|
132
|
-
#
|
133
|
-
# @overload new()
|
134
|
-
# @return [EmptyStructure]
|
135
|
-
#
|
56
|
+
# @api private
|
136
57
|
def new(*args)
|
137
|
-
|
138
|
-
|
139
|
-
|
58
|
+
if args == ['AwsEmptyStructure']
|
59
|
+
super
|
60
|
+
elsif args.empty? || args.first == []
|
61
|
+
EmptyStructure
|
140
62
|
else
|
141
|
-
|
142
|
-
if struct_class.nil?
|
143
|
-
@@classes_mutex.synchronize do
|
144
|
-
struct_class = members.empty? ? super(:_) : super(*members)
|
145
|
-
@@classes[members] = struct_class
|
146
|
-
end
|
147
|
-
end
|
148
|
-
struct_class.new(*values)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
# Deeply converts hashes to Structure objects. Hashes with string
|
153
|
-
# keys are not converted, but their values are.
|
154
|
-
# @api private
|
155
|
-
def from_hash(value)
|
156
|
-
case value
|
157
|
-
when Hash
|
158
|
-
data = value.each.with_object({}) do |(key, value), hash|
|
159
|
-
hash[key] = from_hash(value)
|
160
|
-
end
|
161
|
-
Symbol === data.keys.first ? new(data) : data
|
162
|
-
when Array
|
163
|
-
value.map { |v| from_hash(v) }
|
164
|
-
else value
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
private
|
169
|
-
|
170
|
-
def parse_args(args)
|
171
|
-
case args.count
|
172
|
-
when 0 then [[], []]
|
173
|
-
when 1 then parse_single_arg(args.first)
|
174
|
-
else [args, []]
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def parse_single_arg(arg)
|
179
|
-
case arg
|
180
|
-
when Array then [arg, []]
|
181
|
-
when Hash then [arg.keys, arg.values]
|
182
|
-
else [[arg], []]
|
63
|
+
super(*args)
|
183
64
|
end
|
184
65
|
end
|
185
66
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Aws
|
2
|
+
module Stubbing
|
3
|
+
class DataApplicator
|
4
|
+
|
5
|
+
include Seahorse::Model::Shapes
|
6
|
+
|
7
|
+
# @param [Seahorse::Models::Shapes::ShapeRef] rules
|
8
|
+
def initialize(rules)
|
9
|
+
@rules = rules
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param [Hash] data
|
13
|
+
# @param [Structure] stub
|
14
|
+
def apply_data(data, stub)
|
15
|
+
apply_data_to_struct(@rules, data, stub)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def apply_data_to_struct(ref, data, struct)
|
21
|
+
data.each do |key, value|
|
22
|
+
struct[key] = member_value(ref.shape.member(key), value)
|
23
|
+
end
|
24
|
+
struct
|
25
|
+
end
|
26
|
+
|
27
|
+
def member_value(ref, value)
|
28
|
+
case ref.shape
|
29
|
+
when StructureShape
|
30
|
+
apply_data_to_struct(ref, value, ref[:struct_class].new)
|
31
|
+
when ListShape
|
32
|
+
value.inject([]) do |list, v|
|
33
|
+
list << member_value(ref.shape.member, v)
|
34
|
+
end
|
35
|
+
when MapShape
|
36
|
+
value.inject({}) do |map, (k,v)|
|
37
|
+
map[k.to_s] = member_value(ref.shape.value, v)
|
38
|
+
map
|
39
|
+
end
|
40
|
+
else
|
41
|
+
value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Aws
|
2
|
+
module Stubbing
|
3
|
+
class EmptyStub
|
4
|
+
|
5
|
+
include Seahorse::Model::Shapes
|
6
|
+
|
7
|
+
# @param [Seahorse::Models::Shapes::ShapeRef] rules
|
8
|
+
def initialize(rules)
|
9
|
+
@rules = rules
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Structure]
|
13
|
+
def stub
|
14
|
+
stub_ref(@rules)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def stub_ref(ref, visited = [])
|
20
|
+
if visited.include?(ref.shape)
|
21
|
+
return nil
|
22
|
+
else
|
23
|
+
visited = visited + [ref.shape]
|
24
|
+
end
|
25
|
+
case ref.shape
|
26
|
+
when StructureShape then stub_structure(ref, visited)
|
27
|
+
when ListShape then []
|
28
|
+
when MapShape then {}
|
29
|
+
else stub_scalar(ref)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def stub_structure(ref, visited)
|
34
|
+
ref.shape.members.inject(ref[:struct_class].new) do |struct, (mname, mref)|
|
35
|
+
struct[mname] = stub_ref(mref, visited)
|
36
|
+
struct
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def stub_scalar(ref)
|
41
|
+
case ref.shape
|
42
|
+
when StringShape then ref.shape.name || 'string'
|
43
|
+
when IntegerShape then 0
|
44
|
+
when FloatShape then 0.0
|
45
|
+
when BooleanShape then false
|
46
|
+
when TimestampShape then Time.now
|
47
|
+
else nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Aws
|
2
|
+
module Stubbing
|
3
|
+
module Protocols
|
4
|
+
class EC2
|
5
|
+
|
6
|
+
def stub_data(api, operation, data)
|
7
|
+
resp = Seahorse::Client::Http::Response.new
|
8
|
+
resp.status_code = 200
|
9
|
+
resp.body = build_body(api, operation, data)
|
10
|
+
resp.headers['Content-Length'] = resp.body.size
|
11
|
+
resp.headers['Content-Type'] = 'text/xml;charset=UTF-8'
|
12
|
+
resp.headers['Server'] = 'AmazonEC2'
|
13
|
+
resp
|
14
|
+
end
|
15
|
+
|
16
|
+
def stub_error(error_code)
|
17
|
+
http_resp = Seahorse::Client::Http::Response.new
|
18
|
+
http_resp.status_code = 400
|
19
|
+
http_resp.body = <<-XML.strip
|
20
|
+
<ErrorResponse>
|
21
|
+
<Error>
|
22
|
+
<Code>#{error_code}</Code>
|
23
|
+
<Message>stubbed-response-error-message</Message>
|
24
|
+
</Error>
|
25
|
+
</ErrorResponse>
|
26
|
+
XML
|
27
|
+
http_resp
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def build_body(api, operation, data)
|
33
|
+
xml = []
|
34
|
+
if rules = operation.output
|
35
|
+
Xml::Builder.new(operation.output, target:xml).to_xml(data)
|
36
|
+
xml.shift
|
37
|
+
xml.pop
|
38
|
+
end
|
39
|
+
xmlns = "http://ec2.amazonaws.com/doc/#{api.version}/".inspect
|
40
|
+
xml.unshift(" <requestId>stubbed-request-id</requestId>")
|
41
|
+
xml.unshift("<#{operation.name}Response xmlns=#{xmlns}>\n")
|
42
|
+
xml.push("</#{operation.name}Response>\n")
|
43
|
+
xml.join
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|