aws-sdk 1.6.2 → 1.6.3

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.
@@ -14,7 +14,7 @@
14
14
  module AWS
15
15
  module Core
16
16
  module Http
17
-
17
+
18
18
  # Represents the http response from a service request.
19
19
  #
20
20
  # Responses have:
@@ -23,22 +23,26 @@ module AWS
23
23
  # * headers (hash of response headers)
24
24
  # * body (the response body)
25
25
  class Response
26
-
27
- # @return [Integer] (200) response http status code
26
+
27
+ # @return [Integer] Returns the http response status code.
28
28
  attr_accessor :status
29
-
30
- # @return [Hash] ({}) response http headers
29
+
30
+ # @return [Hash] ({}) Returns the HTTP response headers.
31
31
  attr_accessor :headers
32
-
33
- # @return [String] ('') response http body
32
+
33
+ # @return [String,nil] Returns the HTTP response body.
34
34
  attr_accessor :body
35
-
36
- # @return [Boolean] (false) set to true if the client gives up
37
- # before getting a response from the service.
38
- attr_accessor :timeout
39
35
 
40
- alias_method :timeout?, :timeout
41
-
36
+ # @return [Boolean] Returns +true+ if the request could not be made
37
+ # because of a networking issue (including timeouts).
38
+ attr_accessor :network_error
39
+
40
+ alias_method :network_error?, :network_error
41
+
42
+ # The #network_error attribute was previously #timeout, aliasing
43
+ # for backwards compatability
44
+ alias_method :timeout=, :network_error=
45
+
42
46
  # @param [Hash] options
43
47
  # @option options [Integer] :status (200) HTTP status code
44
48
  # @option options [Hash] :headers ({}) HTTP response headers
@@ -46,11 +50,11 @@ module AWS
46
50
  def initialize options = {}, &block
47
51
  @status = options[:status] || 200
48
52
  @headers = options[:headers] || {}
49
- @body = options[:body] || ''
53
+ @body = options[:body]
50
54
  yield(self) if block_given?
51
55
  self
52
56
  end
53
-
57
+
54
58
  # Returns the header value with the given name.
55
59
  #
56
60
  # The value is matched case-insensitively so if the headers hash
@@ -67,7 +71,7 @@ module AWS
67
71
  end
68
72
  nil
69
73
  end
70
-
74
+
71
75
  end
72
76
  end
73
77
  end
@@ -14,7 +14,7 @@
14
14
  module AWS
15
15
  module Core
16
16
 
17
- # A utility class to provide indifferent access to hash data.
17
+ # A utility class to provide indifferent access to hash data.
18
18
  #
19
19
  # Inspired by ActiveSupport's HashWithIndifferentAccess, this class
20
20
  # has a few notable differences:
@@ -26,10 +26,10 @@ module AWS
26
26
  # These features were omitted because our primary use for this class is to
27
27
  # wrap a 1-level hash as a return value, but we want the user to access
28
28
  # the values with string or symbol keys.
29
- #
29
+ #
30
30
  # @private
31
31
  class IndifferentHash < Hash
32
-
32
+
33
33
  def initialize *args
34
34
  if args.first.is_a?(Hash)
35
35
  super()
@@ -38,51 +38,51 @@ module AWS
38
38
  super(*args)
39
39
  end
40
40
  end
41
-
41
+
42
42
  alias_method :_getter, :[]
43
43
  alias_method :_setter, :[]=
44
-
44
+
45
45
  def []=(key, value)
46
46
  _setter(_convert_key(key), value)
47
47
  end
48
48
  alias_method :store, :[]=
49
-
49
+
50
50
  def [] key
51
51
  _getter(_convert_key(key))
52
52
  end
53
-
53
+
54
54
  def merge! hash
55
55
  hash.each_pair do |key,value|
56
- self[key] = value
56
+ self[key] = value
57
57
  end
58
58
  self
59
59
  end
60
60
  alias_method :update, :merge!
61
-
61
+
62
62
  def merge hash
63
63
  self.dup.merge!(hash)
64
64
  end
65
-
65
+
66
66
  def has_key? key
67
67
  super(_convert_key(key))
68
68
  end
69
69
  alias_method :key?, :has_key?
