aws-sdk 1.7.1 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. data/README.rdoc +4 -4
  2. data/lib/aws-sdk.rb +60 -1
  3. data/lib/aws.rb +1 -50
  4. data/lib/aws/api_config/CloudFront-2012-05-05.yml +864 -899
  5. data/lib/aws/api_config/DataPipeline-2012-10-29.yml +422 -0
  6. data/lib/aws/api_config/EC2-2012-07-20.yml +0 -2
  7. data/lib/aws/api_config/Glacier-2012-06-01.yml +622 -0
  8. data/lib/aws/api_config/ImportExport-2010-06-01.yml +109 -0
  9. data/lib/aws/api_config/{SQS-2011-10-01.yml → SQS-2012-11-05.yml} +3 -1
  10. data/lib/aws/api_config/StorageGateway-2012-06-30.yml +748 -0
  11. data/lib/aws/cloud_front.rb +71 -0
  12. data/lib/aws/cloud_front/client.rb +1307 -0
  13. data/lib/aws/cloud_front/config.rb +18 -0
  14. data/lib/aws/cloud_front/errors.rb +22 -0
  15. data/lib/aws/cloud_front/request.rb +44 -0
  16. data/lib/aws/core.rb +19 -1
  17. data/lib/aws/core/client.rb +7 -0
  18. data/lib/aws/core/collection.rb +1 -1
  19. data/lib/aws/core/configuration.rb +12 -0
  20. data/lib/aws/core/data.rb +13 -8
  21. data/lib/aws/core/json_client.rb +3 -4
  22. data/lib/aws/core/json_parser.rb +76 -0
  23. data/lib/aws/core/json_request_builder.rb +4 -3
  24. data/lib/aws/core/json_response_parser.rb +1 -3
  25. data/lib/aws/core/managed_file.rb +32 -0
  26. data/lib/aws/core/options/json_serializer.rb +82 -0
  27. data/lib/aws/core/options/validator.rb +5 -1
  28. data/lib/aws/core/options/xml_serializer.rb +18 -4
  29. data/lib/aws/core/{rest_client.rb → rest_json_client.rb} +5 -6
  30. data/lib/aws/core/rest_request_builder.rb +59 -35
  31. data/lib/aws/core/rest_response_parser.rb +13 -4
  32. data/lib/aws/core/rest_xml_client.rb +47 -0
  33. data/lib/aws/core/signature/version_4.rb +22 -8
  34. data/lib/aws/data_pipeline.rb +30 -0
  35. data/lib/aws/data_pipeline/client.rb +392 -0
  36. data/lib/aws/data_pipeline/config.rb +18 -0
  37. data/lib/aws/data_pipeline/errors.rb +20 -0
  38. data/lib/aws/data_pipeline/request.rb +26 -0
  39. data/lib/aws/ec2/instance_collection.rb +11 -3
  40. data/lib/aws/ec2/security_group.rb +5 -5
  41. data/lib/aws/ec2/security_group/{egress_ip_permission_collection.rb → ip_permission_collection.rb} +33 -14
  42. data/lib/aws/glacier.rb +50 -0
  43. data/lib/aws/glacier/archive.rb +54 -0
  44. data/lib/aws/glacier/archive_collection.rb +141 -0
  45. data/lib/aws/glacier/client.rb +286 -0
  46. data/lib/aws/glacier/config.rb +19 -0
  47. data/lib/aws/glacier/errors.rb +22 -0
  48. data/lib/aws/glacier/request.rb +34 -0
  49. data/lib/aws/glacier/resource.rb +30 -0
  50. data/lib/aws/glacier/vault.rb +137 -0
  51. data/lib/aws/glacier/vault_collection.rb +75 -0
  52. data/lib/aws/glacier/vault_notification_configuration.rb +27 -0
  53. data/lib/aws/import_export.rb +71 -0
  54. data/lib/aws/import_export/client.rb +109 -0
  55. data/lib/aws/import_export/config.rb +19 -0
  56. data/lib/aws/import_export/errors.rb +22 -0
  57. data/lib/aws/import_export/request.rb +23 -0
  58. data/lib/aws/route_53/client.rb +1 -1
  59. data/lib/aws/s3/bucket_lifecycle_configuration.rb +160 -63
  60. data/lib/aws/s3/client.rb +43 -0
  61. data/lib/aws/s3/client/xml.rb +6 -0
  62. data/lib/aws/s3/cors_rule_collection.rb +1 -1
  63. data/lib/aws/s3/data_options.rb +1 -3
  64. data/lib/aws/s3/request.rb +1 -1
  65. data/lib/aws/s3/s3_object.rb +52 -10
  66. data/lib/aws/sqs/client.rb +9 -3
  67. data/lib/aws/sqs/queue.rb +44 -5
  68. data/lib/aws/storage_gateway.rb +71 -0
  69. data/lib/aws/storage_gateway/client.rb +472 -0
  70. data/lib/aws/storage_gateway/config.rb +18 -0
  71. data/lib/aws/storage_gateway/errors.rb +22 -0
  72. data/lib/aws/storage_gateway/request.rb +28 -0
  73. data/lib/aws/version.rb +1 -1
  74. metadata +45 -10
  75. data/lib/aws/ec2/security_group/ingress_ip_permission_collection.rb +0 -61
