aws-sdk 1.6.3 → 1.6.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.
Files changed (73) hide show
  1. data/lib/aws/api_config/AutoScaling-2011-01-01.yml +1 -0
  2. data/lib/aws/api_config/CloudFormation-2010-05-15.yml +1 -0
  3. data/lib/aws/api_config/CloudFront-2012-05-05.yml +2137 -0
  4. data/lib/aws/api_config/CloudWatch-2010-08-01.yml +9 -0
  5. data/lib/aws/api_config/DynamoDB-2011-12-05.yml +616 -0
  6. data/lib/aws/api_config/EC2-2012-07-20.yml +1 -0
  7. data/lib/aws/api_config/ELB-2012-06-01.yml +1 -0
  8. data/lib/aws/api_config/EMR-2009-03-31.yml +1 -0
  9. data/lib/aws/api_config/IAM-2010-05-08.yml +1 -0
  10. data/lib/aws/api_config/Route53-2012-02-29.yml +350 -349
  11. data/lib/aws/api_config/SNS-2010-03-31.yml +1 -0
  12. data/lib/aws/api_config/SQS-2011-10-01.yml +1 -0
  13. data/lib/aws/api_config/STS-2011-06-15.yml +1 -0
  14. data/lib/aws/api_config/SimpleDB-2009-04-15.yml +1 -0
  15. data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +62 -0
  16. data/lib/aws/api_config/SimpleWorkflow-2012-01-25.yml +1637 -0
  17. data/lib/aws/auto_scaling/client.rb +2 -37
  18. data/lib/aws/cloud_formation/client.rb +2 -17
  19. data/lib/aws/cloud_watch/client.rb +2 -15
  20. data/lib/aws/core.rb +24 -4
  21. data/lib/aws/core/client.rb +115 -46
  22. data/lib/aws/core/configuration.rb +6 -0
  23. data/lib/aws/core/credential_providers.rb +1 -0
  24. data/lib/aws/core/http/curb_handler.rb +3 -3
  25. data/lib/aws/core/http/httparty_handler.rb +15 -15
  26. data/lib/aws/core/json_client.rb +19 -77
  27. data/lib/aws/core/json_error_parser.rb +25 -0
  28. data/lib/aws/core/json_request_builder.rb +34 -0
  29. data/lib/aws/core/json_response_parser.rb +81 -0
  30. data/lib/aws/core/log_formatter.rb +25 -25
  31. data/lib/aws/core/option_grammar.rb +123 -115
  32. data/lib/aws/core/options/xml_serializer.rb +13 -9
  33. data/lib/aws/core/query_client.rb +13 -104
  34. data/lib/aws/core/query_error_parser.rb +24 -0
  35. data/lib/aws/core/query_request_builder.rb +47 -0
  36. data/lib/aws/core/query_response_parser.rb +35 -0
  37. data/lib/aws/core/rest_client.rb +13 -62
  38. data/lib/aws/core/rest_error_parser.rb +24 -0
  39. data/lib/aws/core/rest_request_builder.rb +124 -0
  40. data/lib/aws/core/rest_response_parser.rb +48 -0
  41. data/lib/aws/core/xml/parser.rb +2 -2
  42. data/lib/aws/core/xml/root_frame.rb +1 -1
  43. data/lib/aws/dynamo_db.rb +10 -9
  44. data/lib/aws/dynamo_db/binary.rb +35 -0
  45. data/lib/aws/dynamo_db/client.rb +103 -20
  46. data/lib/aws/dynamo_db/config.rb +2 -0
  47. data/lib/aws/dynamo_db/item.rb +3 -0
  48. data/lib/aws/dynamo_db/primary_key_element.rb +2 -1
  49. data/lib/aws/dynamo_db/table.rb +32 -36
  50. data/lib/aws/dynamo_db/table_collection.rb +13 -13
  51. data/lib/aws/dynamo_db/types.rb +34 -9
  52. data/lib/aws/ec2/client.rb +884 -344
  53. data/lib/aws/ec2/filtered_collection.rb +2 -3
  54. data/lib/aws/elb/client.rb +59 -45
  55. data/lib/aws/emr/client.rb +2 -11
  56. data/lib/aws/iam/client.rb +9 -80
  57. data/lib/aws/record/hash_model/attributes.rb +28 -13
  58. data/lib/aws/route_53/client.rb +6 -16
  59. data/lib/aws/s3/client.rb +2 -1
  60. data/lib/aws/s3/encryption_utils.rb +2 -7
  61. data/lib/aws/s3/s3_object.rb +5 -0
  62. data/lib/aws/simple_db/client.rb +2 -14
  63. data/lib/aws/simple_email_service/client.rb +35 -19
  64. data/lib/aws/simple_email_service/identity.rb +49 -10
  65. data/lib/aws/simple_email_service/identity_collection.rb +4 -4
  66. data/lib/aws/simple_workflow/client.rb +2 -38
  67. data/lib/aws/sns/client.rb +2 -19
  68. data/lib/aws/sqs/client.rb +2 -19
  69. data/lib/aws/sqs/errors.rb +5 -5
  70. data/lib/aws/sts/client.rb +2 -6
  71. metadata +14 -5
  72. data/lib/aws/core/rest_client/input_handler.rb +0 -145
  73. data/lib/aws/core/rest_client/output_handler.rb +0 -53
