aws-sdk 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -70,10 +70,11 @@ module AWS
70
70
  options[:"#{self.class.service_ruby_name}_endpoint"] =
71
71
  options.delete(:endpoint)
72
72
  end
73
-
74
- @config = options[:config]
73
+
74
+ options_without_config = options.dup
75
+ @config = options_without_config.delete(:config)
75
76
  @config ||= AWS.config
76
- @config = @config.with(options)
77
+ @config = @config.with(options_without_config)
77
78
  @signer = @config.signer
78
79
  @http_handler = @config.http_handler
79
80
  @stubs = {}
@@ -155,8 +156,8 @@ module AWS
155
156
  def new_request
156
157
  req = self.class::REQUEST_CLASS.new
157
158
  req.http_method = 'POST'
158
- req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
159
- req.add_param 'Timestamp', Time.now.utc.strftime('%Y-%m-%dT%TZ')
159
+ req.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
160
+ req.add_param 'Timestamp', Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
160
161
  req.add_param 'Version', self.class::API_VERSION
161
162
  req
162
163
  end
@@ -221,8 +222,7 @@ module AWS
221
222
  private
222
223
  def make_async_request response
223
224
 
224
- pauses = async_request_with_retries(response,
225
- response.http_request)
225
+ pauses = async_request_with_retries(response, response.http_request)
226
226
 
227
227
  response
228
228
 
@@ -378,12 +378,15 @@ module AWS
378
378
  opts = options.dup
379
379
  opts.delete(:async)
380
380
 
381
- # configure the http request
382
381
  http_request = new_request
382
+
383
+ # configure the http request
383
384
  http_request.host = endpoint
385
+ http_request.proxy_uri = config.proxy_uri
384
386
  http_request.use_ssl = config.use_ssl?
385
387
  http_request.ssl_verify_peer = config.ssl_verify_peer?
386
388
  http_request.ssl_ca_file = config.ssl_ca_file
389
+
387
390
  send("configure_#{name}_request", http_request, opts, &block)
388
391
  http_request.headers["user-agent"] = user_agent_string
389
392
  http_request.add_authorization!(signer)
@@ -81,10 +81,9 @@ module AWS
81
81
 
82
82
  end
83
83
 
84
- def self.included(mod)
84
+ def self.included mod
85
85
  mod.extend ClassMethods
86
- mod.extend Naming unless
87
- mod.respond_to?(:service_ruby_name)
86
+ mod.extend Naming unless mod.respond_to?(:service_ruby_name)
88
87
  end
89
88
 
90
89
  end
@@ -41,7 +41,7 @@ module AWS
41
41
  # sqs.config.max_retries #=> 2
42
42
  #
43
43
  # If you want to change a configuration value for a single instance you
44
- # pass the new configuration value to that objects initializer:
44
+ # pass the new configuration value to that object's initializer:
45
45
  #
46
46
  # AWS::SQS.new(:max_retries => 0)
47
47
  #
@@ -65,6 +65,12 @@ module AWS
65
65
  # messages generated by service requets. A logger needs to respond to
66
66
  # #log and must accept a severity (e.g. :info, :error, etc) and
67
67
  # a string message.
68
+ # @option options [String, URI, nil] :proxy_uri (nil) The URI of the proxy
69
+ # to send service requests through. You can pass a URI object or a
70
+ # URI string:
71
+ #
72
+ # AWS.config(:proxy_uri => 'https://user:password@my.proxy:443/path?query')
73
+ #
68
74
  # @option options [String] :s3_endpoint ('s3.amazonaws.com') The
69
75
  # service endpoint to use when communicating with Amazon S3.
70
76
  # @option [Integer] :s3_multipart_threshold (16777216) When uploading
@@ -14,6 +14,7 @@
14
14
  require 'aws/default_signer'
15
15
  require 'aws/http/httparty_handler'
16
16
  require 'set'
17
+ require 'uri'
17
18
 
18
19
  module AWS
19
20
 
