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:
commit
748f3d22b2
3 changed files with 63 additions and 5 deletions
|
@ -5,7 +5,9 @@ module Fog
|
|||
class GetBucketLifecycle < Fog::Parsers::Base
|
||||
def reset
|
||||
@expiration = {}
|
||||
@version_expiration = {}
|
||||
@transition = {}
|
||||
@version_transition = {}
|
||||
@rule = {}
|
||||
@response = { 'Rules' => [] }
|
||||
end
|
||||
|
@ -17,6 +19,10 @@ module Fog
|
|||
@in_expiration = true
|
||||
when 'Transition'
|
||||
@in_transition = true
|
||||
when 'NoncurrentVersionExpiration'
|
||||
@in_version_expiration = true
|
||||
when 'NoncurrentVersionTransition'
|
||||
@in_version_transition = true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -32,6 +38,17 @@ module Fog
|
|||
@in_expiration = false
|
||||
@expiration = {}
|
||||
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
|
||||
case name
|
||||
when 'StorageClass',
|
||||
|
@ -45,6 +62,19 @@ module Fog
|
|||
@in_transition = false
|
||||
@transition = {}
|
||||
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
|
||||
case name
|
||||
when 'ID', 'Prefix'
|
||||
|
|
|
@ -10,13 +10,13 @@ module Fog
|
|||
# * ID [String] Unique identifier for the rule
|
||||
# * Prefix [String] Prefix identifying one or more objects to which the rule applies
|
||||
# * Enabled [Boolean] if rule is currently being applied
|
||||
# * Expiration [Hash] Container for the object expiration rule.
|
||||
# * Days [Integer] lifetime, in days, of the objects that are subject to the rule
|
||||
# * [NoncurrentVersion]Expiration [Hash] Container for the object expiration 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.
|
||||
# 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
|
||||
# * 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.
|
||||
# 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
|
||||
|
@ -33,7 +33,7 @@ module Fog
|
|||
ID rule['ID']
|
||||
Prefix rule['Prefix']
|
||||
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'] }
|
||||
else
|
||||
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 }
|
||||
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']
|
||||
Transition {
|
||||
if rule['Transition']['Days']
|
||||
|
@ -53,6 +66,16 @@ module Fog
|
|||
StorageClass rule['Transition']['StorageClass'].nil? ? 'GLACIER' : rule['Transition']['StorageClass']
|
||||
}
|
||||
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
|
||||
|
|
|
@ -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].get_bucket_lifecycle(@aws_bucket_name).body
|
||||
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'}}]}
|
||||
tests('date').returns(lifecycle) do
|
||||
Fog::Storage[:aws].put_bucket_lifecycle(@aws_bucket_name, lifecycle)
|
||||
|
|
Loading…
Reference in a new issue