70
70
  alias_method :member?, :has_key?
71
71
  alias_method :include?, :has_key?
72
-
72
+
73
73
  def fetch key, *extras, &block
74
74
  super(_convert_key(key), *extras, &block)
75
75
  end
76
-
76
+
77
77
  def delete key
78
78
  super(_convert_key(key))
79
79
  end
80
-
80
+
81
81
  private
82
82
  def _convert_key key
83
83
  key.is_a?(String) ? key : key.to_s
84
84
  end
85
-
85
+
86
86
  end
87
87
  end
88
88
  end
@@ -93,6 +93,7 @@ module AWS
93
93
  parser.request_params(options).each do |param|
94
94
  request.add_param(param)
95
95
  end
96
+ request.body = request.url_encoded_params
96
97
 
97
98
  end
98
99
 
@@ -16,14 +16,18 @@ module AWS
16
16
 
17
17
  # = Response
18
18
  #
19
- # Each service request returns a response object. Responses provide
20
- # access to response data and request/response metadata.
19
+ # Each Service has a Client class. There is one method per service
20
+ # operation defined on the client. These methods all return a {Response}
21
+ # object.
22
+ #
23
+ # In addition to the response data, these responses provide metadata
24
+ # about the HTTP request made and the HTTP response received.
21
25
  #
22
26
  # == Response Data
23
27
  #
24
- # Each response has a hash of data that represents the data
25
- # returned by the service. You can get at this data by
26
- # calling {#data} (you can also use the {#[]} method as a shortcut)
28
+ # You can access the response data for a client request using the {#data}
29
+ # method or the {#[]} method. Response data is a hash and {#[]} is
30
+ # a shortcut for accessing this hash.
27
31
  #
28
32
  # # make a request to describe one instance
29
33
  # ec2 = AWS::EC2.new
@@ -40,10 +44,10 @@ module AWS
40
44
  # In addition to the response data, there is additional information
41
45
  # available with the response, including:
42
46
  #
43
- # * the name of the client request method called
44
- # * the hash of options passed to the client request
45
- # * the HTTP request object (useful for debugging)
46
- # * the HTTP response object (useful for debugging)
47
+ # * {#request_type} - the name of the client request method
48
+ # * {#request_options} - the hash of options passed to the client method
49
+ # * {#http_request} - The HTTP request made
50
+ # * {#http_response} - the HTTP response received
47
51
  #
48
52
  # Given the example and response object from above:
49
53
  #
@@ -101,7 +105,7 @@ module AWS
101
105
  @data = {}
102
106
  @retry_count = 0
103
107
  @duration = 0
104
- rebuild_request if @request_builder && !http_request
108
+ build_request if @request_builder && !http_request
105
109
  end
106
110
 
107
111
  # Provides access to the response data. This is a short-cut
@@ -130,9 +134,10 @@ module AWS
130
134
  end
131
135
  end
132
136
 
133
- # @return [Boolean] Returns true if the http request timed out.
134
- def timeout?
135
- http_response.timeout?
137
+ # @return [Boolean] Returns +true+ if the http request failed due to
138
+ # a networking issue.
139
+ def network_error?
140
+ http_response.network_error?
136
141
  end
137
142
 
138
143
  # @return [String]
@@ -157,11 +162,24 @@ module AWS
157
162
  # (throttling, server errors, socket errors, etc).
158
163
  # @private
159
164
  def rebuild_request
160
- @http_request = @request_builder.call
165
+ build_request
166
+ @http_request.body_stream.rewind if @http_request.body_stream
167
+ end
168
+
169
+ # @return [Boolean] Returns +false+ if it is not safe to retry a
170
+ # request. This happens when the http request body is an IO
171
+ # object that can not be rewound and re-streamed.
172
+ def safe_to_retry?
173
+ @http_request.body_stream.nil? or
174
+ @http_request.body_stream.respond_to?(:rewind)
161
175
  end
162
176
 
163
177
  protected
164
178
 
179
+ def build_request
180
+ @http_request = @request_builder.call
181
+ end
182
+
165
183
  # @note The prefered method to get as response data is to use {#[]}.
166
184
  #
167
185
  # This provides a backwards-compat layer to the old response objects
