aws-sdk 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,14 +37,6 @@ module AWS
37
37
  end
38
38
  end
39
39
 
40
- def canned_acl= acl
41
- if acl.kind_of?(Symbol)
42
- headers["x-amz-acl"] = acl.to_s.gsub("_", "-")
43
- elsif acl
44
- headers["x-amz-acl"] = acl
45
- end
46
- end
47
-
48
40
  def storage_class= storage_class
49
41
  if storage_class.kind_of?(Symbol)
50
42
  headers["x-amz-storage-class"] = storage_class.to_s.upcase
@@ -39,6 +39,7 @@ module AWS
39
39
 
40
40
  include Core::Model
41
41
  include DataOptions
42
+ include ACLOptions
42
43
 
43
44
  # @param [Bucket] bucket The bucket this object belongs to.
44
45
  # @param [String] key The object's key.
@@ -247,7 +248,7 @@ module AWS
247
248
  # headers prefixed with +x-amz-meta+. Each name, value pair
248
249
  # must conform to US-ASCII.
249
250
  #
250
- # @option options [Symbol] :acl (private) A canned access
251
+ # @option options [Symbol,String] :acl (:private) A canned access
251
252
  # control policy. Valid values are:
252
253
  #
253
254
  # * +:private+
@@ -257,6 +258,12 @@ module AWS
257
258
  # * +:bucket_owner_read+
258
259
  # * +:bucket_owner_full_control+
259
260
  #
261
+ # @option options [String] :grant_read
262
+ # @option options [String] :grant_write
263
+ # @option options [String] :grant_read_acp
264
+ # @option options [String] :grant_write_acp
265
+ # @option options [String] :grant_full_control
266
+ #
260
267
  # @option options [Symbol] :storage_class Controls whether
261
268
  # Reduced Redundancy Storage is enabled for the object.
262
269
  # Valid values are +:standard+ (the default) or
@@ -293,11 +300,16 @@ module AWS
293
300
  # enabled, returns the {ObjectVersion} representing the
294
301
  # version that was uploaded. If versioning is disabled,
295
302
  # returns self.
303
+ #
296
304
  def write(options_or_data = nil, options = nil)
297
305
 
298
306
  (data_options, put_options) =
299
307
  compute_put_options(options_or_data, options)
300
308
 
309
+ if acl = put_options[:acl]
310
+ put_options[:acl] = acl.to_s.tr('_', '-')
311
+ end
312
+
301
313
  add_configured_write_options(put_options)
302
314
 
303
315
  if use_multipart?(data_options, put_options)
@@ -747,21 +759,19 @@ module AWS
747
759
 
748
760
  end
749
761
 
750
- # Sets the object's access control list. +acl+ can be:
751
- # * An XML policy as a string (which is passed to S3 uninterpreted)
752
- # * An AccessControlList object
753
- # * Any object that responds to +to_xml+
754
- # * Any Hash that is acceptable as an argument to
755
- # AccessControlList#initialize.
756
- #
757
- # @param (see Bucket#acl=)
762
+ # Sets the objects's ACL (access control list). You can provide an ACL
763
+ # in a number of different formats.
764
+ # @param (see ACLOptions#acl_options)
758
765
  # @return [nil]
759
766
  def acl=(acl)
760
- client.set_object_acl(
761
- :bucket_name => bucket.name,
762
- :key => key,
763
- :acl => acl)
767
+
768
+ client_opts = {}
769
+ client_opts[:bucket_name] = bucket.name
770
+ client_opts[:key] = key
771
+
772
+ client.put_object_acl(acl_options(acl).merge(client_opts))
764
773
  nil
774
+
765
775
  end
766
776
 
767
777
  # @private
@@ -33,8 +33,8 @@ module AWS
33
33
  #
34
34
  # === Options:
35
35
  #
36
- # * +:identity+ - *required* - (String) The name of the identity to be
37
- # removed from the list of verified identities.
36
+ # * +:identity+ - *required* - (String) The identity to be removed from
37
+ # the list of identities for the AWS Account.
38
38
  #
