1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00

Merge pull request #210 from xtoddx/s3-versioned-lifecycle

Support NoncurrentVersion[Expiration,Transition] for s3 lifecycle.
This commit is contained in:
Wesley Beary 2015-12-22 10:45:20 -06:00
commit 748f3d22b2
3 changed files with 63 additions and 5 deletions

View file

@ -5,7 +5,9 @@ module Fog
class GetBucketLifecycle < Fog::Parsers::Base class GetBucketLifecycle < Fog::Parsers::Base
def reset def reset
@expiration = {} @expiration = {}
@version_expiration = {}
@transition = {} @transition = {}
@version_transition = {}
@rule = {} @rule = {}
@response = { 'Rules' => [] } @response = { 'Rules' => [] }
end end
@ -17,6 +19,10 @@ module Fog
@in_expiration = true @in_expiration = true
when 'Transition' when 'Transition'
@in_transition = true @in_transition = true
when 'NoncurrentVersionExpiration'
@in_version_expiration = true
when 'NoncurrentVersionTransition'
@in_version_transition = true
end end
end end
@ -32,6 +38,17 @@ module Fog
@in_expiration = false @in_expiration = false
@expiration = {} @expiration = {}
end end
elsif @in_version_expiration
case name
when 'NoncurrentDays'
@version_expiration[name] = value.to_i
when 'Date'
@version_expiration[name] = value
when 'NoncurrentVersionExpiration'
@rule['NoncurrentVersionExpiration'] = @version_expiration
@in_version_expiration = false
@version_expiration = {}
end
elsif @in_transition elsif @in_transition
case name case name
when 'StorageClass', when 'StorageClass',
@ -45,6 +62,19 @@ module Fog
@in_transition = false @in_transition = false
@transition = {} @transition = {}
end end
elsif @in_version_transition
case name
when 'StorageClass',
@version_transition['StorageClass'] = value
when 'Date'
@version_transition[name] = value
when 'NoncurrentDays'
@version_transition[name] = value.to_i
when 'NoncurrentVersionTransition'
@rule['NoncurrentVersionTransition'] = @transition
@in_version_transition = false
@version_transition = {}
end
else else
case name case name
when 'ID', 'Prefix' when 'ID', 'Prefix'

View file