@@ -81,6 +82,7 @@ module AWS
81
82
  :sns_endpoint => 'sns.us-east-1.amazonaws.com',
82
83
  :sqs_endpoint => 'sqs.us-east-1.amazonaws.com',
83
84
  :stub_requests => false,
85
+ :proxy_uri => nil,
84
86
  :use_ssl => true,
85
87
  :user_agent_prefix => nil,
86
88
  :ssl_verify_peer => true,
@@ -259,6 +261,12 @@ module AWS
259
261
  @options[:ssl_ca_file]
260
262
  end
261
263
 
264
+ # @return [URI::HTTP, URI::HTTPS, nil] Returns the URI for the configured
265
+ # proxy if there is one. Defaults to nil.
266
+ def proxy_uri
267
+ @options[:proxy_uri] ? URI.parse(@options[:proxy_uri].to_s) : nil
268
+ end
269
+
262
270
  # @private
263
271
  def inspect
264
272
  "<#{self.class}>"
@@ -16,16 +16,31 @@ require 'openssl'
16
16
 
17
17
  module AWS
18
18
 
19
- # @private
19
+ # Computes signatures using credentials that are stored in memory.
20
20
  class DefaultSigner
21
21
 
22
- attr_reader :access_key_id, :secret_access_key
22
+ # @return [String] The Access Key ID used to sign requests.
23
+ attr_reader :access_key_id
23
24
 
25
+ # @return [String] The Secret Access Key used to sign requests.
26
+ attr_reader :secret_access_key
27
+
28
+ # @param [String] access_key_id The Access Key ID used to sign
29
+ # requests.
30
+ #
31
+ # @param [String] secret_access_key The Secret Access Key used to
32
+ # sign requests.
24
33
  def initialize(access_key_id, secret_access_key)
25
34
  @access_key_id = access_key_id
26
35
  @secret_access_key = secret_access_key
27
36
  end
28
37
 
38
+ # Signs a string using the credentials stored in memory.
39
+ #
40
+ # @param [String] string_to_sign The string to sign.
41
+ #
42
+ # @param [String] digest_method The digest method to use when
43
+ # computing the HMAC digest.
29
44
  def sign(string_to_sign, digest_method = 'sha256')