@@ -24,6 +24,7 @@ module AWS
24
24
  add_param('SignatureVersion', '2')
25
25
  add_param('SignatureMethod', 'HmacSHA256')
26
26
  add_param('Signature', signature(credentials))
27
+ self.body = url_encoded_params
27
28
  end
28
29
 
29
30
  protected
@@ -19,7 +19,7 @@ module AWS
19
19
  module Core
20
20
  module Signature
21
21
  module Version4
22
-
22
+
23
23
  def self.included base
24
24
  base.send(:include, Signer)
25
25
  end
@@ -29,13 +29,13 @@ module AWS
29
29
  headers['content-type'] ||= 'application/x-www-form-urlencoded'
30
30
  headers['host'] = host
31
31
  headers['x-amz-date'] = datetime
32
- headers['x-amz-security-token'] = credentials.session_token if
32
+ headers['x-amz-security-token'] = credentials.session_token if
33
33
  credentials.session_token
34
34
  headers['authorization'] = authorization(credentials, datetime)
35
35
  end
36
-
36
+
37
37
  protected
38
-
38
+
39
39
  def authorization credentials, datetime
40
40
  parts = []
41
41
  parts << "AWS4-HMAC-SHA256 Credential=#{credentials.access_key_id}/#{credential_string(datetime)}"
@@ -43,7 +43,7 @@ module AWS
43
43
  parts << "Signature=#{hex16(signature(credentials, datetime))}"
44
44
  parts.join(', ')
45
45
  end
46
-
46
+
47
47
  def signature credentials, datetime
48
48
  k_secret = credentials.secret_access_key
49
49
  k_date = hmac("AWS4" + k_secret, datetime[0,8])
@@ -52,7 +52,7 @@ module AWS
52
52
  k_credentials = hmac(k_service, 'aws4_request')
53
53
  hmac(k_credentials, string_to_sign(datetime))
54
54
  end
55
-
55
+
56
56
  def string_to_sign datetime
57
57
  parts = []
58
58
  parts << 'AWS4-HMAC-SHA256'
@@ -61,8 +61,8 @@ module AWS
61
61
  parts << hex16(hash(canonical_request))
62
62
  parts.join("\n")
63
63
  end
64
-
65
- def credential_string datetime
64
+
65
+ def credential_string datetime
66
66
  parts = []
67
67
  parts << datetime[0,8]
68
68
  parts << region
@@ -70,7 +70,7 @@ module AWS
70
70
  parts << 'aws4_request'
71
71
  parts.join("/")
72
72
  end
73
-
73
+
74
74
  def canonical_request
75
75
  parts = []
76
76
  parts << http_method
@@ -81,18 +81,18 @@ module AWS
81
81
  parts << hex16(hash(body || ''))
82
82
  parts.join("\n")
83
83
  end
84
-
84
+
85
85
  def service
86
86
  # this method is implemented in the request class for each service
87
87
  raise NotImplementedError
88
88
  end
89
-
89
+
90
90
  def signed_headers
91
91
  to_sign = headers.keys.map{|k| k.to_s.downcase }
92
92
  to_sign.delete('authorization')
93
93
  to_sign.sort.join(";")
94
94
  end
95
-
95
+
96
96
  def canonical_headers
97
97
  headers = []
98
98
  self.headers.each_pair do |k,v|
@@ -101,20 +101,20 @@ module AWS
101
101
  headers = headers.sort_by(&:first)
102
102
  headers.map{|k,v| "#{k}:#{canonical_header_values(v)}" }.join("\n")
103
103
  end
104
-
104
+
105
105
  def canonical_header_values values
106
106
  values = [values] unless values.is_a?(Array)
107
107
  values.map(&:to_s).map(&:strip).join(',')
108
108
  end
109
-
109
+
110
110
  def hex16 string
111
111
  string.unpack('H*').first
112
112
  end
113
-
113
+
114
114
  def hash string
115
115
  Digest::SHA256.digest(string)
116
116
  end
117
-
117
+
118
118
  end
119
119
  end
120
120
  end
@@ -761,7 +761,7 @@ module AWS
761
761
  end
762
762
  end
763
763
 
764
- def should_retry? response
764
+ def retryable_error? response
765
765
  if response.error.is_a?(Errors::ProvisionedThroughputExceededException)