39
39
  # === Response Structure:
40
40
  #
@@ -50,7 +50,7 @@ module AWS
50
50
  # === Options:
51
51
  #
52
52
  # * +:email_address+ - *required* - (String) An email address to be
53
- # removed from the list of verified addreses.
53
+ # removed from the list of verified addresses.
54
54
  #
55
55
  # === Response Structure:
56
56
  #
@@ -60,12 +60,31 @@ module AWS
60
60
  #
61
61
  define_client_method :delete_verified_email_address, 'DeleteVerifiedEmailAddress'
62
62
 
63
+ # Calls the GetIdentityNotificationAttributes API operation.
64
+ # @method get_identity_notification_attributes(options = {})
65
+ #
66
+ # === Options:
67
+ #
68
+ # * +:identities+ - *required* - (Array<String>) A list of one or more
69
+ # identities.
70
+ #
71
+ # === Response Structure:
72
+ #
73
+ # * +:notification_attributes+ - (Hash<String,Hash>)
74
+ # * +:bounce_topic+ - (String)
75
+ # * +:complaint_topic+ - (String)
76
+ # * +:forwarding_enabled+ - (Boolean)
77
+ #
78
+ # @return [Core::Response]
79
+ #
80
+ define_client_method :get_identity_notification_attributes, 'GetIdentityNotificationAttributes'
81
+
63
82
  # Calls the GetIdentityVerificationAttributes API operation.
64
83
  # @method get_identity_verification_attributes(options = {})
65
84
  #
66
85
  # === Options:
67
86
  #
68
- # * +:identities+ - *required* - (Array<String>)
87
+ # * +:identities+ - *required* - (Array<String>) A list of identities.
69
88
  #
70
89
  # === Response Structure:
71
90
  #
@@ -119,11 +138,12 @@ module AWS
119
138
  #
120
139
  # === Options:
121
140
  #
122
- # * +:identity_type+ - (String) The type of the identities listed.
123
- # Possible values are: "EmailAddress", "Domain" or null.
124
- # * +:next_token+ - (String) The token used for retrieving the next set
125
- # of items.
126
- # * +:max_items+ - (Integer) The maximum number of items returned.
141
+ # * +:identity_type+ - (String) The type of the identities to list.
142
+ # Possible values are "EmailAddress" and "Domain". If this parameter is
143
+ # omitted, then all identities will be listed.
144
+ # * +:next_token+ - (String) The token to use for pagination.
145
+ # * +:max_items+ - (Integer) The maximum number of identities per page.
146
+ # Possible values are 1-100 inclusive.
127
147
  #
128
148
  # === Response Structure:
129
149
  #
@@ -231,13 +251,58 @@ module AWS
231
251
  #
232
252
  define_client_method :send_raw_email, 'SendRawEmail'
233
253
 