@ -10,13 +10,13 @@ module Fog
# * ID [String] Unique identifier for the rule # * ID [String] Unique identifier for the rule
# * Prefix [String] Prefix identifying one or more objects to which the rule applies # * Prefix [String] Prefix identifying one or more objects to which the rule applies
# * Enabled [Boolean] if rule is currently being applied # * Enabled [Boolean] if rule is currently being applied
# * Expiration [Hash] Container for the object expiration rule. # * [NoncurrentVersion]Expiration [Hash] Container for the object expiration rule.
# * Days [Integer] lifetime, in days, of the objects that are subject to the rule # * [Noncurrent]Days [Integer] lifetime, in days, of the objects that are subject to the rule
# * Date [Date] Indicates when the specific rule take effect. # * Date [Date] Indicates when the specific rule take effect.
# The date value must conform to the ISO 8601 format. The time is always midnight UTC. # The date value must conform to the ISO 8601 format. The time is always midnight UTC.
# * Transition [Hash] Container for the transition rule that describes when objects transition # * [NoncurrentVersion]Transition [Hash] Container for the transition rule that describes when objects transition
# to the Glacier storage class # to the Glacier storage class
# * Days [Integer] lifetime, in days, of the objects that are subject to the rule # * [Noncurrent]Days [Integer] lifetime, in days, of the objects that are subject to the rule
# * Date [Date] Indicates when the specific rule take effect. # * Date [Date] Indicates when the specific rule take effect.
# The date value must conform to the ISO 8601 format. The time is always midnight UTC. # The date value must conform to the ISO 8601 format. The time is always midnight UTC.
# * StorageClass [String] Indicates the Amazon S3 storage class to which you want the object # * StorageClass [String] Indicates the Amazon S3 storage class to which you want the object
@ -33,7 +33,7 @@ module Fog
ID rule['ID'] ID rule['ID']
Prefix rule['Prefix'] Prefix rule['Prefix']
Status rule['Enabled'] ? 'Enabled' : 'Disabled' Status rule['Enabled'] ? 'Enabled' : 'Disabled'
unless (rule['Expiration'] or rule['Transition']) unless (rule['Expiration'] or rule['Transition'] or rule['NoncurrentVersionExpiration'] or rule['NoncurrentVersionTransition'])
Expiration { Days rule['Days'] } Expiration { Days rule['Days'] }
else else
if rule['Expiration'] if rule['Expiration']
@ -43,6 +43,19 @@ module Fog
Expiration { Date rule['Expiration']['Date'].is_a?(Time) ? rule['Expiration']['Date'].utc.iso8601 : Time.parse(rule['Expiration']['Date']).utc.iso8601 } Expiration { Date rule['Expiration']['Date'].is_a?(Time) ? rule['Expiration']['Date'].utc.iso8601 : Time.parse(rule['Expiration']['Date']).utc.iso8601 }
end end
end end
if rule['NoncurrentVersionExpiration']
if rule['NoncurrentVersionExpiration']['NoncurrentDays']
NoncurrentVersionExpiration { NoncurrentDays rule['NoncurrentVersionExpiration']['NoncurrentDays'] }
elsif rule['NoncurrentVersionExpiration']['Date']
NoncurrentVersoinExpiration {
if Date rule['NoncurrentVersionExpiration']['Date'].is_a?(Time)
rule['NoncurrentVersionExpiration']['Date'].utc.iso8601
else
Time.parse(rule['NoncurrentVersionExpiration']['Date']).utc.iso8601
end
}
end
end
if rule['Transition'] if rule['Transition']
Transition { Transition {
if rule['Transition']['Days'] if rule['Transition']['Days']
@ -53,6 +66,16 @@ module Fog
StorageClass rule['Transition']['StorageClass'].nil? ? 'GLACIER' : rule['Transition']['StorageClass'] StorageClass rule['Transition']['StorageClass'].nil? ? 'GLACIER' : rule['Transition']['StorageClass']
} }
end end
if rule['NoncurrentVersionTransition']
NoncurrentVersionTransition {
if rule['NoncurrentVersionTransition']['NoncurrentDays']
NoncurrentDays rule['NoncurrentVersionTransition']['NoncurrentDays']
elsif rule['NoncurrentVersionTransition']['Date']
Date rule['NoncurrentVersionTransition']['Date'].is_a?(Time) ? time.utc.iso8601 : Time.parse(time).utc.iso8601
end
StorageClass rule['NoncurrentVersionTransition']['StorageClass'].nil? ? 'GLACIER' : rule['NoncurrentVersionTransition']['StorageClass']
}
end
end end
} }
end end

View file

@ -277,6 +277,11 @@ Shindo.tests('Fog::Storage[:aws] | bucket requests', ["aws"]) do
Fog::Storage[:aws].put_bucket_lifecycle(@aws_bucket_name, lifecycle) Fog::Storage[:aws].put_bucket_lifecycle(@aws_bucket_name, lifecycle)
Fog::Storage[:aws].get_bucket_lifecycle(@aws_bucket_name).body Fog::Storage[:aws].get_bucket_lifecycle(@aws_bucket_name).body
end end
lifecycle = {'Rules' => [{'ID' => 'test rule', 'Prefix' => '/prefix', 'Enabled' => true, 'NoncurrentVersionExpiration' => {'NoncurrentDays' => 42}, 'NoncurrentVersionTransition' => {'NoncurrentDays' => 6, 'StorageClass'=>'GLACIER'}}]}
tests('versioned transition').returns(lifecycle) do
Fog::Storage[:aws].put_bucket_lifecycle(@aws_bucket_name, lifecycle)
Fog::Storage[:aws].get_bucket_lifecycle(@aws_bucket_name).body
end
lifecycle = {'Rules' => [{'ID' => 'test rule', 'Prefix' => '/prefix', 'Enabled' => true, 'Expiration' => {'Date' => '2012-12-31T00:00:00.000Z'}}]} lifecycle = {'Rules' => [{'ID' => 'test rule', 'Prefix' => '/prefix', 'Enabled' => true, 'Expiration' => {'Date' => '2012-12-31T00:00:00.000Z'}}]}
tests('date').returns(lifecycle) do tests('date').returns(lifecycle) do
Fog::Storage[:aws].put_bucket_lifecycle(@aws_bucket_name, lifecycle) Fog::Storage[:aws].put_bucket_lifecycle(@aws_bucket_name, lifecycle)