@@ -53,9 +53,9 @@ module AWS
53
53
  xml = []
54
54
  builder = Builder::XmlMarkup.new(:target => xml, :indent => 2)
55
55
  builder.tag!("#{operation_name}Request", :xmlns => namespace) do
56
- request_options.each_pair do |opt_name, opt_value|
57
- to_xml(builder, opt_name, rules[opt_name], opt_value)
58
- end
56
+
57
+ hash_members_xml(request_options, rules, builder)
58
+
59
59
  end
60
60
  xml.join
61
61
  end
@@ -78,12 +78,7 @@ module AWS
78
78
  when Hash
79
79
 
80
80
  builder.tag!(xml_name) do
81
- xml_ordered_members(rules[:members]).each do |member_name|
82
- if value.key?(member_name)
83
- member_value = value[member_name]
84
- to_xml(builder, member_name, rules[:members][member_name], member_value)
85
- end
86
- end
81
+ hash_members_xml(value, rules[:members], builder)
87
82
  end
88
83
 
89
84
  when Array
@@ -97,6 +92,15 @@ module AWS
97
92
 
98
93
  end
99
94
 
95
+ def hash_members_xml hash, rules, builder
96
+ xml_ordered_members(rules).each do |member_name|
97
+ if hash.key?(member_name)
98
+ value = hash[member_name]
99
+ to_xml(builder, member_name, rules[member_name], value)
100
+ end
101
+ end
102
+ end
103
+
100
104
  def xml_ordered_members members
101
105
  members.inject([]) do |list,(member_name, member)|
102
106
  list << [member[:position] || 0, member_name]
@@ -11,120 +11,29 @@
11
11
  # ANY KIND, either express or implied. See the License for the specific
12
12
  # language governing permissions and limitations under the License.
13
13
 
14
- #me Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
15
- #
16
- # Licensed under the Apache License, Version 2.0 (the "License"). You
17
- # may not use this file except in compliance with the License. A copy of
18
- # the License is located at
19
- #
20
- # http://aws.amazon.com/apache2.0/
21
- #
22
- # or in the "license" file accompanying this file. This file is
23
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
24
- # ANY KIND, either express or implied. See the License for the specific
25
- # language governing permissions and limitations under the License.
26
-
27
14
  module AWS
28
15
  module Core
29
-
30
- # When a client class extends this module, its API configuration
31
- # is parsed. For each operation in the API configuration, one
32
- # client method is added.
33
- #
34
- # Clients extending Query all have in common their method
35
- # of serializing request (input) paramters and parsing response
36
- # (output) XML.
37
- #
38
- module QueryClient
39
-
40
- # @private
41
- def self.extended base
42
- base.send(:include, ErrorParser)
43
- base.send(:define_parsers)
44
- end
45
-
46
- # @return [Hash<Symbol,OptionGrammar>] Returns a hash option
47
- # parsers. Hash keys are client method names and hash
48
- # values are {OptionGrammar} objects.
49
- # @private
50
- def option_parsers
51
- @option_parsers ||= {}
52
- end
53
-
54
- # @return [Hash<Symbol,XML::Parser>] Returns a hash of xml
55
- # parsers. Hash keys are client method names and hash
56
- # values are {XML::Parser} objects.
57
- # @private
58
- def xml_parsers
59
- @xml_parsers ||= {}
60
- end
16
+ class QueryClient < Core::Client
61
17
 