254
+ # Calls the SetIdentityFeedbackForwardingEnabled API operation.
255
+ # @method set_identity_feedback_forwarding_enabled(options = {})
256
+ #
257
+ # === Options:
258
+ #
259
+ # * +:identity+ - *required* - (String) The identity for which to set
260
+ # feedback notification forwarding. Examples: user@example.com,
261
+ # example.com.
262
+ # * +:forwarding_enabled+ - *required* - (Boolean) Sets whether Amazon
263
+ # SES will forward feedback notifications as email. +true+ specifies
264
+ # that Amazon SES will forward feedback notifications as email, in
265
+ # addition to any Amazon SNS topic publishing otherwise specified.
266
+ # +false+ specifies that Amazon SES will publish feedback notifications
267
+ # only through Amazon SNS. This value can only be set to +false+ when
268
+ # topics are specified for both Bounce and Complaint topic types.
269
+ #
270
+ # === Response Structure:
271
+ #
272
+ # This method returns no response data.
273
+ #
274
+ # @return [Core::Response]
275
+ #
276
+ define_client_method :set_identity_feedback_forwarding_enabled, 'SetIdentityFeedbackForwardingEnabled'
277
+
278
+ # Calls the SetIdentityNotificationTopic API operation.
279
+ # @method set_identity_notification_topic(options = {})
280
+ #
281
+ # === Options:
282
+ #
283
+ # * +:identity+ - *required* - (String) The identity for which the topic
284
+ # will be set. Examples: user@example.com, example.com.
285
+ # * +:notification_type+ - *required* - (String) The type of feedback
286
+ # notifications that will be published to the specified topic.
287
+ # * +:sns_topic+ - (String) The Amazon Resource Name (ARN) of the Amazon
288
+ # Simple Notification Service (Amazon SNS) topic. If the parameter is
289
+ # ommited from the request or a null value is passed, the topic is
290
+ # cleared and publishing is disabled.
291
+ #
292
+ # === Response Structure:
293
+ #
294
+ # This method returns no response data.
295
+ #
296
+ # @return [Core::Response]
297
+ #
298
+ define_client_method :set_identity_notification_topic, 'SetIdentityNotificationTopic'
299
+
234
300
  # Calls the VerifyDomainIdentity API operation.
235
301
  # @method verify_domain_identity(options = {})
236
302
  #
237
303
  # === Options:
238
304
  #
239
- # * +:domain+ - *required* - (String) The name of the domain to be
240
- # verified.
305
+ # * +:domain+ - *required* - (String) The domain to be verified.
241
306
  #
242
307
  # === Response Structure:
243
308
  #
@@ -18,6 +18,14 @@ module AWS
18
18
  #
19
19
  # @attr_reader [String,nil] verification_token
20
20
  #
21
+ # @attr [String] bounce_topic_arn
22
+ #
23
+ # @attr [String] complaint_topic_arn
24
+ #
25
+ # @attr [Boolean] forwarding_enabled When +false+, complaint and bounce
26
+ # notifications will not be forwarded via email. Can only be set to
27
+ # +false+ when there is both a +bounce_topic+ and +complaint_topic+.
28
+ #
21
29
  class Identity < Core::Resource
22
30
 
23
31
  # @private
@@ -34,8 +42,53 @@ module AWS
34
42
 
35
43
  attribute :verification_token, :static => true
36
44
 
37
- populates_from(:get_identity_verification_attributes) do |resp|
38
- resp.data[:verification_attributes][identity]
45
+ mutable_attribute :bounce_topic_arn, :as => :bounce_topic
46
+
47
+ mutable_attribute :complaint_topic_arn, :as => :complaint_topic
48
+
49
+ mutable_attribute :forwarding_enabled
50
+
51
+ alias_method :forwarding_enabled?, :forwarding_enabled
52
+
53
+ provider(:get_identity_verification_attributes) do |provider|
54
+ provider.provides :verification_token
55
+ provider.provides :verification_status
56
+ provider.find{|resp| resp.data[:verification_attributes][identity] }
57
+ end
58
+
59
+ provider(:get_identity_notification_attributes) do |provider|
60
+ provider.provides :bounce_topic_arn
61
+ provider.provides :complaint_topic_arn
62
+ provider.provides :forwarding_enabled
63
+ provider.find{|resp| resp.data[:notification_attributes][identity] }
64
+ end
65
+
66
+ # @param [String,SNS::Topic] topic The topic (ARN string or topic
67
+ # object) that bounce notifications should be published to.
68
+ def bounce_topic= topic
69
+ arn = topic.respond_to?(:arn) ? topic.arn : topic
70
+ self.bounce_topic_arn = arn
71
+ end
72
+
73
+ # @return [SNS::Topic,nil]
74
+ def bounce_topic
75
+ if arn = bounce_topic_arn
76
+ SNS::Topic.new(arn, :config => config)
77
+ end
78
+ end
79
+
80
+ # @param [String,SNS::Topic] topic The topic (ARN string or topic
81
+ # object) that complaint notifications should be published to.
82
+ def complaint_topic= topic
83
+ arn = topic.respond_to?(:arn) ? topic.arn : topic
84
+ self.complaint_topic_arn = arn
85
+ end
86
+
87
+ # @return [SNS::Topic,nil]
88
+ def complaint_topic
89
+ if arn = complaint_topic_arn
90
+ SNS::Topic.new(arn, :config => config)
91
+ end
39
92
  end
