aws-sdk 1.6.5 → 1.6.6
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.
- data/lib/aws/api_config/CloudFormation-2010-05-15.yml +1 -1
- data/lib/aws/api_config/EC2-2012-07-20.yml +283 -9
- data/lib/aws/cloud_formation/client.rb +2 -2
- data/lib/aws/core.rb +1 -1
- data/lib/aws/core/credential_providers.rb +6 -0
- data/lib/aws/core/http/net_http_handler.rb +1 -0
- data/lib/aws/core/inflection.rb +1 -0
- data/lib/aws/core/json_client.rb +1 -1
- data/lib/aws/core/options/xml_serializer.rb +1 -1
- data/lib/aws/core/rest_request_builder.rb +0 -2
- data/lib/aws/dynamo_db/types.rb +1 -1
- data/lib/aws/ec2/client.rb +161 -6
- data/lib/aws/s3.rb +3 -0
- data/lib/aws/s3/bucket.rb +63 -9
- data/lib/aws/s3/bucket_lifecycle_configuration.rb +1 -1
- data/lib/aws/s3/bucket_tag_collection.rb +109 -0
- data/lib/aws/s3/client.rb +167 -6
- data/lib/aws/s3/client/xml.rb +37 -1
- data/lib/aws/s3/config.rb +2 -0
- data/lib/aws/s3/cors_rule.rb +106 -0
- data/lib/aws/s3/cors_rule_collection.rb +192 -0
- data/lib/aws/s3/request.rb +1 -1
- data/lib/aws/s3/s3_object.rb +3 -1
- metadata +84 -70
- data/lib/user.rb +0 -49
@@ -0,0 +1,109 @@
|
|
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
|
+
class S3
|
16
|
+
|
17
|
+
# Manages tags for a single S3 {Bucket}.
|
18
|
+
#
|
19
|
+
# @example Setting a tag.
|
20
|
+
#
|
21
|
+
# bucket.tags['key'] = 'value'
|
22
|
+
#
|
23
|
+
# @exapmle Getting a tag.
|
24
|
+
#
|
25
|
+
# bucket.tags['key']
|
26
|
+
# #=> 'value'
|
27
|
+
#
|
28
|
+
# @example Getting all tags
|
29
|
+
#
|
30
|
+
# bucket.tags.to_h
|
31
|
+
# #=> { 'key' => 'value', ... }
|
32
|
+
#
|
33
|
+
# @example Removing all tags
|
34
|
+
#
|
35
|
+
# bucket.tags.clear
|
36
|
+
#
|
37
|
+
class BucketTagCollection
|
38
|
+
|
39
|
+
include Core::Model
|
40
|
+
|
41
|
+
# @param [Bucket] bucket
|
42
|
+
# @param [Hash] options
|
43
|
+
def initialize bucket, options = {}
|
44
|
+
@bucket = bucket
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Bucket]
|
49
|
+
attr_reader :bucket
|
50
|
+
|
51
|
+
# @param [String] key
|
52
|
+
# @return [String,nil] Returns the tag for the given key. If there
|
53
|
+
# Returns +nil+ if the key does not exist.
|
54
|
+
def [] key
|
55
|
+
self.to_h[key]
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param [String] key
|
59
|
+
# @param [String] value
|
60
|
+
def []= key, value
|
61
|
+
self.set(self.to_h.merge(key => value))
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param [Hash<String,String>] tags A hash of tag keys and values.
|
65
|
+
# @return [nil]
|
66
|
+
def set tags
|
67
|
+
if tags.nil? or tags.empty?
|
68
|
+
self.clear
|
69
|
+
else
|
70
|
+
client.put_bucket_tagging(:bucket_name => bucket.name, :tags => tags)
|
71
|
+
end
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
|
75
|
+
# Removes all tags from the bucket.
|
76
|
+
#
|
77
|
+
# bucket.tags.clear
|
78
|
+
# bucket.tags.to_h #=> {}
|
79
|
+
#
|
80
|
+
# @return [nil]
|
81
|
+
def clear
|
82
|
+
client.delete_bucket_tagging(:bucket_name => bucket.name)
|
83
|
+
nil
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Hash]
|
87
|
+
def to_h
|
88
|
+
client.get_bucket_tagging(:bucket_name => bucket.name).data[:tags]
|
89
|
+
rescue AWS::S3::Errors::NoSuchTagSet
|
90
|
+
{}
|
91
|
+
end
|
92
|
+
alias_method :to_hash, :to_h
|
93
|
+
|
94
|
+
# @param [Hash] other
|
95
|
+
# @return [Boolean] Returns +true+ if the tags for this bucket match
|
96
|
+
# the passed hash.
|
97
|
+
def eql? other
|
98
|
+
self.to_h == other
|
99
|
+
end
|
100
|
+
alias_method :==, :eql?
|
101
|
+
|
102
|
+
# @private
|
103
|
+
def inspect
|
104
|
+
self.to_h.inspect
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/aws/s3/client.rb
CHANGED
@@ -16,6 +16,7 @@ require 'pathname'
|
|
16
16
|
require 'stringio'
|
17
17
|
require 'json'
|
18
18
|
require 'digest/md5'
|
19
|
+
require 'nokogiri'
|
19
20
|
|
20
21
|
module AWS
|
21
22
|
class S3
|
@@ -166,10 +167,9 @@ module AWS
|
|
166
167
|
|
167
168
|
configure_request do |req, options|
|
168
169
|
xml = options[:lifecycle_configuration]
|
169
|
-
md5 = Base64.encode64(Digest::MD5.digest(xml)).strip
|
170
170
|
req.add_param('lifecycle')
|
171
171
|
req.body = xml
|
172
|
-
req.headers['content-md5'] = md5
|
172
|
+
req.headers['content-md5'] = md5(xml)
|
173
173
|
super(req, options)
|
174
174
|
end
|
175
175
|
|
@@ -206,6 +206,166 @@ module AWS
|
|
206
206
|
|
207
207
|
end
|
208
208
|
|
209
|
+
# @overload put_bucket_cors(options = {})
|
210
|
+
# @param [Hash] options
|
211
|
+
# @option options [required,String] :bucket_name
|
212
|
+
# @option options [required,Array<Hash>] :rules An array of rule hashes.
|
213
|
+
# * +:id+ - (String) A unique identifier for the rule. The ID
|
214
|
+
# value can be up to 255 characters long. The IDs help you find
|
215
|
+
# a rule in the configuration.
|
216
|
+
# * +:allowed_methods+ - (required,Array<String>) A list of HTTP
|
217
|
+
# methods that you want to allow the origin to execute.
|
218
|
+
# Each rule must identify at least one method.
|
219
|
+
# * +:allowed_origins+ - (required,Array<String>) A list of origins
|
220
|
+
# you want to allow cross-domain requests from. This can
|
221
|
+
# contain at most one * wild character.
|
222
|
+
# * +:allowed_headers+ - (Array<String>) A list of headers allowed
|
223
|
+
# in a pre-flight OPTIONS request via the
|
224
|
+
# Access-Control-Request-Headers header. Each header name
|
225
|
+
# specified in the Access-Control-Request-Headers header must
|
226
|
+
# have a corresponding entry in the rule.
|
227
|
+
# Amazon S3 will send only the allowed headers in a response
|
228
|
+
# that were requested. This can contain at most one * wild
|
229
|
+
# character.
|
230
|
+
# * +:max_age_seconds+ - (Integer) The time in seconds that your
|
231
|
+
# browser is to cache the preflight response for the specified
|
232
|
+
# resource.
|
233
|
+
# * +:expose_headers+ - (Array<String>) One or more headers in
|
234
|
+
# the response that you want customers to be able to access
|
235
|
+
# from their applications (for example, from a JavaScript
|
236
|
+
# XMLHttpRequest object).
|
237
|
+
# @return [Core::Response]
|
238
|
+
bucket_method(:put_bucket_cors, :put) do
|
239
|
+
configure_request do |req, options|
|
240
|
+
|
241
|
+
req.add_param('cors')
|
242
|
+
|
243
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
244
|
+
xml.CORSConfiguration do
|
245
|
+
options[:rules].each do |rule|
|
246
|
+
xml.CORSRule do
|
247
|
+
|
248
|
+
xml.ID(rule[:id]) if rule[:id]
|
249
|
+
|
250
|
+
(rule[:allowed_methods] || []).each do |method|
|
251
|
+
xml.AllowedMethod(method)
|
252
|
+
end
|
253
|
+
|
254
|
+
(rule[:allowed_origins] || []).each do |origin|
|
255
|
+
xml.AllowedOrigin(origin)
|
256
|
+
end
|
257
|
+
|
258
|
+
(rule[:allowed_headers] || []).each do |header|
|
259
|
+
xml.AllowedHeader(header)
|
260
|
+
end
|
261
|
+
|
262
|
+
xml.MaxAgeSeconds(rule[:max_age_seconds]) if
|
263
|
+
rule[:max_age_seconds]
|
264
|
+
|
265
|
+
(rule[:expose_headers] || []).each do |header|
|
266
|
+
xml.ExposeHeader(header)
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end.doc.root.to_xml
|
273
|
+
|
274
|
+
req.body = xml
|
275
|
+
req.headers['content-md5'] = md5(xml)
|
276
|
+
|
277
|
+
super(req, options)
|
278
|
+
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
# @overload get_bucket_cors(options = {})
|
283
|
+
# @param [Hash] options
|
284
|
+
# @option options [required,String] :bucket_name
|
285
|
+
# @return [Core::Response]
|
286
|
+
bucket_method(:get_bucket_cors, :get) do
|
287
|
+
|
288
|
+
configure_request do |req, options|
|
289
|
+
req.add_param('cors')
|
290
|
+
super(req, options)
|
291
|
+
end
|
292
|
+
|
293
|
+
process_response do |resp|
|
294
|
+
resp.data = XML::GetBucketCors.parse(resp.http_response.body)
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
# @overload delete_bucket_cors(options = {})
|
300
|
+
# @param [Hash] options
|
301
|
+
# @option options [required,String] :bucket_name
|
302
|
+
# @return [Core::Response]
|
303
|
+
bucket_method(:delete_bucket_cors, :delete) do
|
304
|
+
configure_request do |req, options|
|
305
|
+
req.add_param('cors')
|
306
|
+
super(req, options)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
# @overload put_bucket_tagging(options = {})
|
311
|
+
# @param [Hash] options
|
312
|
+
# @option options [required,String] :bucket_name
|
313
|
+
# @option options [Hash] :tags
|
314
|
+
# @return [Core::Response]
|
315
|
+
bucket_method(:put_bucket_tagging, :put) do
|
316
|
+
configure_request do |req, options|
|
317
|
+
|
318
|
+
req.add_param('tagging')
|
319
|
+
|
320
|
+
xml = Nokogiri::XML::Builder.new
|
321
|
+
xml.Tagging do |xml|
|
322
|
+
xml.TagSet do
|
323
|
+
options[:tags].each_pair do |key,value|
|
324
|
+
xml.Tag do
|
325
|
+
xml.Key(key)
|
326
|
+
xml.Value(value)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
xml = xml.doc.root.to_xml
|
333
|
+
req.body = xml
|
334
|
+
req.headers['content-md5'] = md5(xml)
|
335
|
+
|
336
|
+
super(req, options)
|
337
|
+
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
# @overload get_bucket_tagging(options = {})
|
342
|
+
# @param [Hash] options
|
343
|
+
# @option options [required,String] :bucket_name
|
344
|
+
# @return [Core::Response]
|
345
|
+
bucket_method(:get_bucket_tagging, :get) do
|
346
|
+
|
347
|
+
configure_request do |req, options|
|
348
|
+
req.add_param('tagging')
|
349
|
+
super(req, options)
|
350
|
+
end
|
351
|
+
|
352
|
+
process_response do |resp|
|
353
|
+
resp.data = XML::GetBucketTagging.parse(resp.http_response.body)
|
354
|
+
end
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
# @overload delete_bucket_tagging(options = {})
|
359
|
+
# @param [Hash] options
|
360
|
+
# @option options [required,String] :bucket_name
|
361
|
+
# @return [Core::Response]
|
362
|
+
bucket_method(:delete_bucket_tagging, :delete) do
|
363
|
+
configure_request do |req, options|
|
364
|
+
req.add_param('tagging')
|
365
|
+
super(req, options)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
209
369
|
# @overload list_buckets(options = {})
|
210
370
|
# @param [Hash] options
|
211
371
|
# @return [Core::Response]
|
@@ -929,10 +1089,7 @@ module AWS
|
|
929
1089
|
xml << "<Delete><Quiet>#{quiet}</Quiet>#{objects}</Delete>"
|
930
1090
|
|
931
1091
|
req.body = xml
|
932
|
-
|
933
|
-
md5 = Base64.encode64(Digest::MD5.digest(xml)).strip
|
934
|
-
|
935
|
-
req.headers['content-md5'] = md5
|
1092
|
+
req.headers['content-md5'] = md5(xml)
|
936
1093
|
|
937
1094
|
end
|
938
1095
|
end
|
@@ -1192,6 +1349,10 @@ module AWS
|
|
1192
1349
|
end
|
1193
1350
|
end
|
1194
1351
|
|
1352
|
+
def md5 str
|
1353
|
+
Base64.encode64(Digest::MD5.digest(str)).strip
|
1354
|
+
end
|
1355
|
+
|
1195
1356
|
module Validators
|
1196
1357
|
|
1197
1358
|
# @return [Boolean] Returns true if the given bucket name is valid.
|
data/lib/aws/s3/client/xml.rb
CHANGED
@@ -164,13 +164,49 @@ module AWS
|
|
164
164
|
GetBucketLifecycleConfiguration = BaseGrammar.customize do
|
165
165
|
element("Rule") do
|
166
166
|
list
|
167
|
-
rename(:rules)
|
167
|
+
rename(:rules)
|
168
168
|
element("Expiration") do
|
169
169
|
element("Days") { integer_value }
|
170
170
|
end
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
+
GetBucketCors = BaseGrammar.customize do
|
175
|
+
element "CORSRule" do
|
176
|
+
list
|
177
|
+
rename :rules
|
178
|
+
element "AllowedMethod" do
|
179
|
+
list
|
180
|
+
rename :allowed_methods
|
181
|
+
end
|
182
|
+
element "AllowedOrigin" do
|
183
|
+
list
|
184
|
+
rename :allowed_origins
|
185
|
+
end
|
186
|
+
element "AllowedHeader" do
|
187
|
+
list
|
188
|
+
rename :allowed_headers
|
189
|
+
end
|
190
|
+
element "MaxAgeSeconds" do
|
191
|
+
integer
|
192
|
+
end
|
193
|
+
element "ExposeHeader" do
|
194
|
+
list
|
195
|
+
rename :expose_headers
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
GetBucketTagging = BaseGrammar.customize do
|
201
|
+
element "TagSet" do
|
202
|
+
ignore
|
203
|
+
element "Tag" do
|
204
|
+
map_entry("Key", "Value")
|
205
|
+
rename :tags
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
174
210
|
end
|
175
211
|
end
|
176
212
|
end
|
data/lib/aws/s3/config.rb
CHANGED
@@ -0,0 +1,106 @@
|
|
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
|
+
class S3
|
16
|
+
|
17
|
+
# Represents a single CORS rule for an S3 {Bucket}.
|
18
|
+
#
|
19
|
+
# rule = bucket.cors.first
|
20
|
+
# rule.allowed_methods #=> ['GET', 'HEAD']
|
21
|
+
# rule.allowed_origins #=> ['*']
|
22
|
+
#
|
23
|
+
# @see CORSRuleCollection
|
24
|
+
class CORSRule
|
25
|
+
|
26
|
+
# @param [Hash] options A hash of the rule details.
|
27
|
+
#
|
28
|
+
# @option options [String] :id A unique identifier for the rule. The ID
|
29
|
+
# value can be up to 255 characters long. The IDs help you find
|
30
|
+
# a rule in the configuration.
|
31
|
+
#
|
32
|
+
# @option options [required,Array<String>] :allowed_methods A list of HTTP
|
33
|
+
# methods that you want to allow the origin to execute.
|
34
|
+
# Each rule must identify at least one method.
|
35
|
+
#
|
36
|
+
# @option options [required,Array<String>] :allowed_origins A list of
|
37
|
+
# origins you want to allow cross-domain requests from. This can
|
38
|
+
# contain at most one * wild character.
|
39
|
+
#
|
40
|
+
# @option options [Array<String>] :allowed_headers A list of headers
|
41
|
+
# allowed in a pre-flight OPTIONS request via the
|
42
|
+
# Access-Control-Request-Headers header. Each header name
|
43
|
+
# specified in the Access-Control-Request-Headers header must
|
44
|
+
# have a corresponding entry in the rule.
|
45
|
+
#
|
46
|
+
# Amazon S3 will send only the allowed headers in a response
|
47
|
+
# that were requested. This can contain at most one '*' wild
|
48
|
+
# character.
|
49
|
+
#
|
50
|
+
# @option options [Array<String>] :max_age_seconds The time in
|
51
|
+
# seconds that your browser is to cache the pre-flight response for
|
52
|
+
# the specified resource.
|
53
|
+
#
|
54
|
+
# @option options [Array<String>] :expose_headers One or more headers in
|
55
|
+
# the response that you want customers to be able to access
|
56
|
+
# from their applications (for example, from a JavaScript
|
57
|
+
# XMLHttpRequest object).
|
58
|
+
#
|
59
|
+
def initialize options = {}
|
60
|
+
@id = options[:id]
|
61
|
+
@allowed_methods = options[:allowed_methods] || []
|
62
|
+
@allowed_origins = options[:allowed_origins] || []
|
63
|
+
@allowed_headers = options[:allowed_headers] || []
|
64
|
+
@max_age_seconds = options[:max_age_seconds]
|
65
|
+
@expose_headers = options[:expose_headers] || []
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [String,nil] A user supplied unique identifier for this role.
|
69
|
+
# Set this when you set or add roles via {CORSRuleCollection}.
|
70
|
+
attr_reader :id
|
71
|
+
|
72
|
+
# @return [Array<String>] A list of HTTP methods (GET, POST, etc) this
|
73
|
+
# role authorizes.
|
74
|
+
attr_reader :allowed_methods
|
75
|
+
|
76
|
+
# @return [Array<String>] The list of origins allowed to make
|
77
|
+
# cross-domain requests to the bucket.
|
78
|
+
attr_reader :allowed_origins
|
79
|
+
|
80
|
+
# @return [Array<String>] A list of headers allowed in the pre-flight
|
81
|
+
# OPTIONS request.
|
82
|
+
attr_reader :allowed_headers
|
83
|
+
|
84
|
+
# @return [Integer,nil] The time in seconds the browser may cache the
|
85
|
+
# pre-flight response.
|
86
|
+
attr_reader :max_age_seconds
|
87
|
+
|
88
|
+
# @return [Array<String>] The headers that may be accessed cross-domain.
|
89
|
+
attr_reader :expose_headers
|
90
|
+
|
91
|
+
# @return [Hash]
|
92
|
+
def to_h
|
93
|
+
h = {}
|
94
|
+
h[:id] = id if id
|
95
|
+
h[:allowed_methods] = allowed_methods
|
96
|
+
h[:allowed_origins] = allowed_origins
|
97
|
+
h[:allowed_headers] = allowed_headers unless allowed_headers.empty?
|
98
|
+
h[:max_age_seconds] = max_age_seconds if max_age_seconds
|
99
|
+
h[:expose_headers] = expose_headers unless expose_headers.empty?
|
100
|
+
h
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|