aws-sdk 1.3.2 → 1.3.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.
- data/lib/aws/api_config/{IAM-2010-07-15.yml → IAM-2010-05-08.yml} +56 -4
- data/lib/aws/api_config/SNS-2010-03-31.yml +90 -81
- data/lib/aws/core.rb +26 -11
- data/lib/aws/core/client.rb +12 -4
- data/lib/aws/core/collection.rb +5 -12
- data/lib/aws/core/collection/limitable.rb +10 -3
- data/lib/aws/core/collection/simple.rb +1 -0
- data/lib/aws/core/configuration.rb +2 -0
- data/lib/aws/core/configured_json_client_methods.rb +5 -2
- data/lib/aws/core/http/httparty_handler.rb +1 -1
- data/lib/aws/core/http/net_http_handler.rb +2 -1
- data/lib/aws/core/http/request.rb +27 -0
- data/lib/aws/core/json_client.rb +41 -0
- data/lib/aws/core/lazy_error_classes.rb +2 -0
- data/lib/aws/core/option_grammar.rb +1 -1
- data/lib/aws/core/resource.rb +12 -14
- data/lib/aws/core/session_signer.rb +0 -5
- data/lib/aws/core/xml_grammar.rb +12 -2
- data/lib/aws/dynamo_db.rb +4 -1
- data/lib/aws/dynamo_db/client.rb +4 -17
- data/lib/aws/dynamo_db/item_collection.rb +15 -0
- data/lib/aws/ec2/security_group.rb +2 -1
- data/lib/aws/ec2/security_group/ip_permission.rb +2 -3
- data/lib/aws/elb/listener.rb +2 -2
- data/lib/aws/iam.rb +17 -0
- data/lib/aws/iam/client.rb +9 -6
- data/lib/aws/iam/mfa_device.rb +4 -2
- data/lib/aws/iam/mfa_device_collection.rb +14 -3
- data/lib/aws/iam/user.rb +10 -0
- data/lib/aws/iam/virtual_mfa_device.rb +139 -0
- data/lib/aws/iam/virtual_mfa_device_collection.rb +73 -0
- data/lib/aws/record/abstract_base.rb +1 -0
- data/lib/aws/record/hash_model/attributes.rb +8 -8
- data/lib/aws/record/hash_model/finder_methods.rb +10 -15
- data/lib/aws/record/model.rb +1 -3
- data/lib/aws/record/model/finder_methods.rb +3 -3
- data/lib/aws/s3.rb +1 -0
- data/lib/aws/s3/bucket.rb +83 -16
- data/lib/aws/s3/bucket_lifecycle_configuration.rb +360 -0
- data/lib/aws/s3/client.rb +50 -0
- data/lib/aws/s3/client/xml.rb +10 -0
- data/lib/aws/s3/object_version.rb +5 -0
- data/lib/aws/s3/object_version_collection.rb +15 -1
- data/lib/aws/s3/request.rb +1 -1
- data/lib/aws/s3/s3_object.rb +56 -1
- data/lib/aws/sns.rb +1 -0
- data/lib/aws/sns/has_delivery_policy.rb +68 -0
- data/lib/aws/sns/subscription.rb +62 -14
- data/lib/aws/sns/subscription_collection.rb +1 -1
- data/lib/aws/sns/topic.rb +22 -4
- data/lib/aws/sts.rb +3 -2
- data/lib/net/http/connection_pool.rb +1 -1
- metadata +27 -25
- data/lib/aws/core/collection/batchable.rb +0 -133
@@ -38,35 +38,28 @@ module AWS
|
|
38
38
|
end
|
39
39
|
alias_method :[], :find_by_id
|
40
40
|
|
41
|
-
# Finds records in
|
42
|
-
# current class.
|
41
|
+
# Finds records in Amazon DynamoDB and returns them as objects of
|
42
|
+
# the current class.
|
43
43
|
#
|
44
44
|
# Finding +:all+ returns an enumerable scope object
|
45
45
|
#
|
46
|
-
# People.find(:all, :
|
46
|
+
# People.find(:all, :limit => 10).each do |person|
|
47
47
|
# puts person.name
|
48
48
|
# end
|
49
49
|
#
|
50
50
|
# Finding +:first+ returns a single record (or nil)
|
51
51
|
#
|
52
|
-
# boss = People.find(:first
|
52
|
+
# boss = People.find(:first)
|
53
53
|
#
|
54
|
-
# Find accepts a hash of find modifiers (+:
|
55
|
-
#
|
54
|
+
# Find accepts a hash of find modifiers (+:shard+ and +:limit+).
|
55
|
+
# You can also choose to omit these modifiers and
|
56
56
|
# chain them on the scope object returned. In the following
|
57
57
|
# example only one request is made to SimpleDB (when #each is
|
58
58
|
# called)
|
59
59
|
#
|
60
|
-
# people = People.find(:all)
|
60
|
+
# people = People.find(:all, :limit => 10)
|
61
61
|
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
# johns.order(:age, :desc).limit(10).each do |suspects|
|
65
|
-
# # ...
|
66
|
-
# end
|
67
|
-
#
|
68
|
-
# See also {#where}, {#order} and {#limit} for more
|
69
|
-
# information and options.
|
62
|
+
# people = people.limit(10).find(:all)
|
70
63
|
#
|
71
64
|
# @overload find(id)
|
72
65
|
# @param id The record to find, raises an exception if the record is
|
@@ -77,6 +70,8 @@ module AWS
|
|
77
70
|
# and array is returned of records. When finding +:first+ then
|
78
71
|
# +nil+ or a single record will be returned.
|
79
72
|
# @param [Hash] options
|
73
|
+
# @option options [Integer] :shard The shard name of the Amazon
|
74
|
+
# DynamoDB table to search.
|
80
75
|
# @option options [Integer] :limit The max number of records to fetch.
|
81
76
|
def find *args
|
82
77
|
new_scope.find(*args)
|
data/lib/aws/record/model.rb
CHANGED
@@ -65,7 +65,7 @@ module AWS
|
|
65
65
|
# # ...
|
66
66
|
# end
|
67
67
|
#
|
68
|
-
# See also {
|
68
|
+
# See also {where}, {order} and {limit} for more
|
69
69
|
# information and options.
|
70
70
|
#
|
71
71
|
# @overload find(id)
|
@@ -107,7 +107,7 @@ module AWS
|
|
107
107
|
# end
|
108
108
|
#
|
109
109
|
# This method is equivalent to +find(:all)+, and therefore you can also
|
110
|
-
# pass aditional options. See {
|
110
|
+
# pass aditional options. See {.find} for more information on what
|
111
111
|
# options you can pass.
|
112
112
|
#
|
113
113
|
# Book.all(:where => { :author' => 'me' }).each do |my_book|
|
@@ -138,7 +138,7 @@ module AWS
|
|
138
138
|
#
|
139
139
|
# People.find(:all).where(:boss => true).count
|
140
140
|
#
|
141
|
-
# See {
|
141
|
+
# See {find} and {Scope#count} for more details.
|
142
142
|
#
|
143
143
|
# @param [Hash] options (<code>{}</code>) Options for counting
|
144
144
|
# records.
|
data/lib/aws/s3.rb
CHANGED
@@ -99,6 +99,7 @@ module AWS
|
|
99
99
|
autoload :ACLObject, 'acl_object'
|
100
100
|
autoload :Bucket, 'bucket'
|
101
101
|
autoload :BucketCollection, 'bucket_collection'
|
102
|
+
autoload :BucketLifecycleConfiguration, 'bucket_lifecycle_configuration'
|
102
103
|
autoload :BucketVersionCollection, 'bucket_version_collection'
|
103
104
|
autoload :Client, 'client'
|
104
105
|
autoload :DataOptions, 'data_options'
|
data/lib/aws/s3/bucket.rb
CHANGED
@@ -100,30 +100,27 @@ module AWS
|
|
100
100
|
client.get_bucket_versioning(:bucket_name => @name).status
|
101
101
|
end
|
102
102
|
|
103
|
-
# Deletes
|
104
|
-
#
|
105
|
-
|
106
|
-
|
103
|
+
# Deletes all objects from this bucket.
|
104
|
+
# @return [nil]
|
105
|
+
def clear!
|
106
|
+
versions.each_batch do |versions|
|
107
|
+
objects.delete(versions)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Deletes the current bucket. An error will be raised if the
|
112
|
+
# bucket is not empty.
|
107
113
|
# @return [nil]
|
108
|
-
#
|
109
114
|
def delete
|
110
115
|
client.delete_bucket(:bucket_name => @name)
|
111
116
|
nil
|
112
117
|
end
|
113
118
|
|
114
|
-
#
|
115
|
-
# and then attempts to delete the bucket.
|
116
|
-
#
|
117
|
-
# @note This operation may fail if you do not have privileges to delete
|
118
|
-
# all objects from the bucket.
|
119
|
-
#
|
119
|
+
# Deletes all objects in a bucket and then deletes the bucket.
|
120
120
|
# @return [nil]
|
121
|
-
#
|
122
121
|
def delete!
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
self.delete
|
122
|
+
clear!
|
123
|
+
delete
|
127
124
|
end
|
128
125
|
|
129
126
|
# @return [String] bucket owner id
|
@@ -286,6 +283,76 @@ module AWS
|
|
286
283
|
nil
|
287
284
|
end
|
288
285
|
|
286
|
+
# The primary interface for editing the lifecycle configuration.
|
287
|
+
# See {BucketLifecycleConfiguration} for more information.
|
288
|
+
#
|
289
|
+
# @example Adding rules to a bucket's lifecycle configuration
|
290
|
+
#
|
291
|
+
# bucket.lifecycle_configuration.update do
|
292
|
+
# add_rule 'cache-1/', 30
|
293
|
+
# add_rule 'cache-2/', 30
|
294
|
+
# end
|
295
|
+
#
|
296
|
+
# @example Deleting the lifecycle configuration
|
297
|
+
#
|
298
|
+
# bucket.lifecycle_configuration.clear
|
299
|
+
#
|
300
|
+
# @return [BucketLifecycleConfiguration]
|
301
|
+
#
|
302
|
+
def lifecycle_configuration
|
303
|
+
@lifecycle_cfg ||= BucketLifecycleConfiguration.new(self)
|
304
|
+
end
|
305
|
+
|
306
|
+
# You can call this method if you prefer to build your own
|
307
|
+
# lifecycle configuration.
|
308
|
+
#
|
309
|
+
# bucket.lifecycle_configuration = <<-XML
|
310
|
+
# <LifecycleConfiguration>
|
311
|
+
# ...
|
312
|
+
# </LifecycleConfiguration>
|
313
|
+
# XML
|
314
|
+
#
|
315
|
+
# You can also use this method to copy a lifecycle configuration
|
316
|
+
# from another bucket.
|
317
|
+
#
|
318
|
+
# bucket.lifecycle_configuration = other_bucket.lifecycle_configuration
|
319
|
+
#
|
320
|
+
# If you call this method, passing nil, the lifecycle configuration
|
321
|
+
# for this bucket will be deleted.
|
322
|
+
#
|
323
|
+
# @param [String,Object] config You can pass an xml string or any
|
324
|
+
# other object that responds to #to_xml (e.g.
|
325
|
+
# BucketLifecycleConfiguration).
|
326
|
+
#
|
327
|
+
# @return [nil]
|
328
|
+
#
|
329
|
+
def lifecycle_configuration= config
|
330
|
+
|
331
|
+
if config.nil?
|
332
|
+
|
333
|
+
client_opts = {}
|
334
|
+
client_opts[:bucket_name] = name
|
335
|
+
client.delete_bucket_lifecycle_configuration(client_opts)
|
336
|
+
|
337
|
+
@lifecycle_cfg = BucketLifecycleConfiguration.new(self, :empty => true)
|
338
|
+
|
339
|
+
else
|
340
|
+
|
341
|
+
xml = config.is_a?(String) ? config : config.to_xml
|
342
|
+
|
343
|
+
client_opts = {}
|
344
|
+
client_opts[:bucket_name] = name
|
345
|
+
client_opts[:lifecycle_configuration] = xml
|
346
|
+
client.set_bucket_lifecycle_configuration(client_opts)
|
347
|
+
|
348
|
+
@lifecycle_cfg = BucketLifecycleConfiguration.new(self, :xml => xml)
|
349
|
+
|
350
|
+
end
|
351
|
+
|
352
|
+
nil
|
353
|
+
|
354
|
+
end
|
355
|
+
|
289
356
|
# Returns a tree that allows you to expose the bucket contents
|
290
357
|
# like a directory structure.
|
291
358
|
#
|
@@ -0,0 +1,360 @@
|
|
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
|
+
require 'builder'
|
15
|
+
require 'uuidtools'
|
16
|
+
|
17
|
+
module AWS
|
18
|
+
class S3
|
19
|
+
|
20
|
+
# A lifecycle configuration is collections of rules for a single
|
21
|
+
# bucket that instructs that instruct
|
22
|
+
# Amazon S3 to delete certain objects after a period of days.
|
23
|
+
#
|
24
|
+
# == Rules
|
25
|
+
#
|
26
|
+
# Each lifecycle configuration has a list of rules. Each rule has the
|
27
|
+
# following attributes:
|
28
|
+
#
|
29
|
+
# * +#prefix+
|
30
|
+
# * +#expiration_days+
|
31
|
+
# * +#status+
|
32
|
+
# * +#id+
|
33
|
+
#
|
34
|
+
# Objects with keys matching a rule prefix will be deleted after
|
35
|
+
# #expiration_days have passed.
|
36
|
+
#
|
37
|
+
# A rule is comprised primarily of a prefix and number of expiration days.
|
38
|
+
# Objects with keys that start with the given prefix will be automatically
|
39
|
+
# deleted after "expiration days" have passed. Rules also have an
|
40
|
+
# ID and a status (they can be disabled).
|
41
|
+
#
|
42
|
+
# See {Rule} for more information on all of the attributes and methods
|
43
|
+
# available for rules.
|
44
|
+
#
|
45
|
+
# == Adding Rules
|
46
|
+
#
|
47
|
+
# You can add a rule to a bucket lifecycle configuration using #{add_rule}.
|
48
|
+
#
|
49
|
+
# # add a rule that deletes backups after they are 1 year old
|
50
|
+
# bucket.lifecycle_configuration.update do
|
51
|
+
# add_rule('backups/', 365)
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# If you perfer to specify a rule's ID or status (defaults to 'Enabled')
|
55
|
+
# you can do this with {#add_rule}.
|
56
|
+
#
|
57
|
+
# # add a rule that deletes backups after they are 1 year old
|
58
|
+
# bucket.lifecycle_configuration.update do
|
59
|
+
# add_rule('backups/', 365, :id => 'backup-rule', :disabled => true
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# == Replacing Rules
|
63
|
+
#
|
64
|
+
# If you prefer to completely replace a lifecycle configuration, call
|
65
|
+
# #add_rule inside a #replace block instead of an #update block:
|
66
|
+
#
|
67
|
+
# # replace all existing rules with the following
|
68
|
+
# bucket.lifecycle_configuration.replace do
|
69
|
+
# add_rule('backups/', 30)
|
70
|
+
# add_rule('temp/', 10)
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# == Removing Rules
|
74
|
+
#
|
75
|
+
# You can delete specific rules with #remove_rule.
|
76
|
+
#
|
77
|
+
# # delete all disabled rules
|
78
|
+
# bucket.lifecycle_configuration.update do
|
79
|
+
# rules.each do |rule|
|
80
|
+
# remove_rule(rule) if rule.disabled?
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# You can also remove all rules in a single call:
|
85
|
+
#
|
86
|
+
# # remove all rules from this lifecycle configuration
|
87
|
+
# bucket.lifecycle_configuration.clear
|
88
|
+
#
|
89
|
+
# == Editing Existing Rules
|
90
|
+
#
|
91
|
+
# You can also make changes to existing rules.
|
92
|
+
#
|
93
|
+
# # change the expiration days to 10 for EVERY rule
|
94
|
+
# bucket.lifecycle_configuration.update do
|
95
|
+
# rules.each do |rule|
|
96
|
+
# rule.expiration_days = 10
|
97
|
+
# end
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# Please be aware, if you add, remove or edit rules outside of an
|
101
|
+
# #update or #replace block, then you must call {#update} yourself
|
102
|
+
# or the changes will not be persisted.
|
103
|
+
#
|
104
|
+
class BucketLifecycleConfiguration
|
105
|
+
|
106
|
+
# @private
|
107
|
+
def initialize bucket, options = {}
|
108
|
+
@bucket = bucket
|
109
|
+
@rules = parse_xml(options[:xml]) if options[:xml]
|
110
|
+
@rules = [] if options[:empty] == true
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Bucket] Returns the bucket this lifecycle configuration
|
114
|
+
# belongs to.
|
115
|
+
attr_reader :bucket
|
116
|
+
|
117
|
+
# @return [Array<Hash>] Returns an array of rules.
|
118
|
+
def rules
|
119
|
+
@rules ||= begin
|
120
|
+
begin
|
121
|
+
opts = { :bucket_name => bucket.name }
|
122
|
+
response = bucket.client.get_bucket_lifecycle_configuration(opts)
|
123
|
+
parse_xml(response.http_response.body)
|
124
|
+
rescue Errors::NoSuchLifecycleConfiguration
|
125
|
+
[]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# @param [String] prefix
|
131
|
+
#
|
132
|
+
# @param [Integer] expiration_days Indicates the lifetime for objects
|
133
|
+
# matching the given prefix.
|
134
|
+
#
|
135
|
+
# @param [Hash] options
|
136
|
+
#
|
137
|
+
# @option options [String] :id A unique ID for this rule. If an ID
|
138
|
+
# is not provided, one will be generated.
|
139
|
+
#
|
140
|
+
# @option options [Boolean] :disabled (false) By default, all rules
|
141
|
+
# will have the status of enabled. You can override this default
|
142
|
+
# by passing +:disabled+ => true.
|
143
|
+
#
|
144
|
+
# @return [Rule] Returns the rule that was added, as a {Rule} object.
|
145
|
+
#
|
146
|
+
def add_rule prefix, expiration_days, options = {}
|
147
|
+
id = options[:id] || UUIDTools::UUID.random_create.to_s
|
148
|
+
status = options[:disabled] == true ? 'Disabled' : 'Enabled'
|
149
|
+
rule = Rule.new(self, id, prefix, expiration_days, status)
|
150
|
+
self.rules << rule
|
151
|
+
rule
|
152
|
+
end
|
153
|
+
|
154
|
+
# Removes a single rule. You can pass a rule id or a {Rule}
|
155
|
+
# object.
|
156
|
+
#
|
157
|
+
# # remove a single rule by its ID
|
158
|
+
# bucket.lifecycle_configuration.update do
|
159
|
+
# remove_rule('rule-id')
|
160
|
+
# end
|
161
|
+
#
|
162
|
+
# # remove all disabled rules
|
163
|
+
# bucket.lifecycle_configuration.update do
|
164
|
+
# rules.each do |rule|
|
165
|
+
# remove_rule(rule) if rule.disabled?
|
166
|
+
# end
|
167
|
+
# end
|
168
|
+
#
|
169
|
+
# If you call #remove_rule outside an update block
|
170
|
+
# you need to call #update to save the changes.
|
171
|
+
#
|
172
|
+
# @param [Rule,String] rule_or_rule_id
|
173
|
+
#
|
174
|
+
# @return [nil]
|
175
|
+
#
|
176
|
+
def remove_rule rule_or_rule_id
|
177
|
+
rule_id = rule_or_rule_id
|
178
|
+
if rule_id.nil?
|
179
|
+
raise ArgumentError, "expected a rule or rule id, got nil"
|
180
|
+
end
|
181
|
+
rule_id = rule_id.id unless rule_id.is_a?(String)
|
182
|
+
@rules = rules.select{|r| r.id != rule_id }
|
183
|
+
nil
|
184
|
+
end
|
185
|
+
|
186
|
+
# Saves changes made to this lifecycle configuration.
|
187
|
+
#
|
188
|
+
# # set the number of days before expiration for all rules to 10
|
189
|
+
# config = bucket.lifecycle_configuration
|
190
|
+
# config.rules.each do |rule|
|
191
|
+
# rule.expiration_days = 10
|
192
|
+
# end
|
193
|
+
# config.update
|
194
|
+
#
|
195
|
+
# You can call #update with a block. Changes are persisted at the
|
196
|
+
# end of the block.
|
197
|
+
#
|
198
|
+
# # shorter version of the example above
|
199
|
+
# bucket.lifecycle_configuration.update do
|
200
|
+
# rules.each {|rule| rule.expiration_days = 10 }
|
201
|
+
# end
|
202
|
+
#
|
203
|
+
# A block method for updating a BucketLifecycleConfiguration.
|
204
|
+
# All modifications made inside the block are persisted at the end of
|
205
|
+
# the block.
|
206
|
+
#
|
207
|
+
# # 1 request
|
208
|
+
# bucket.lifecycle_configuration.update do
|
209
|
+
# add_rule 'prefix/a', 10
|
210
|
+
# add_rule 'prefix/b', 5
|
211
|
+
# end
|
212
|
+
#
|
213
|
+
# # 2 requests
|
214
|
+
# bucket.lifecycle_configuration.add_rule 'prefix/a', 10
|
215
|
+
# bucket.lifecycle_configuration.add_rule 'prefix/b', 5
|
216
|
+
#
|
217
|
+
# @return [nil]
|
218
|
+
#
|
219
|
+
def update &block
|
220
|
+
begin
|
221
|
+
@batching = true
|
222
|
+
instance_eval(&block) if block_given?
|
223
|
+
persist(true)
|
224
|
+
ensure
|
225
|
+
@batching = false
|
226
|
+
end
|
227
|
+
nil
|
228
|
+
end
|
229
|
+
|
230
|
+
# Yields to the given block. Before yielding, the current
|
231
|
+
# rules will be blanked out. This allows you to provide all
|
232
|
+
# new rules.
|
233
|
+
#
|
234
|
+
# When the block is complete, a single call will be made to save
|
235
|
+
# the new rules.
|
236
|
+
#
|
237
|
+
# bucket.lifecycle_configuration.rules.size #=> 3
|
238
|
+
#
|
239
|
+
# # replace the existing 3 rules with a single rule
|
240
|
+
# bucket.lifecycle_configuration.replace
|
241
|
+
# add_rule 'temp/', 10
|
242
|
+
# end
|
243
|
+
#
|
244
|
+
# bucket.lifecycle_configuration.rules.size #=> 1
|
245
|
+
#
|
246
|
+
def replace &block
|
247
|
+
@rules = []
|
248
|
+
update(&block)
|
249
|
+
end
|
250
|
+
|
251
|
+
def clear
|
252
|
+
@rules = []
|
253
|
+
bucket.lifecycle_configuration = nil
|
254
|
+
end
|
255
|
+
alias_method :remove, :clear
|
256
|
+
|
257
|
+
# @return [String] Returns an xml string representation of this
|
258
|
+
# bucket lifecycle configuration.
|
259
|
+
def to_xml
|
260
|
+
xml = Builder::XmlMarkup.new(:indent => 2)
|
261
|
+
xml.LifecycleConfiguration do
|
262
|
+
rules.each do |rule|
|
263
|
+
xml.Rule do
|
264
|
+
xml.ID rule.id
|
265
|
+
xml.Prefix rule.prefix
|
266
|
+
xml.Status rule.status
|
267
|
+
xml.Expiration do
|
268
|
+
xml.Days rule.expiration_days
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end.strip
|
273
|
+
end
|
274
|
+
|
275
|
+
protected
|
276
|
+
def persist force = false
|
277
|
+
unless @batching and force == false
|
278
|
+
if rules.empty?
|
279
|
+
bucket.lifecycle_configuration = nil
|
280
|
+
else
|
281
|
+
bucket.lifecycle_configuration = self
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
protected
|
287
|
+
def parse_xml xml
|
288
|
+
Client::XML::GetBucketLifecycleConfiguration.parse(xml).rules.map do |r|
|
289
|
+
Rule.new(self, r.id, r.prefix, r.expiration.days, r.status)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
# Represents a single rule from an Amazon S3 bucket lifecycle
|
294
|
+
# configuration.
|
295
|
+
#
|
296
|
+
# # delete all objects with the prefix 'temporary/' after 10 days
|
297
|
+
# bucket.lifecycle_configuration.add_rule 'temporary/', 10
|
298
|
+
#
|
299
|
+
# # remove the rule created above
|
300
|
+
# bucket.lifecycle_configuration.remove_rule 'temporary/'
|
301
|
+
#
|
302
|
+
#
|
303
|
+
class Rule
|
304
|
+
|
305
|
+
def initialize configuration, id, prefix, expiration_days, status
|
306
|
+
@configuration = configuration
|
307
|
+
@id = id
|
308
|
+
@prefix = prefix
|
309
|
+
@expiration_days = expiration_days
|
310
|
+
@status = status
|
311
|
+
end
|
312
|
+
|
313
|
+
# @return [BucketLifecycleConfiguration]
|
314
|
+
attr_reader :configuration
|
315
|
+
|
316
|
+
# @return [String]
|
317
|
+
attr_reader :id
|
318
|
+
|
319
|
+
# @return [String]
|
320
|
+
attr_accessor :prefix
|
321
|
+
|
322
|
+
# @return [Integer]
|
323
|
+
attr_accessor :expiration_days
|
324
|
+
|
325
|
+
# @return [String] Returns the rule status, 'Enabled' or 'Disabled'
|
326
|
+
attr_accessor :status
|
327
|
+
|
328
|
+
def enabled?
|
329
|
+
status == 'Enabled'
|
330
|
+
end
|
331
|
+
|
332
|
+
def enable!
|
333
|
+
self.status = 'Enabled'
|
334
|
+
end
|
335
|
+
|
336
|
+
def disabled?
|
337
|
+
status == 'Disabled'
|
338
|
+
end
|
339
|
+
|
340
|
+
def disabled!
|
341
|
+
self.status = 'Disabled'
|
342
|
+
end
|
343
|
+
|
344
|
+
# @private
|
345
|
+
def eql? other
|
346
|
+
other.is_a?(Rule) and
|
347
|
+
other.configuration.bucket == configuration.bucket and
|
348
|
+
other.id == id and
|
349
|
+
other.prefix == prefix and
|
350
|
+
other.expiration_days == expiration_days and
|
351
|
+
other.status == status
|
352
|
+
end
|
353
|
+
alias_method :==, :eql?
|
354
|
+
|
355
|
+
end
|
356
|
+
|
357
|
+
end
|
358
|
+
|
359
|
+
end
|
360
|
+
end
|