40
93
 
41
94
  # @return [Boolean] Returns +true+ if this {Identity} represents an
@@ -80,10 +133,34 @@ module AWS
80
133
  [[:identity, identity]]
81
134
  end
82
135
 
83
- def get_resource attr = nil
136
+ def get_resource attr
84
137
  client_opts = {}
85
138
  client_opts[:identities] = [identity]
86
- client.get_identity_verification_attributes(client_opts)
139
+ if attr.name.to_s.match(/verification/)
140
+ client.get_identity_verification_attributes(client_opts)
141
+ else
142
+ client.get_identity_notification_attributes(client_opts)
143
+ end
144
+ end
145
+
146
+ def update_resource attr, value
147
+ client_opts = {}
148
+ client_opts[:identity] = identity
149
+ case attr.name
150
+ when :bounce_topic_arn
151
+ method = :set_identity_notification_topic
152
+ client_opts[:notification_type] = 'Bounce'
153
+ client_opts[:sns_topic] = value if value
154
+ when :complaint_topic_arn
155
+ method = :set_identity_notification_topic
156
+ client_opts[:notification_type] = 'Complaint'
157
+ client_opts[:sns_topic] = value if value
158
+ when :forwarding_enabled
159
+ method = :set_identity_feedback_forwarding_enabled
160
+ client_opts[:forwarding_enabled] = value
161
+ else raise "unhandled attribute: #{attr.name}"
162
+ end
163
+ client.send(method, client_opts)
87
164
  end
88
165
 
89
166
  end
@@ -14,6 +14,7 @@
14
14
  require 'net/http/connection_pool/session'
15
15
  require 'net/http/connection_pool/connection'
16
16
  require 'thread'
17
+ require 'logger'
17
18
 
18
19
  # @private
19
20
  class Net::HTTP::ConnectionPool
@@ -29,18 +30,26 @@ class Net::HTTP::ConnectionPool
29
30
 
30
31
  # @param [Hash] options
31
32
  #
32
- # @option options [Numeric] :idle_timeout (60) The number of seconds a
33
+ # @option options [Numeric] :http_idle_timeout (60) The number of seconds a
33
34
  # connection is allowed to sit idle before it is closed and removed
34
35
  # from the pool.
35
36
  #
36
- # @option options [Numeric] :open_timeout (15) The number of seconds to
37
+ # @option options [Numeric] :http_open_timeout (15) The number of seconds to
37
38
  # wait when opening a http session before raising a timeout exception.
39
+ #
40
+ # @option options [Boolean] :http_wire_trace (false) When +true+, HTTP
41
+ # debug output will be sent to the +:logger+.
42
+ #
43
+ # @option options [Logger] :logger (Logger.new($stdout)) Where debug out
44
+ # is sent (wire traces).
38
45
  #
39
46
  def initialize options = {}
40
47
  @pool = []
41
48
  @pool_mutex = Mutex.new
42
- @open_timeout = options[:open_timeout] || 15
43
- @idle_timeout = options[:idle_timeout] || 60
49
+ @open_timeout = options[:http_open_timeout] || 15
50
+ @idle_timeout = options[:http_idle_timeout] || 60
51
+ @log_wire_trace = !!options[:http_wire_trace]
52
+ @logger = options[:logger] || Logger.new($stdout)
44
53
  end
45
54
 
46
55
  # @return [Integer]
@@ -49,20 +58,32 @@ class Net::HTTP::ConnectionPool
49
58
  # @return [Integer]
