aws-sdk 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/aws/core.rb +13 -2
- data/lib/aws/core/autoloader.rb +1 -1
- data/lib/aws/core/client.rb +69 -30
- data/lib/aws/core/configuration.rb +12 -1
- data/lib/aws/core/http/handler.rb +28 -16
- data/lib/aws/core/http/net_http_handler.rb +31 -11
- data/lib/aws/core/http/request.rb +52 -16
- data/lib/aws/core/http/response.rb +20 -16
- data/lib/aws/core/indifferent_hash.rb +14 -14
- data/lib/aws/core/query_client.rb +1 -0
- data/lib/aws/core/response.rb +32 -14
- data/lib/aws/core/signature/version_2.rb +1 -0
- data/lib/aws/core/signature/version_4.rb +16 -16
- data/lib/aws/dynamo_db/client.rb +2 -2
- data/lib/aws/dynamo_db/request.rb +0 -6
- data/lib/aws/ec2/security_group/ip_permission.rb +4 -1
- data/lib/aws/rails.rb +10 -10
- data/lib/aws/s3.rb +44 -29
- data/lib/aws/s3/bucket.rb +171 -6
- data/lib/aws/s3/cipher_io.rb +119 -0
- data/lib/aws/s3/client.rb +75 -45
- data/lib/aws/s3/config.rb +6 -0
- data/lib/aws/s3/data_options.rb +136 -49
- data/lib/aws/s3/encryption_utils.rb +144 -0
- data/lib/aws/s3/errors.rb +14 -0
- data/lib/aws/s3/multipart_upload.rb +7 -4
- data/lib/aws/s3/object_collection.rb +2 -2
- data/lib/aws/s3/policy.rb +1 -1
- data/lib/aws/s3/request.rb +21 -33
- data/lib/aws/s3/s3_object.rb +797 -237
- data/lib/aws/simple_email_service/request.rb +0 -2
- data/lib/aws/simple_workflow/request.rb +0 -3
- data/lib/net/http/connection_pool.rb +63 -75
- data/lib/net/http/connection_pool/connection.rb +69 -15
- data/lib/net/http/connection_pool/session.rb +39 -6
- metadata +4 -2
@@ -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]
|
26
|
+
|
27
|
+
# @return [Integer] Returns the http response status code.
|
28
28
|
attr_accessor :status
|
29
|
-
|
30
|
-
# @return [Hash] ({}) response
|
29
|
+
|
30
|
+
# @return [Hash] ({}) Returns the HTTP response headers.
|
31
31
|
attr_accessor :headers
|
32
|
-
|
33
|
-
# @return [String]
|
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
|
-
|
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
|
data/lib/aws/core/response.rb
CHANGED
@@ -16,14 +16,18 @@ module AWS
|
|
16
16
|
|
17
17
|
# = Response
|
18
18
|
#
|
19
|
-
# Each
|
20
|
-
#
|
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
|
-
#
|
25
|
-
#
|
26
|
-
#
|
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
|
44
|
-
# * the hash of options passed to the client
|
45
|
-
# *
|
46
|
-
# * the HTTP response
|
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
|
-
|
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
|
134
|
-
|
135
|
-
|
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
|
-
|
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
|
@@ -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
|
data/lib/aws/dynamo_db/client.rb
CHANGED
@@ -761,7 +761,7 @@ module AWS
|
|
761
761
|
end
|
762
762
|
end
|
763
763
|
|
764
|
-
def
|
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
|
data/lib/aws/rails.rb
CHANGED
@@ -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
|
#
|