@@ -0,0 +1,32 @@
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
+ # This trival wrapper around File provides an easy way for the client to know when
18
+ # the file that it just streamed over HTTP should be closed after receiving the
19
+ # response. This should only be used internally to track files that we opened.
20
+ # Open files passed into upload methods should be closed by the user.
21
+ # @private
22
+ class ManagedFile < File
23
+
24
+ def self.open path
25
+ file_opts = ['rb']
26
+ file_opts << { :encoding => "BINARY" } if Object.const_defined?(:Encoding)
27
+ super(path.to_s, *file_opts)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,82 @@
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 'json'
15
+ require 'base64'
16
+
17
+ module AWS
18
+ module Core
19
+ module Options
20
+
21
+ # Given a hash of serialization rules, a JSONSerializer can convert
22
+ # a hash of request options into a JSON document. The request options
23
+ # are validated before returning JSON.
24
+ class JSONSerializer
25
+
26
+ # @param [Hash] rules A hash of option rules to validate against.
27
+ # @param [String,nil] payload_param
28
+ def initialize rules, payload_param
29
+ @payload_param = payload_param
30
+ @rules = @payload_param ? rules[@payload_param][:members] : rules
31
+ end
32
+
33
+ # @return [String] Returns the name of the API operation.
34
+ attr_reader :operation_name
35
+
36
+ # @return [String]
37
+ attr_reader :namespace
38
+
39
+ # @return [Hash]
40
+ attr_reader :rules
41
+
42
+ # @overload serialize!(request_options)
43
+ # @param [Hash] request_options A hash of already validated
44
+ # request options with normalized values.
45
+ # @return [String] Returns an string of the request parameters
46
+ # serialized into XML.
47
+ def serialize request_options
48
+ request_options = request_options[@payload_param] if @payload_param
49
+ data = normalize_keys(request_options, rules)
50
+ if rules.any?{|k,v| v[:location] == 'body' }
51
+ data = data.values.first
52
+ end
53
+ JSON.pretty_generate(data)
54
+ end
55
+
56
+ protected
57
+
58
+ def normalize_keys values, rules
59
+ values.inject({}) do |h,(k,v)|
60
+ child_rules = rules[k]
61
+ child_name = child_rules[:name] || Inflection.class_name(k.to_s)
62
+ h.merge(child_name => normalize_value(v, child_rules))
63
+ end
64
+ end
65
+
66
+ def normalize_value value, rules
67
+ case rules[:type]
68
+ when :hash then normalize_keys(value, rules[:members])
69
+ when :array then value.map{|v| normalize_value(v, rules[:members]) }
70
+ when :map
71
+ value.inject({}) do |h,(k,v)|
72
+ h.merge(k => normalize_value(v, rules[:members]))
73
+ end
74
+ when :blob then Base64.encode64(value.read).strip
75
+ else value
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end
82
+ end
@@ -45,7 +45,7 @@ module AWS
45
45
  rules.each_pair do |opt_name, opt_rules|
46
46
  if opt_rules[:required]
47
47
  unless request_options.key?(opt_name)
48
- raise ArgumentError, "missing required option :#{opt_name}"
48
+ raise ArgumentError, "missing required option #{opt_name.inspect}"
49
49
  end
50
50
  end
51
51
  end
@@ -129,6 +129,10 @@ module AWS
129
129
  value.to_s
130
130
  end
131
131
 
132
+ def validate_blob rules, value, opt_name, context = nil
133
+ value
134
+ end
135
+
132
136
  def format_error description, opt_name, context
133
137
  context = context || "option :#{opt_name}"
134
138
  raise ArgumentError, "expected #{description} for #{context}"
@@ -25,10 +25,11 @@ module AWS
25
25
  # @param [String] namespace
26
26
  # @param [String] operation_name
27
27
  # @param [Hash] rules A hash of option rules to validate against.
28
- def initialize namespace, operation_name, rules
28
+ def initialize namespace, operation_name, operation
29
29
  @namespace = namespace
30
30
  @operation_name = operation_name
31
- @rules = rules
31
+ @rules = operation[:inputs]
32
+ @http = operation[:http]
32
33
  @validator = Validator.new(rules)
33
34
  end
34
35
 
@@ -41,6 +42,9 @@ module AWS
41
42
  # @return [Hash]