766
766
  config.dynamo_db_retry_throughput_errors?
767
767
  else
@@ -771,7 +771,7 @@ module AWS
771
771
 
772
772
  def sleep_durations response
773
773
 
774
- retry_count =
774
+ retry_count =
775
775
  if expired_credentials?(response)
776
776
  config.max_retries == 0 ? 0 : 1
777
777
  else
@@ -13,20 +13,14 @@
13
13
 
14
14
  module AWS
15
15
  class DynamoDB
16
-
17
16
  # @private
18
17
  class Request < Core::Http::Request
19
-
20
18
  include Core::Signature::Version4
21
19
 
22
20
  def service
23
21
  'dynamodb'
24
22
  end
25
23
 
26
- # @return [String,nil]
27
- attr_accessor :body
28
-
29
24
  end
30
-
31
25
  end
32
26
  end
@@ -43,7 +43,7 @@ module AWS
43
43
 
44
44
  @groups = Array(options[:groups])
45
45
 
46
- @egress = options[:egress]
46
+ @egress = options[:egress] || false
47
47
 
48
48
  # not all egress permissions require port ranges, depends on the
49
49
  # protocol
@@ -72,6 +72,9 @@ module AWS
72
72
  # granted access with this permission.
73
73
  attr_reader :groups
74
74
 
75
+ # @return [Boolean] True if this is an egress permission
76
+ attr_reader :egress
77
+
75
78
  # @return [Boolean] Returns true if this is an egress permission.
76
79
  def egress?
77
80
  @egress ? true : false
@@ -35,7 +35,7 @@ module AWS
35
35
  # for rails 2 and bundler for rails 3) then {setup} is called
36
36
  # automatically.
37
37
  module Rails
38
-
38
+
39
39
  # Adds extra functionality to Rails.
40
40
  #
41
41
  # Normailly this method is invoked automatically when you require this
@@ -56,13 +56,13 @@ module AWS
56
56
  log_to_rails_logger
57
57
  nil
58
58
  end
59
-
59
+
60
60
  # Loads AWS configuration options from +RAILS_ROOT/config/aws.yml+.
61
61
  #
62
62
  # This configuration file is optional. You can omit this file and instead
63
63
  # use ruby to configure AWS inside a configuration initialization script
64
64
  # (e.g. RAILS_ROOT/config/intializers/aws.rb).
65
- #
65
+ #
66
66
  # If you have a yaml configuration file it should be formatted like the
67
67
  # standard +database.yml+ file in a Rails application. This means there
68
68
  # should be one section for Rails environment:
@@ -76,8 +76,8 @@ module AWS
76
76
  # access_key_id: YOUR_ACCESS_KEY_ID
77
77
  # secret_access_key: YOUR_SECRET_ACCESS_KEY
78
78
  # simple_db_consistent_reads: true
79
- #
80
- # You should also consider DRYing up your configuration file using
79
+ #
80
+ # You should also consider DRYing up your configuration file using
81
81
  # YAML references:
82
82
  #
83
83
  # development:
@@ -90,7 +90,7 @@ module AWS
90
90
  # simple_db_consistent_reads: true
91
91
  #
92
92
  # The yaml file will also be ERB parsed so you can use ruby inside of it:
93
- #
93
+ #
94
94
  # development:
95
95
  # access_key_id: YOUR_ACCESS_KEY_ID
96
96
  # secret_access_key: <%= read_secret_from_a_secure_location %>
@@ -101,9 +101,9 @@ module AWS
101
101
  # simple_db_consistent_reads: true
102
102
  #
103
103
  def self.load_yaml_config
104
-
104
+
105
105
  path = Pathname.new("#{rails_root}/config/aws.yml")
106
-
106
+
107
107
  if File.exists?(path)
108
108
  cfg = YAML::load(ERB.new(File.read(path)).result)
109
109
  unless cfg[rails_env]
@@ -111,9 +111,9 @@ module AWS
111
111
  end
112
112
  AWS.config(cfg[rails_env])
113
113
  end
114
-
114
+
115
115
  end
116
-
116
+
117
117
  # Adds a delivery method to ActionMailer that uses
118
118
  # {AWS::SimpleEmailService}.
119
119
  #