62
18
  protected
63
19
 
64
- # Enumerates through the operations specified in the API
65
- # configuration (yaml configuration file found in lib/api_config/)
66
- # and defines one request method per operation.
67
- def define_parsers
68
- api_config[:operations].each do |op|
69
-
70
- method_name = op[:method]
71
-
72
- option_parsers[method_name] = OptionGrammar.customize(op[:inputs])
73
- xml_parsers[method_name] = XML::Parser.new(op[:outputs])
74
-
75
- end
20
+ def self.request_builder_for api_config, operation
21
+ QueryRequestBuilder.new(api_config[:api_version], operation)
76
22
  end
77
23
 
78
- def define_client_method method_name, operation_name
79
- add_client_request_method(method_name) do
80
-
81
- configure_request do |request, options|
82
-
83
- now = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
84
-
85
- request.headers['Content-Type'] =
86
- "application/x-www-form-urlencoded; charset=utf-8"
87
-
88
- request.add_param 'Timestamp', now
89
- request.add_param 'Version', self.class::API_VERSION
90
- request.add_param 'Action', operation_name
91
-
92
- parser = self.class.option_parsers[method_name]
93
- parser.request_params(options).each do |param|
94
- request.add_param(param)
95
- end
96
- request.body = request.url_encoded_params
97
-
98
- end
99
-
100
- process_response do |response|
101
- parser = self.class.xml_parsers[method_name]
102
- response.data = parser.parse(response.http_response.body)
103
- end
104
-
105
- simulate_response do |response|
106
- parser = self.class.xml_parsers[method_name]
107
- response.data = parser.simulate
108
- end
109
-
110
- end
24
+ def self.response_parser_for api_config, operation
25
+ QueryResponseParser.new(operation[:outputs])
111
26
  end
112
27
 
113
- module ErrorParser
114
-
115
- protected
116
-
117
- def extract_error_details response
118
- if
119
- response.http_response.status >= 300 and
120
- body = response.http_response.body and
121
- error = errors_module::GRAMMAR.parse(body) and
122
- error[:code]
123
- then
124
- [error[:code], error[:message]]
125
- end
28
+ def extract_error_details response
29
+ if
30
+ response.http_response.status >= 300 and
31
+ body = response.http_response.body and
32
+ error = errors_module::GRAMMAR.parse(body) and
33
+ error[:code]
34
+ then
35
+ [error[:code], error[:message]]
126
36
  end
127
-
128
37
  end
129
38
 
130
39
  end
@@ -0,0 +1,24 @@
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
+
17
+ # @private
18
+ module QueryErrorParser
19
+
20
+
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,47 @@
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
+
17
+ # @private
18
+ class QueryRequestBuilder
19
+
20
+ def initialize api_version, operation
21
+ @api_version = api_version
22
+ @operation_name = operation[:name]
23
+ @grammar = OptionGrammar.customize(operation[:inputs])
24
+ end
25
+
26
+ def populate_request request, options
27
+
28
+ now = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
29
+
30
+ request.headers['Content-Type'] =
31
+ "application/x-www-form-urlencoded; charset=utf-8"
32
+
33
+ request.add_param 'Timestamp', now
34
+ request.add_param 'Version', @api_version
35
+ request.add_param 'Action', @operation_name
36
+
37
+ @grammar.request_params(options).each do |param|
38
+ request.add_param(param)
39
+ end
40
+ request.body = request.url_encoded_params
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,35 @@
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
+
17
+ # @private
18
+ class QueryResponseParser
19
+
20
+ def initialize parsing_rules
21
+ @parser = XML::Parser.new(parsing_rules)
22
+ end
23
+
24
+ def extract_data response
25
+ @parser.parse(response.http_response.body)
26
+ end
27
+
28
+ def simulate
29
+ @parser.simulate
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -11,78 +11,29 @@
11
11
  # ANY KIND, either express or implied. See the License for the specific
12
12
  # language governing permissions and limitations under the License.
13
13
 