42
43
  attr_reader :rules
43
44
 
45
+ # @return [Hash,nil]
46
+ attr_reader :http
47
+
44
48
  # @return [Validator]
45
49
  attr_reader :validator
46
50
 
@@ -50,9 +54,19 @@ module AWS
50
54
  # @return [String] Returns an string of the request parameters
51
55
  # serialized into XML.
52
56
  def serialize request_options
57
+ if http && http[:request_payload]
58
+ payload = http[:request_payload]
59
+ root_node_name = rules[payload][:name]
60
+ params = request_options[payload]
61
+ rules = self.rules[payload][:members]
62
+ else
63
+ root_node_name = "#{operation_name}Request"
64
+ params = request_options
65
+ rules = self.rules
66
+ end
53
67
  xml = Nokogiri::XML::Builder.new
54
- xml.send("#{operation_name}Request", :xmlns => namespace) do |xml|
55
- hash_members_xml(request_options, rules, xml)
68
+ xml.send(root_node_name, :xmlns => namespace) do |xml|
69
+ hash_members_xml(params, rules, xml)
56
70
  end
57
71
  xml.doc.root.to_xml
58
72
  end
@@ -13,26 +13,25 @@
13
13
 
14
14
  module AWS
15
15
  module Core
16
- class RESTClient < Core::Client
16
+ class RESTJSONClient < Core::Client
17
17
 
18
18
  protected
19
19
 
20
20
  def self.request_builder_for api_config, operation
21
- RESTRequestBuilder.new(api_config[:namespace], operation)
21
+ Core::RESTRequestBuilder.new(operation, :format => :json)
22
22
  end
23
23
 
24
24
  def self.response_parser_for api_config, operation
25
- RESTResponseParser.new(operation)
25
+ Core::RESTResponseParser.new(operation, :format => :json)
26
26
  end
27
27
 
28
28
  def extract_error_details response
29
29
  if
30
30
  response.http_response.status >= 300 and
31
31
  body = response.http_response.body and
32
- error = errors_module::GRAMMAR.parse(body) and
33
- error[:code]
32
+ json = (::JSON.load(body) rescue nil)
34
33
  then
35
- [error[:code], error[:message]]
34
+ [json['code'], json['message']]
36
35
  end
37
36
  end
38
37
 
@@ -19,43 +19,67 @@ module AWS
19
19
  class RESTRequestBuilder
20
20
 
21
21
  # @private
22
- def initialize namespace, operation
22
+ def initialize operation, options = {}
23
23
 
24
24
  @http = operation[:http]
25
-
26
25
  @rules = operation[:inputs]
27
26
 
28
27
  @validator = Options::Validator.new(@rules)
29
28
 
30
- @xml_serializer = Options::XMLSerializer.new(
31
- namespace, operation[:name], @rules)
29
+ @serializer =
30
+ case options[:format]
31
+ when :xml
32
+ namespace = options[:xmlnamespace]
33
+ name = operation[:name]
34
+ Options::XMLSerializer.new(namespace, name, operation)
35
+ when :json
36
+ Options::JSONSerializer.new(@rules, @http[:request_payload])
37
+ else
38
+ raise ArgumentError, "unhandled format: #{options[:format]}"
39
+ end
32
40
 
33
41
  end
34
42
 
35
- # Populates an http request object with params in the uri, headers,
36
- # and body.
43
+ # Populates a Http::Request with the following:
44
+ #
45
+ # * HTTP method
46
+ # * URI
47
+ # * headers
48
+ # * body
49
+ #
37
50
  # @param [Http::Request] request
38
- # @param [Hash] request_options A hash of options to send with
39
- # the request.
51
+ #
52
+ # @param [Hash] request_options The hash of request options provided
53
+ # to the client request method. This will be used to populate
54
+ # the headers, uri and body.
55
+ #
40
56
  # @raise [ArgumentError] Raises ArgumentError when any of the
41
57
  # request options are invalid (wrong type, missing, unknown, etc).
42
- # @return [Http::Request]
43
- def populate_request request, request_options
58
+ #
59
+ def populate_request request, params
60
+ params = @validator.validate!(params)
61
+ populate_method(request)
62
+ populate_uri(request, params)
63
+ populate_headers(request, params)
64
+ populate_body(request, params)
65
+ end
44
66
 
45
- params = @validator.validate!(request_options)
67
+ protected
46
68
 
69
+ def populate_method request
47
70
  request.http_method = @http[:verb]
71
+ end
72
+
73
+ def populate_uri request, params
48
74
  request.uri = extract_uri(params)
75
+ end
76
+
77
+ def populate_headers request, params
49
78
  extract_headers(params).each_pair do |header_name, header_value|
50
79
  request.headers[header_name] = header_value
51
80
  end
52
- request.body = build_body(params)
53
- request
54
-
55
81
  end