30
45
  Base64.encode64(
31
46
  OpenSSL::HMAC.digest(
@@ -31,21 +31,23 @@ module AWS
31
31
  REQUEST_CLASS = EC2::Request
32
32
 
33
33
  # @private
34
- CACHEABLE_REQUESTS = Set[:describe_instances,
35
- :describe_instance_attribute,
36
- :describe_images,
37
- :describe_image_attribute,
38
- :describe_volumes,
39
- :describe_security_groups,
40
- :describe_addresses,
41
- :describe_key_pairs,
42
- :describe_regions,
43
- :describe_availability_zones,
44
- :describe_reserved_instances,
45
- :describe_reserved_instances_offerings,
46
- :describe_snapshots,
47
- :describe_snapshot_attribute,
48
- :describe_tags]
34
+ CACHEABLE_REQUESTS = Set[
35
+ :describe_instances,
36
+ :describe_instance_attribute,
37
+ :describe_images,
38
+ :describe_image_attribute,
39
+ :describe_volumes,
40
+ :describe_security_groups,
41
+ :describe_addresses,
42
+ :describe_key_pairs,
43
+ :describe_regions,
44
+ :describe_availability_zones,
45
+ :describe_reserved_instances,
46
+ :describe_reserved_instances_offerings,
47
+ :describe_snapshots,
48
+ :describe_snapshot_attribute,
49
+ :describe_tags
50
+ ]
49
51
 
50
52
  configure_client
51
53
 
@@ -94,6 +94,9 @@ module AWS
94
94
  # [delete_on_termination] True if the Amazon EBS volume is
95
95
  # deleted on instance termination.
96
96
  #
97
+ # @attr_reader [Array<String>] product_codes Returns an array of
98
+ # product codes attached to this instance.
99
+ #
97
100
  # @attr_reader [Symbol] virtualization_type The type of
98
101
  # virtualization of the AMI. Possible values:
99
102
  #
@@ -229,6 +232,30 @@ module AWS
229
232
  end
230
233
  end
231
234
 
235
+ describe_call_attribute :product_codes, :memoize => true do
236
+ translate_output do |list|
237
+ (list || []).collect{|item| item.product_code }
238
+ end
239
+ end
240
+
241
+ # Adds one or more product codes:
242
+ #
243
+ # image.add_product_codes 'ABCXYZ', 'MNOPQR'
244
+ #
245
+ # You can also pass an array of product codes:
246
+ #
247
+ # image.add_product_codes ['ABCXYZ', 'MNOPQR']
248
+ #
249
+ # @param [Array<String>] product_codes
250
+ # @return [nil]
251
+ def add_product_codes *product_codes
252
+ opts = {}
253
+ opts[:image_id] = self.id
254
+ opts[:product_codes] = product_codes.flatten
255
+ client.modify_image_attribute(opts)
256
+ nil
257
+ end
258
+
232
259
  # @private
233
260
  def __permissions_attribute__
234
261
  "launchPermission"
@@ -26,11 +26,9 @@ module AWS
26
26
  def initialize(*args)
27
27
  super
28
28
  @memoized_attributes = {}
29
- if options = args.last and
30
- options.kind_of?(Hash)
29
+ if options = args.last and options.kind_of?(Hash)
31
30
  self.class.memoized_attributes.each do |att|
32
- @memoized_attributes[att] = options[att] if
33
- options.key?(att)
31
+ @memoized_attributes[att] = options[att] if options.key?(att)
34
32
  end
35
33
  end
36
34
  end
@@ -311,10 +309,12 @@ module AWS
311
309
  request_name = Inflection.class_name(name.to_s)
312
310
  request_name = request_name[0,1].downcase + request_name[1..-1]
313
311
 
314
- # define the getter and setter
312
+ # define getter
315
313
  define_method(getter) do
316
314
  retrieve_attribute(getter) { describe_attribute_call(request_name) }
317
315
  end
316
+
317
+ # define setter
318
318
  define_method(setter) do |input_value|
319
319
  set_mutable_attribute(name, input_value)
320
320
  end unless opts[:setter] == false
@@ -85,11 +85,15 @@ module AWS
85
85
  url = request.use_ssl? ?
86
86
  "https://#{request.host}:443#{request.uri}" :
87
87
  "http://#{request.host}#{request.uri}"
88
- puts url
89
88
 
90
89
  curl = Curl::Easy.new(url)
91
90
  curl.headers = request.headers
92
91
 
92
+ if proxy = request.proxy_uri
93
+ curl.proxy_url = proxy.to_s
94
+ curl.proxy_port = proxy.port
95
+ end
96
+
93
97
  curl.on_header {|header_data|
94
98
  name, value = header_data.strip.split(/:\s+/, 2)
95
99
  response.headers[name] = value
@@ -16,9 +16,38 @@ require 'httparty'
16
16
  module AWS
17
17
  module Http
18
18
 
19
- # @private
19
+ # Makes HTTP requests using HTTParty. This is the default
20
+ # handler, so you don't need to do anything special to configure
21
+ # it. However, you can directly instantiate this class in order
22
+ # to send extra options to HTTParty, for example to enable an HTTP
23
+ # proxy:
24
+ #
25
+ # AWS.config(
26
+ # :http_handler => AWS::Http::HTTPartyHandler.new(
27
+ # :http_proxyaddr => "http://myproxy.com",
28
+ # :http_proxyport => 80
29
+ # )
30
+ # )
31
+ #
20
32
  class HTTPartyHandler
21
33
 
34
+ # @return [Hash] The default options to send to HTTParty on each
35
+ # request.
36
+ attr_reader :default_request_options
37
+
38
+ # Constructs a new HTTP handler using HTTParty.
39
+ #
40
+ # @param [Hash] options Default options to send to HTTParty on
41
+ # each request. These options will be sent to +get+, +post+,
42
+ # +head+, +put+, or +delete+ when a request is made. Note
43
+ # that +:body+, +:headers+, +:parser+, and +:ssl_ca_file+ are
44
+ # ignored. If you need to set the CA file, you should use the
45
+ # +:ssl_ca_file+ option to {AWS.config} or
46
+ # {AWS::Configuration} instead.
47
+ def initialize options = {}
48
+ @default_request_options = options
49
+ end
50
+
22
51
  include HTTParty
23
52
 
24
53
  class NoOpParser < HTTParty::Parser
@@ -27,10 +56,15 @@ module AWS
27
56
 
28
57
  def handle(request, response)
29
58
 
30
- opts = {
59
+ opts = default_request_options.merge({
31
60
  :body => request.body,
32
61
  :parser => NoOpParser
33
- }
62
+ })
63
+
64
+ if request.proxy_uri
65
+ opts[:http_proxyaddr] = request.proxy_uri.to_s
66
+ opts[:http_proxyport] = request.proxy_uri.port
67
+ end
34
68
 
35
69
  if request.use_ssl?
36
70
  url = "https://#{request.host}:443#{request.uri}"
@@ -18,7 +18,6 @@ module AWS
18
18
  module Http
19
19
 
20
20
  # Base class for all service reqeusts.
21
- # @private
22
21
  class Request
23
22
 
24
23
  # Returns a new empty http request object.
@@ -51,6 +50,10 @@ module AWS
51
50
  # request
52
51
  attr_accessor :access_key_id
53
52
 
53
+ # @return [nil, URI] The URI to the proxy server requests are
54
+ # sent through if configured. Returns nil if there is no proxy.
55
+ attr_accessor :proxy_uri
56
+
54
57
  # @param [Boolean] ssl If the request should be sent over ssl or not.
55
58
  def use_ssl= use_ssl
56
59
  @use_ssl = use_ssl
@@ -17,6 +17,10 @@ module AWS
17
17
  module Http
18
18
  class Request
19
19
 
20
+ # Represents a single request paramater. Some services accept this
21
+ # in a form encoded body string, others as query parameters.
22
+ # It is up to each service's Request class to determine how to
23
+ # consume these params.
20
24
  # @private
21
25
  class Param
22
26
 
@@ -52,10 +56,13 @@ module AWS
52
56
  end
53
57
  end
54
58
 
59
+ # @private
60
+ protected
55
61
  def escape value
62
+ value = value.encode("UTF-8") if
63
+ value.respond_to?(:encode)
56
64
  CGI::escape(value.to_s).gsub('+', '%20')
57
65
  end
58
- protected :escape
59
66
 
60
67
  end
61
68
  end
@@ -12,19 +12,16 @@
12
12
  # language governing permissions and limitations under the License.
13
13
 
14
14
  module AWS
15
-
16
- # @private
15
+
17
16
  module Http
18
17
 
19
18
  # Represents the http response from a service request.
20
19
  #
21
20
  # Responses have:
22
- #
21
+ #
23
22
  # * status (200, 404, 500, etc)
24
23
  # * headers (hash of response headers)
25
24
  # * body (the response body)
26
- #
27
- # @private
28
25
  class Response
29
26
 
30
27
  # @return [Integer] (200) response http status code
@@ -41,7 +38,7 @@ module AWS
41
38
  attr_accessor :timeout
42
39
  alias_method :timeout?, :timeout
43
40
 
44
- # @param [Hash] options
41
+ # @param [Hash] options
45
42
  # @option options [Integer] :status (200) HTTP status code
46
43
  # @option options [Hash] :headers ({}) HTTP response headers
47
44
  # @option options [String] :body ('') HTTP response body
@@ -19,7 +19,6 @@ module AWS
19
19
  module Naming
20
20
 
21
21
  def service_name
22
- debugger if self.name == nil
23
22
  self.name.split(/::/)[1]
24
23
  end
25
24
 
@@ -17,7 +17,7 @@ require 'date'
17
17
 
18
18
  module AWS
19
19
 
20
- # Represents an access policy for S3 operations and resources. For example:
20
+ # Represents an access policy for AWS operations and resources. For example:
21
21
  #
22
22
  # policy = Policy.new do |policy|
23
23
  # policy.allow(:actions => ['s3:PutObject'],
@@ -17,6 +17,7 @@ module AWS
17
17
 
18
18
  if Object.const_defined?(:Rails) and Rails.const_defined?(:Railtie)
19
19
 
20
+ # @private
20
21
  class Railtie < Rails::Railtie
21
22
 
22
23
  # configure our plugin on boot. other extension points such
@@ -125,17 +126,20 @@ module AWS
125
126
  path = Pathname.new("#{rails_root}/config/aws.yml")
126
127
 
127
128
  if File.exists?(path)
128
- cfg = YAML::load(ERB.new(File.read(path)).result)[rails_env]
129
- AWS.config(cfg)
129
+ cfg = YAML::load(ERB.new(File.read(path)).result)
130
+ unless cfg[rails_env]
131
+ raise "config/aws.yml is missing a section for `#{rails_env}`"
132
+ end
133
+ AWS.config(cfg[rails_env])
130
134
  end
131
135
 
132
136
  end
133
137
 
134
138
  # Adds a delivery method to ActionMailer that uses {AWS::SimplEmailService}.
135
139
  #
136
- # Once you have an SES delivery method you can configure Rails to use this
137
- # for ActionMailer in your environment configuration (e.g.
138
- # RAILS_ROOT/config/environments/production.rb)
140
+ # Once you have an SES delivery method you can configure Rails to
141
+ # use this for ActionMailer in your environment configuration
142
+ # (e.g. RAILS_ROOT/config/environments/production.rb)
139
143
  #
140
144
  # config.action_mailer.delivery_method = :amazon_ses
141
145
  #
@@ -153,21 +157,23 @@ module AWS
153
157
  # AWS.add_action_mailer_delivery_method(:ses, custom_options)
154
158
  #
155
159
  # @param [Hash] options
156
- # @param [Symbol] name (:amazon_ses) The name of the delivery
157
- # method. The name used here should be the same as you set in your
158
- # environment config. If you name the delivery method +:amazon_ses+ then
159
- # you could do something like this in your config/environments/ENV.rb file:
160
- #
160
+ #
161
+ # @param [Symbol] name (:amazon_ses) The name of the delivery
162
+ # method. The name used here should be the same as you set in
163
+ # your environment config. If you name the delivery method
164
+ # +:amazon_ses+ then you could do something like this in your
165
+ # config/environments/ENV.rb file:
166
+ #
161
167
  # config.action_mailer.delivery_method = :amazon_ses
162
168
  #
163
- # @param [Hash] options ({}) A hash of options that are passes to
164
- # {AWS::SimpleEmailService#new} before delivering email.
169
+ # @param [Hash] options A hash of options that are passes to
170
+ # {AWS::SimpleEmailService#new} before delivering email.
165
171
  #
166
- # @return [nil]
172
+ # @return [nil]
167
173
  def self.add_action_mailer_delivery_method name = :amazon_ses, options = {}
168
-
174
+
169
175
  amb = ::ActionMailer::Base
170
-
176
+
171
177
  if ::Rails.version.to_f >= 3
172
178
  amb.add_delivery_method(name, AWS::SimpleEmailService, options)
173
179
  else
@@ -175,11 +181,11 @@ module AWS
175
181
  AWS::SimpleEmailService.new(options).send_raw_email(mail)
176
182
  end
177
183
  end
178
-
184
+
179
185
  nil
180
-
186
+
181
187
  end
182
-
188
+
183
189
  # Configures AWS to log to the Rails defualt logger.
184
190
  # @return [nil]
185
191
  def self.log_to_rails_logger