14
- require 'aws/core/rest_client/input_handler'
15
- require 'aws/core/rest_client/output_handler'
16
-
17
14
  module AWS
18
15
  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
16
+ class RESTClient < Core::Client
36
17
 
37
18
  protected
38
19
 
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
20
+ def self.request_builder_for api_config, operation
21
+ RESTRequestBuilder.new(api_config[:namespace], operation)
48
22
  end
49
23
 
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
24
+ def self.response_parser_for api_config, operation
25
+ RESTResponseParser.new(operation)
69
26
  end
70
27
 
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
28
+ def extract_error_details response
29
+ if
30
+ response.http_response.status >= 300 and
31
+ body = response.http_response.body and
32
+ error = errors_module::GRAMMAR.parse(body) and
33
+ error[:code]
34
+ then
35
+ [error[:code], error[:message]]
84
36
  end
85
-
86
37
  end
87
38
 
88
39
  end
@@ -0,0 +1,24 @@
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
+
17
+ # @private
18
+ module RESTErrorParser
19
+
20
+
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,124 @@
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
+
19
+ # Given a hash of request options, a REST::RequestHandler can
20
+ # populate a Core::Http::Request object.
21
+ class RESTRequestBuilder
22
+
23
+ # @private
24
+ def initialize namespace, operation
25
+
26
+ @http = operation[:http]
27
+
28
+ @rules = operation[:inputs]
29
+
30
+ @validator = Options::Validator.new(@rules)
31
+
32
+ @xml_serializer = Options::XMLSerializer.new(
33
+ namespace, operation[:name], @rules)
34
+
35
+ end
36
+
37
+ # Populates an http request object with params in the uri, headers,
38
+ # and body.
39
+ # @param [Http::Request] request
40
+ # @param [Hash] request_options A hash of options to send with
41
+ # the request.
42
+ # @raise [ArgumentError] Raises ArgumentError when any of the
43
+ # request options are invalid (wrong type, missing, unknown, etc).
44
+ # @return [Http::Request]
45
+ def populate_request request, request_options
46
+
47
+ params = @validator.validate!(request_options)
48
+
49
+ request.http_method = @http[:verb]
50
+ request.uri = extract_uri(params)
51
+ extract_headers(params).each_pair do |header_name, header_value|
52
+ request.headers[header_name] = header_value
53
+ end
54
+ request.body = build_body(params)
55
+ request
56
+
57
+ end
58
+
59
+ protected
60
+
61
+ # @param [Hash] params
62
+ # @return [String]
63
+ def extract_uri params
64
+
65
+ path, querystring = @http[:uri].split(/\?/)
66
+
67
+ uri = path.gsub(/:\w+/) do |param_name|
68
+ unless param = params.delete(param_name[1..-1].to_sym)
69
+ msg = "missing required uri argument :#{param_name[1..-1]}"
70
+ raise ArgumentError, msg
71
+ end
72
+ UriEscape.escape(param)
73
+ end
74
+
75
+ querystring_parts = []
76
+ querystring.to_s.split(/&/).each do |part|
77
+ param_name = part.match(/:(\w+)/)[1]
78
+ if param = params.delete(param_name.to_sym)
79
+ param = UriEscape.escape(param)
80
+ querystring_parts << part.sub(/:#{param_name}/, param)
81
+ end
82
+ end
83
+
84
+ unless querystring_parts.empty?
85
+ uri << "?#{querystring_parts.join('&')}"
86
+ end
87
+
88
+ uri
89
+
90
+ end
91
+
92
+ # @param [Hash] params
93
+ # @return [Hash]
94
+ def extract_headers params
95
+ headers = {}
96
+ (@http[:request_headers] || {}).each_pair do |param_name,header_name|
97
+ if param_value = params.delete(param_name)
98
+ headers[header_name] = param_value
99
+ end
100
+ end
101
+ headers
102
+ end
103
+
104
+ # @param [Hash] params
105
+ # @return [String,nil]
106
+ def build_body params
107
+ if params.empty?
108
+ nil
109
+ else
110
+ if
111
+ payload = @http[:request_payload] and
112
+ @rules[payload][:type] != :hash
113
+ then
114
+ params[payload]
115
+ else
116
+ @xml_serializer.serialize(params)
117
+ end
118
+ end
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+ end