56
82
 
57
- protected
58
-
59
83
  # @param [Hash] params
60
84
  # @return [String]
61
85
  def extract_uri params
@@ -63,15 +87,15 @@ module AWS
63
87
  path, querystring = @http[:uri].split(/\?/)
64
88
 
65
89
  uri = path.gsub(/:\w+/) do |param_name|
66
- unless param = params.delete(param_name[1..-1].to_sym)
67
- msg = "missing required uri argument :#{param_name[1..-1]}"
68
- raise ArgumentError, msg
90
+ if param = params.delete(param_name.sub(/^:/, '').to_sym)
91
+ UriEscape.escape(param)
92
+ else
93
+ raise ArgumentError, "missing required option #{param_name}"
69
94
  end
70
- UriEscape.escape(param)
71
95
  end
72
96
 
73
97
  querystring_parts = []
74
- querystring.to_s.split(/&/).each do |part|
98
+ querystring.to_s.split(/&|;/).each do |part|
75
99
  param_name = part.match(/:(\w+)/)[1]
76
100
  if param = params.delete(param_name.to_sym)
77
101
  param = UriEscape.escape(param)
@@ -91,28 +115,28 @@ module AWS
91
115
  # @return [Hash]
92
116
  def extract_headers params
93
117
  headers = {}
94
- (@http[:request_headers] || {}).each_pair do |param_name,header_name|
95
- if param_value = params.delete(param_name)
96
- headers[header_name] = param_value
97
- end
118
+ (@http[:request_headers] || {}).each_pair do |param,header|
119
+ headers[header] = params[param] if params.key?(param)
98
120
  end
99
121
  headers
100
122
  end
101
123
 
102
124
  # @param [Hash] params
103
125
  # @return [String,nil]
104
- def build_body params
126
+ def populate_body request, params
105
127
  if params.empty?
106
- nil
128
+ request.body = nil
129
+ elsif payload = streaming_param # streaming request
130
+ request.body_stream = params[payload]
131
+ request.headers['Content-Length'] = params[payload].size
107
132
  else
108
- if
109
- payload = @http[:request_payload] and
110
- @rules[payload][:type] != :hash
111
- then
112
- params[payload]
113
- else
114
- @xml_serializer.serialize(params)
115
- end
133
+ request.body = @serializer.serialize(params)
134
+ end
135
+ end
136
+
137
+ def streaming_param
138
+ if payload = @http[:request_payload]
139
+ @rules[payload][:type] == :blob ? payload : nil
116
140
  end
117
141
  end
118
142
 
@@ -19,9 +19,14 @@ module AWS
19
19
  class RESTResponseParser
20
20
 
21
21
  # @private
22
- def initialize operation
22
+ def initialize operation, options
23
23
  @http = operation[:http]
24
- @parser = XML::Parser.new(operation[:outputs])
24
+ @parser =
25
+ case options[:format]
26
+ when :xml then XML::Parser.new(operation[:outputs])
27
+ when :json then Core::JSONParser.new(operation[:outputs])
28
+ else raise "unhandled format: #{options[:format].inspect}"
29
+ end
25
30
  end
26
31
 
27
32
  # Given a response object, this method extract and returns a
@@ -30,18 +35,22 @@ module AWS
30
35
  # @return [Hash]
31
36
  def extract_data response
32
37
 
33
- # parse the response XML body
34
38
  data = @parser.parse(response.http_response.body)
35
39
 
36
40
  # extract headers and insert into response
37
41
  (@http[:response_headers] || {}).each_pair do |name,header_name|
38
- data[name] = response.http_response.headers[header_name]
42
+ header = response.http_response.headers[header_name.downcase]
43
+ data[name] = [header].flatten.first
39
44
  end
40
45
 
41
46
  data
42
47
 
43
48
  end
44
49
 
50
+ def simulate
51
+ {}
52
+ end
53
+
45
54
  end
46
55
 
47
56
  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
+ # @since 1.8.0
17
+ class RESTXMLClient < Core::Client
18
+
19
+ protected
20
+
21
+ def self.request_builder_for api_config, operation
22
+ RESTRequestBuilder.new(operation,
23
+ :format => :xml,
24
+ :xmlnamespace => api_config[:namespace])
25
+ end
26
+
27
+ def self.response_parser_for api_config, operation
28
+ RESTResponseParser.new(operation, :format => :xml)
29
+ end
30
+
31
+ def extract_error_details response
32
+ if
33
+ response.http_response.status >= 300 and
34
+ body = response.http_response.body and
35
+ error = errors_module::GRAMMAR.parse(body) and
36
+ error[:code]
37
+ then
38
+ [error[:code], error[:message]]
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ # @deprecated Use RESTXMLClient instead.
45
+ RESTClient = RESTXMLClient
46
+ end
47
+ end