50
59
  attr_accessor :open_timeout
51
60
 
52
- # Requests a http session from the connection pool.
61
+ # @return [Boolean] Returns +true+ when HTTP debug output (wire traces)
62
+ # will be logged.
63
+ attr_reader :log_wire_trace
64
+
65
+ alias_method :log_wire_trace?, :log_wire_trace
66
+
67
+ # @return [Logger] Where debug output is sent.
68
+ attr_reader :logger
69
+
70
+ # Requests a connection object from the connection pool.
53
71
  #
54
- # pool.connection_for('domain.com') do |connection|
72
+ # connection = pool.connection_for('domain.com')
73
+ # connection.request(Net::HTTP::Get.new('/index.html'))
74
+ # connection.request(Net::HTTP::Get.new('/about.html'))
55
75
  #
56
- # # make
76
+ # # same thing in block form
77
+ # pool.connection_for('domain.com') do |connection|
57
78
  # connection.request(Net::HTTP::Get.new('/index.html'))
58
79
  # connection.request(Net::HTTP::Get.new('/about.html'))
59
- #
60
80
  # end
61
81
  #
62
- # The yielded connection object is a thin wrapper around the persistent
63
- # http session object. You generally want to call {Connection#request}
64
- # on the yielded object. When the block is complete the connection
65
- # will be returned to the pool.
82
+ # Because the pool manages HTTP sessions you do not have to
83
+ # worry about closing a connection or returning a connection
84
+ # to the pool. Every time you call request on a connection
85
+ # object, a HTTP session received from the pool and returned after
86
+ # the request is complete.
66
87
  #
67
88
  # @param [String] host
68
89
  #
@@ -76,7 +97,7 @@ class Net::HTTP::ConnectionPool
76
97
  # to +true+.
77
98
  #
78
99
  # @option options [Boolean] :ssl_verify_peer (true) If true, ssl
79
- # connections will verify peer certificates. This should only ever be
100
+ # connections should verify peer certificates. This should only ever be
80
101
  # set false false for debugging purposes.
81
102
  #
82
103
  # @option options [String] :ssl_ca_file Full path to the SSL certificate
@@ -90,8 +111,8 @@ class Net::HTTP::ConnectionPool
90
111
  # the the system default will be used if available.
91
112
  #
92
113
  # @option options [URI::HTTP,String] :proxy_uri (nil) A URI string or
93
- # URI::HTTP for a proxy reqeusts should be made through. You should
94
- # not pass both +:proxy_uri+ with any of the other proxy options.
114
+ # URI::HTTP object to use as a proxy. You should not provide
115
+ # +:proxy_uri+ with any other proxy options.
95
116
  #
96
117
  # :proxy_uri => 'http://user:pass@host.com:80'
97
118
  #
@@ -103,19 +124,19 @@ class Net::HTTP::ConnectionPool
103
124
  #
104
125
  # @option options [String] :proxy_password
105
126
  #
106
- # @yieldparam [Connection] connection
127
+ # @yield [connection]
128
+ #
129
+ # @yieldparam [optional,Connection] connection
107
130
  #
108
- # @return [nil]
131
+ # @return [Connection]
109
132
  #
110
133
  def connection_for host, options = {}, &block
111
134
  connection = Connection.new(self, host, options)
112
- if block_given?
113
- yield(connection)
114
- else
115
- connection
116
- end
135
+ yield(connection) if block_given?
136
+ connection
117
137
  end
118
138
 
139
+ # @private
119
140
  def request connection, *request_args, &block
120
141
 
121
142
  session = nil
@@ -187,7 +208,8 @@ class Net::HTTP::ConnectionPool
187
208
  end
188
209
 
189
210
  if session.nil?
190
- session = Session.for(connection, open_timeout)
211
+ logger = log_wire_trace? ? self.logger : nil
212
+ session = Session.for(connection, open_timeout, logger)
191
213
  end
192
214
 
193
215
  session