aws-sdk 1.5.8 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/aws.rb +2 -0
- data/lib/aws/api_config/Route53-2012-02-29.yml +348 -0
- data/lib/aws/auto_scaling/client.rb +362 -588
- data/lib/aws/cloud_formation/client.rb +155 -224
- data/lib/aws/cloud_watch/client.rb +156 -229
- data/lib/aws/core.rb +67 -52
- data/lib/aws/core/client.rb +81 -82
- data/lib/aws/core/collection/with_limit_and_next_token.rb +2 -2
- data/lib/aws/core/configuration.rb +75 -72
- data/lib/aws/core/http/net_http_handler.rb +3 -3
- data/lib/aws/core/http/request.rb +107 -138
- data/lib/aws/core/inflection.rb +3 -3
- data/lib/aws/core/json_client.rb +106 -0
- data/lib/aws/core/option_grammar.rb +10 -1
- data/lib/aws/core/options/validator.rb +140 -0
- data/lib/aws/core/options/xml_serializer.rb +98 -0
- data/lib/aws/core/query_client.rb +131 -0
- data/lib/aws/core/rest_client.rb +90 -0
- data/lib/aws/core/rest_client/input_handler.rb +145 -0
- data/lib/aws/core/rest_client/output_handler.rb +43 -0
- data/lib/aws/core/signature/version_2.rb +7 -7
- data/lib/aws/core/signature/version_3.rb +5 -1
- data/lib/aws/core/signature/version_3_https.rb +51 -0
- data/lib/aws/core/signature/version_4.rb +5 -22
- data/lib/aws/core/signer.rb +1 -1
- data/lib/aws/core/uri_escape.rb +2 -0
- data/lib/aws/core/xml/frame.rb +8 -8
- data/lib/aws/core/xml/grammar.rb +8 -3
- data/lib/aws/dynamo_db/client.rb +600 -662
- data/lib/aws/ec2/client.rb +2688 -3492
- data/lib/aws/ec2/request.rb +0 -1
- data/lib/aws/elb/client.rb +280 -407
- data/lib/aws/emr/client.rb +7 -7
- data/lib/aws/iam/client.rb +822 -1268
- data/lib/aws/route_53.rb +71 -0
- data/lib/aws/route_53/client.rb +272 -0
- data/lib/aws/route_53/config.rb +18 -0
- data/lib/aws/route_53/errors.rb +22 -0
- data/lib/aws/route_53/request.rb +23 -0
- data/lib/aws/s3/object_version_collection.rb +6 -6
- data/lib/aws/s3/paginated_collection.rb +1 -1
- data/lib/aws/s3/request.rb +10 -5
- data/lib/aws/simple_db/client.rb +184 -234
- data/lib/aws/simple_email_service/client.rb +147 -238
- data/lib/aws/simple_workflow/client.rb +997 -1191
- data/lib/aws/sns/client.rb +176 -264
- data/lib/aws/sqs/client.rb +162 -253
- data/lib/aws/sqs/queue.rb +1 -1
- data/lib/aws/sqs/request.rb +4 -0
- data/lib/aws/sts/client.rb +57 -66
- metadata +95 -71
- data/lib/aws/core/client/query_json.rb +0 -112
- data/lib/aws/core/client/query_xml.rb +0 -122
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright 2011-2012 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 'aws/core/rest_client/input_handler'
|
15
|
+
require 'aws/core/rest_client/output_handler'
|
16
|
+
|
17
|
+
module AWS
|
18
|
+
module Core
|
19
|
+
module RESTClient
|
20
|
+
|
21
|
+
# @private
|
22
|
+
def self.extended base
|
23
|
+
base.send(:include, ErrorParser)
|
24
|
+
base.send(:define_handlers)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @private
|
28
|
+
def input_handlers
|
29
|
+
@input_handlers ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
# @private
|
33
|
+
def output_handlers
|
34
|
+
@output_handlers ||= {}
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
# Enumerates through the operations specified in the API
|
40
|
+
# configuration (yaml configuration file found in lib/api_config/)
|
41
|
+
# and defines a request and a response handler for each operation.
|
42
|
+
def define_handlers
|
43
|
+
namespace = api_config[:namespace]
|
44
|
+
api_config[:operations].each_pair do |method,operation|
|
45
|
+
input_handlers[method] = InputHandler.new(namespace, operation)
|
46
|
+
output_handlers[method] = OutputHandler.new(operation)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def define_client_method method_name, operation_name
|
51
|
+
add_client_request_method(method_name) do
|
52
|
+
|
53
|
+
configure_request do |request, request_options|
|
54
|
+
handler = self.class.input_handlers[method_name]
|
55
|
+
handler.populate_request(request, request_options)
|
56
|
+
end
|
57
|
+
|
58
|
+
process_response do |response|
|
59
|
+
handler = self.class.output_handlers[method_name]
|
60
|
+
response.data = handler.extract_data(response)
|
61
|
+
end
|
62
|
+
|
63
|
+
simulate_response do |response|
|
64
|
+
handler = self.class.output_handlers[method_name]
|
65
|
+
response.data = handler.simulate
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
module ErrorParser
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
def extract_error_details response
|
76
|
+
if
|
77
|
+
response.http_response.status >= 300 and
|
78
|
+
body = response.http_response.body and
|
79
|
+
error = errors_module::GRAMMAR.parse(body) and
|
80
|
+
error[:code]
|
81
|
+
then
|
82
|
+
[error[:code], error[:message]]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# Copyright 2011-2012 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 'builder'
|
15
|
+
|
16
|
+
module AWS
|
17
|
+
module Core
|
18
|
+
module RESTClient
|
19
|
+
|
20
|
+
# Given a hash of request options, a REST::RequestHandler can
|
21
|
+
# populate a Core::Http::Request object.
|
22
|
+
class InputHandler
|
23
|
+
|
24
|
+
# @param [String] namespace
|
25
|
+
# @param [Hash] configuration
|
26
|
+
# @option operation [required,Hash] :http REST traits.
|
27
|
+
# @option operation [required,Hash] :inputs Rules for serializing
|
28
|
+
# request options.
|
29
|
+
# @private
|
30
|
+
def initialize namespace, configuration
|
31
|
+
@namespace = namespace
|
32
|
+
@operation_name = configuration[:name]
|
33
|
+
@http = configuration[:http]
|
34
|
+
@rules = configuration[:inputs]
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [String]
|
38
|
+
attr_reader :namespace
|
39
|
+
|
40
|
+
# @return [String]
|
41
|
+
attr_reader :operation_name
|
42
|
+
|
43
|
+
# @return [Hash] A hash of http rules.
|
44
|
+
attr_reader :http
|
45
|
+
|
46
|
+
# @return [Hash] A hash of rules for where to place request options
|
47
|
+
# in the HTTP request (e.g. uri, querystring, header, body, etc).
|
48
|
+
# Also contains type information for each request option.
|
49
|
+
attr_reader :rules
|
50
|
+
|
51
|
+
# Populates an http request object with params in the uri, headers,
|
52
|
+
# and body.
|
53
|
+
# @param [Http::Request] request
|
54
|
+
# @param [Hash] request_options A hash of options to send with
|
55
|
+
# the request.
|
56
|
+
# @raise [ArgumentError] Raises ArgumentError when any of the
|
57
|
+
# request options are invalid (wrong type, missing, unknown, etc).
|
58
|
+
# @return [Http::Request]
|
59
|
+
def populate_request request, request_options
|
60
|
+
|
61
|
+
params = Options::Validator.new(rules).validate!(request_options)
|
62
|
+
|
63
|
+
request.http_method = http[:verb]
|
64
|
+
request.uri = extract_uri(params)
|
65
|
+
extract_headers(params).each_pair do |header_name, header_value|
|
66
|
+
request.headers[header_name] = header_value
|
67
|
+
end
|
68
|
+
request.body = build_body(params)
|
69
|
+
request
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
# @param [Hash] params
|
76
|
+
# @return [String]
|
77
|
+
def extract_uri params
|
78
|
+
|
79
|
+
path, querystring = http[:uri].split(/\?/)
|
80
|
+
|
81
|
+
uri = path.gsub(/:\w+/) do |param_name|
|
82
|
+
unless param = params.delete(param_name[1..-1].to_sym)
|
83
|
+
msg = "missing required uri argument :#{param_name[1..-1]}"
|
84
|
+
raise ArgumentError, msg
|
85
|
+
end
|
86
|
+
UriEscape.escape(param)
|
87
|
+
end
|
88
|
+
|
89
|
+
querystring_parts = []
|
90
|
+
querystring.to_s.split(/&/).each do |part|
|
91
|
+
param_name = part.match(/:(\w+)/)[1]
|
92
|
+
if param = params.delete(param_name.to_sym)
|
93
|
+
param = UriEscape.escape(param)
|
94
|
+
querystring_parts << part.sub(/:#{param_name}/, param)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
unless querystring_parts.empty?
|
99
|
+
uri << "?#{querystring_parts.join('&')}"
|
100
|
+
end
|
101
|
+
|
102
|
+
uri
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
# @param [Hash] params
|
107
|
+
# @return [Hash]
|
108
|
+
def extract_headers params
|
109
|
+
headers = {}
|
110
|
+
(http[:request_headers] || {}).each_pair do |param_name,header_name|
|
111
|
+
if param_value = params.delete(param_name)
|
112
|
+
headers[header_name] = param_value
|
113
|
+
end
|
114
|
+
end
|
115
|
+
headers
|
116
|
+
end
|
117
|
+
|
118
|
+
# @param [Hash] params
|
119
|
+
# @return [String,nil]
|
120
|
+
def build_body params
|
121
|
+
if params.empty?
|
122
|
+
nil
|
123
|
+
else
|
124
|
+
if
|
125
|
+
payload = http[:request_payload] and
|
126
|
+
rules[payload][:type] != :hash
|
127
|
+
then
|
128
|
+
params[payload]
|
129
|
+
else
|
130
|
+
params_to_xml(params)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# @param [Hash] params
|
136
|
+
# @return [String] Returns xml.
|
137
|
+
def params_to_xml params
|
138
|
+
Options::XMLSerializer.new(namespace, operation_name, rules).serialize(params)
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright 2011-2012 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
|
+
module AWS
|
15
|
+
module Core
|
16
|
+
module RESTClient
|
17
|
+
|
18
|
+
# Given a hash of request options, a REST::RequestHandler can
|
19
|
+
# populate a Core::Http::Request object.
|
20
|
+
class OutputHandler
|
21
|
+
|
22
|
+
# @param [Hash] operation
|
23
|
+
# @option operation [required,Hash] :http REST traits.
|
24
|
+
# @option operation [required,Hash] :outputs XML parsing rules.
|
25
|
+
# @private
|
26
|
+
def initialize operation
|
27
|
+
@http = operation[:http]
|
28
|
+
@parser = XML::Parser.new(operation[:outputs])
|
29
|
+
end
|
30
|
+
|
31
|
+
# Given a response object, this method extract and returns a
|
32
|
+
# hash of response data.
|
33
|
+
# @param [Response] response
|
34
|
+
# @return [Hash]
|
35
|
+
def extract_data response
|
36
|
+
@parser.parse(response.http_response.body)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -16,10 +16,6 @@ module AWS
|
|
16
16
|
module Signature
|
17
17
|
module Version2
|
18
18
|
|
19
|
-
def self.included base
|
20
|
-
base.send(:include, Signer)
|
21
|
-
end
|
22
|
-
|
23
19
|
def add_authorization! credentials
|
24
20
|
add_param('AWSAccessKeyId', credentials.access_key_id)
|
25
21
|
if token = credentials.session_token
|
@@ -27,14 +23,18 @@ module AWS
|
|
27
23
|
end
|
28
24
|
add_param('SignatureVersion', '2')
|
29
25
|
add_param('SignatureMethod', 'HmacSHA256')
|
30
|
-
add_param('Signature',
|
26
|
+
add_param('Signature', signature(credentials))
|
31
27
|
end
|
32
28
|
|
33
29
|
protected
|
34
30
|
|
31
|
+
def signature credentials
|
32
|
+
Signer.sign(credentials.secret_access_key, string_to_sign)
|
33
|
+
end
|
34
|
+
|
35
35
|
def string_to_sign
|
36
36
|
|
37
|
-
host =
|
37
|
+
host =
|
38
38
|
case port
|
39
39
|
when 80, 443 then self.host
|
40
40
|
else "#{self.host}:#{port}"
|
@@ -42,7 +42,7 @@ module AWS
|
|
42
42
|
|
43
43
|
[
|
44
44
|
http_method,
|
45
|
-
host,
|
45
|
+
host.to_s.downcase,
|
46
46
|
path,
|
47
47
|
params.sort.collect { |p| p.encoded }.join('&'),
|
48
48
|
].join("\n")
|
@@ -37,11 +37,15 @@ module AWS
|
|
37
37
|
"AWSAccessKeyId=#{credentials.access_key_id},"+
|
38
38
|
"Algorithm=HmacSHA256,"+
|
39
39
|
"SignedHeaders=#{headers_to_sign.join(';')},"+
|
40
|
-
"Signature=#{
|
40
|
+
"Signature=#{signature(credentials)}"
|
41
41
|
end
|
42
42
|
|
43
43
|
protected
|
44
44
|
|
45
|
+
def signature credentials
|
46
|
+
Signer.sign(credentials.secret_access_key, string_to_sign)
|
47
|
+
end
|
48
|
+
|
45
49
|
def string_to_sign
|
46
50
|
OpenSSL::Digest::SHA256.digest([
|
47
51
|
http_method,
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright 2011-2012 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 'time'
|
15
|
+
|
16
|
+
module AWS
|
17
|
+
module Core
|
18
|
+
module Signature
|
19
|
+
module Version3HTTPS
|
20
|
+
|
21
|
+
def self.included base
|
22
|
+
base.send(:include, Signer)
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_authorization! credentials
|
26
|
+
|
27
|
+
self.access_key_id = credentials.access_key_id
|
28
|
+
|
29
|
+
parts = []
|
30
|
+
parts << "AWS3-HTTPS AWSAccessKeyId=#{access_key_id}"
|
31
|
+
parts << "Algorithm=HmacSHA256"
|
32
|
+
parts << "Signature=#{signature(credentials)}"
|
33
|
+
headers['x-amzn-authorization'] = parts.join(',')
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def signature credentials
|
40
|
+
Signer.sign(credentials.secret_access_key, string_to_sign)
|
41
|
+
end
|
42
|
+
|
43
|
+
def string_to_sign
|
44
|
+
headers['date'] ||= Time.now.rfc822
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -73,12 +73,12 @@ module AWS
|
|
73
73
|
|
74
74
|
def canonical_request
|
75
75
|
parts = []
|
76
|
-
parts <<
|
77
|
-
parts <<
|
78
|
-
parts <<
|
76
|
+
parts << http_method
|
77
|
+
parts << path
|
78
|
+
parts << querystring
|
79
79
|
parts << canonical_headers + "\n"
|
80
80
|
parts << signed_headers
|
81
|
-
parts << hex16(hash(
|
81
|
+
parts << hex16(hash(body || ''))
|
82
82
|
parts.join("\n")
|
83
83
|
end
|
84
84
|
|
@@ -87,22 +87,6 @@ module AWS
|
|
87
87
|
raise NotImplementedError
|
88
88
|
end
|
89
89
|
|
90
|
-
def action_name
|
91
|
-
http_method.to_s.upcase
|
92
|
-
end
|
93
|
-
|
94
|
-
def canonical_uri
|
95
|
-
path
|
96
|
-
end
|
97
|
-
|
98
|
-
def payload
|
99
|
-
body || ''
|
100
|
-
end
|
101
|
-
|
102
|
-
def canonical_querystring
|
103
|
-
http_method.to_s.upcase == 'GET' ? url_encoded_params : ''
|
104
|
-
end
|
105
|
-
|
106
90
|
def signed_headers
|
107
91
|
to_sign = headers.keys.map{|k| k.to_s.downcase }
|
108
92
|
to_sign.delete('authorization')
|
@@ -112,8 +96,7 @@ module AWS
|
|
112
96
|
def canonical_headers
|
113
97
|
headers = []
|
114
98
|
self.headers.each_pair do |k,v|
|
115
|
-
|
116
|
-
headers << header unless header.first == 'authorization'
|
99
|
+
headers << [k,v] unless k == 'authorization'
|
117
100
|
end
|
118
101
|
headers = headers.sort_by(&:first)
|
119
102
|
headers.map{|k,v| "#{k}:#{canonical_header_values(v)}" }.join("\n")
|