aws-sdk 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/README.rdoc +4 -4
  2. data/lib/aws-sdk.rb +60 -1
  3. data/lib/aws.rb +1 -50
  4. data/lib/aws/api_config/CloudFront-2012-05-05.yml +864 -899
  5. data/lib/aws/api_config/DataPipeline-2012-10-29.yml +422 -0
  6. data/lib/aws/api_config/EC2-2012-07-20.yml +0 -2
  7. data/lib/aws/api_config/Glacier-2012-06-01.yml +622 -0
  8. data/lib/aws/api_config/ImportExport-2010-06-01.yml +109 -0
  9. data/lib/aws/api_config/{SQS-2011-10-01.yml → SQS-2012-11-05.yml} +3 -1
  10. data/lib/aws/api_config/StorageGateway-2012-06-30.yml +748 -0
  11. data/lib/aws/cloud_front.rb +71 -0
  12. data/lib/aws/cloud_front/client.rb +1307 -0
  13. data/lib/aws/cloud_front/config.rb +18 -0
  14. data/lib/aws/cloud_front/errors.rb +22 -0
  15. data/lib/aws/cloud_front/request.rb +44 -0
  16. data/lib/aws/core.rb +19 -1
  17. data/lib/aws/core/client.rb +7 -0
  18. data/lib/aws/core/collection.rb +1 -1
  19. data/lib/aws/core/configuration.rb +12 -0
  20. data/lib/aws/core/data.rb +13 -8
  21. data/lib/aws/core/json_client.rb +3 -4
  22. data/lib/aws/core/json_parser.rb +76 -0
  23. data/lib/aws/core/json_request_builder.rb +4 -3
  24. data/lib/aws/core/json_response_parser.rb +1 -3
  25. data/lib/aws/core/managed_file.rb +32 -0
  26. data/lib/aws/core/options/json_serializer.rb +82 -0
  27. data/lib/aws/core/options/validator.rb +5 -1
  28. data/lib/aws/core/options/xml_serializer.rb +18 -4
  29. data/lib/aws/core/{rest_client.rb → rest_json_client.rb} +5 -6
  30. data/lib/aws/core/rest_request_builder.rb +59 -35
  31. data/lib/aws/core/rest_response_parser.rb +13 -4
  32. data/lib/aws/core/rest_xml_client.rb +47 -0
  33. data/lib/aws/core/signature/version_4.rb +22 -8
  34. data/lib/aws/data_pipeline.rb +30 -0
  35. data/lib/aws/data_pipeline/client.rb +392 -0
  36. data/lib/aws/data_pipeline/config.rb +18 -0
  37. data/lib/aws/data_pipeline/errors.rb +20 -0
  38. data/lib/aws/data_pipeline/request.rb +26 -0
  39. data/lib/aws/ec2/instance_collection.rb +11 -3
  40. data/lib/aws/ec2/security_group.rb +5 -5
  41. data/lib/aws/ec2/security_group/{egress_ip_permission_collection.rb → ip_permission_collection.rb} +33 -14
  42. data/lib/aws/glacier.rb +50 -0
  43. data/lib/aws/glacier/archive.rb +54 -0
  44. data/lib/aws/glacier/archive_collection.rb +141 -0
  45. data/lib/aws/glacier/client.rb +286 -0
  46. data/lib/aws/glacier/config.rb +19 -0
  47. data/lib/aws/glacier/errors.rb +22 -0
  48. data/lib/aws/glacier/request.rb +34 -0
  49. data/lib/aws/glacier/resource.rb +30 -0
  50. data/lib/aws/glacier/vault.rb +137 -0
  51. data/lib/aws/glacier/vault_collection.rb +75 -0
  52. data/lib/aws/glacier/vault_notification_configuration.rb +27 -0
  53. data/lib/aws/import_export.rb +71 -0
  54. data/lib/aws/import_export/client.rb +109 -0
  55. data/lib/aws/import_export/config.rb +19 -0
  56. data/lib/aws/import_export/errors.rb +22 -0
  57. data/lib/aws/import_export/request.rb +23 -0
  58. data/lib/aws/route_53/client.rb +1 -1
  59. data/lib/aws/s3/bucket_lifecycle_configuration.rb +160 -63
  60. data/lib/aws/s3/client.rb +43 -0
  61. data/lib/aws/s3/client/xml.rb +6 -0
  62. data/lib/aws/s3/cors_rule_collection.rb +1 -1
  63. data/lib/aws/s3/data_options.rb +1 -3
  64. data/lib/aws/s3/request.rb +1 -1
  65. data/lib/aws/s3/s3_object.rb +52 -10
  66. data/lib/aws/sqs/client.rb +9 -3
  67. data/lib/aws/sqs/queue.rb +44 -5
  68. data/lib/aws/storage_gateway.rb +71 -0
  69. data/lib/aws/storage_gateway/client.rb +472 -0
  70. data/lib/aws/storage_gateway/config.rb +18 -0
  71. data/lib/aws/storage_gateway/errors.rb +22 -0
  72. data/lib/aws/storage_gateway/request.rb +28 -0
  73. data/lib/aws/version.rb +1 -1
  74. metadata +45 -10
  75. data/lib/aws/ec2/security_group/ingress_ip_permission_collection.rb +0 -61
@@ -0,0 +1,75 @@
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 Glacier
16
+
17
+ class VaultCollection
18
+
19
+ include Core::Collection::WithLimitAndNextToken
20
+
21
+ # @param [Hash] options
22
+ # @option options [String] :account_id
23
+ def initialize options = {}
24
+ @account_id = options[:account_id] || '-'
25
+ super
26
+ end
27
+
28
+ # @return [String]
29
+ attr_reader :account_id
30
+
31
+ # @param [String] name
32
+ def create name
33
+
34
+ options = {}
35
+ options[:vault_name] = name
36
+ options[:account_id] = account_id
37
+ client.create_vault(options)
38
+
39
+ self[name]
40
+
41
+ end
42
+
43
+ # @param [String] name The name of the vault.
44
+ # @return [Vault] Returns a vault with the given name.
45
+ def [] name
46
+ Vault.new(name, :config => config, :account_id => account_id)
47
+ end
48
+
49
+ protected
50
+
51
+ def _each_item next_token, limit, options, &block
52
+
53
+ options[:limit] = limit if limit
54
+ options[:marker] = next_token if next_token
55
+ options[:account_id] = account_id
56
+
57
+ resp = client.list_vaults(options)
58
+ resp[:vault_list].each do |v|
59
+
60
+ vault = Vault.new_from(:list_vaults, v,
61
+ v[:vault_name],
62
+ :config => config,
63
+ :account_id => account_id)
64
+
65
+ yield(vault)
66
+
67
+ end
68
+
69
+ resp[:marker]
70
+
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,27 @@
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 Glacier
16
+ class VaultNotificationConfiguration
17
+
18
+ # @return [SNS::Topic] The SNS topic Glacier will publish events to.
19
+ attr_accessor :sns_topic
20
+
21
+ # @return [Array<String>] events An array of one or more events for
22
+ # which Amazon Glacier will send notifications.
23
+ attr_accessor :events
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,71 @@
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 'aws/core'
15
+ require 'aws/import_export/config'
16
+
17
+ module AWS
18
+
19
+ # This class is the starting point for working with AWS Import/Export.
20
+ #
21
+ # To use AWS Import/Export you must first
22
+ # {sign up here}[http://aws.amazon.com/importexport/].
23
+ #
24
+ # For more information about AWS Import/Export:
25
+ #
26
+ # * {AWS Import/Export}[http://aws.amazon.com/importexport/]
27
+ # * {AWS Import/Export Documentation}[http://aws.amazon.com/documentation/importexport/]
28
+ #
29
+ # = Credentials
30
+ #
31
+ # You can setup default credentials for all AWS services via
32
+ # AWS.config:
33
+ #
34
+ # AWS.config(
35
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
36
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
37
+ #
38
+ # Or you can set them directly on the AWS::ImportExport interface:
39
+ #
40
+ # ie = AWS::ImportExport.new(
41
+ # :access_key_id => 'YOUR_ACCESS_KEY_ID',
42
+ # :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
43
+ #
44
+ # = Using the Client
45
+ #
46
+ # AWS::ImportExport does not provide higher level abstractions for Import/Export at
47
+ # this time. You can still access all of the API methods using
48
+ # {AWS::ImportExport::Client}. Here is how you access the client and make
49
+ # a simple request:
50
+ #
51
+ # ie = AWS::ImportExport.new
52
+ #
53
+ # resp = ie.client.list_hosted_zones
54
+ # resp[:hosted_zones].each do |zone|
55
+ # # ...
56
+ # end
57
+ #
58
+ # See {Client} for documentation on all of the supported operations.
59
+ #
60
+ class ImportExport
61
+
62
+ AWS.register_autoloads(self, 'aws/import_export') do
63
+ autoload :Client, 'client'
64
+ autoload :Errors, 'errors'
65
+ autoload :Request, 'request'
66
+ end
67
+
68
+ include Core::ServiceInterface
69
+
70
+ end
71
+ end
@@ -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 ImportExport
16
+
17
+ # Client class for AWS Import/Export.
18
+ class Client < Core::QueryClient
19
+
20
+ define_client_methods('2010-06-01')
21
+
22
+ # @private
23
+ CACHEABLE_REQUESTS = Set[]
24
+
25
+ ## client methods ##
26
+
27
+ # @!method cancel_job(options = {})
28
+ # Calls the CancelJob API operation.
29
+ # @param [Hash] options
30
+ # * +:job_id+ - *required* - (String)
31
+ # @return [Core::Response]
32
+ # The #data method of the response object returns
33
+ # a hash with the following structure:
34
+ # * +:success+ - (Boolean)
35
+
36
+ # @!method create_job(options = {})
37
+ # Calls the CreateJob API operation.
38
+ # @param [Hash] options
39
+ # * +:job_type+ - *required* - (String)
40
+ # * +:manifest+ - *required* - (String)
41
+ # * +:manifest_addendum+ - (String)
42
+ # * +:validate_only+ - *required* - (Boolean)
43
+ # @return [Core::Response]
44
+ # The #data method of the response object returns
45
+ # a hash with the following structure:
46
+ # * +:job_id+ - (String)
47
+ # * +:job_type+ - (String)
48
+ # * +:aws_shipping_address+ - (String)
49
+ # * +:signature+ - (String)
50
+ # * +:signature_file_contents+ - (String)
51
+ # * +:warning_message+ - (String)
52
+
53
+ # @!method get_status(options = {})
54
+ # Calls the GetStatus API operation.
55
+ # @param [Hash] options
56
+ # * +:job_id+ - *required* - (String)
57
+ # @return [Core::Response]
58
+ # The #data method of the response object returns
59
+ # a hash with the following structure:
60
+ # * +:job_id+ - (String)
61
+ # * +:job_type+ - (String)
62
+ # * +:aws_shipping_address+ - (String)
63
+ # * +:location_code+ - (String)
64
+ # * +:location_message+ - (String)
65
+ # * +:progress_code+ - (String)
66
+ # * +:progress_message+ - (String)
67
+ # * +:carrier+ - (String)
68
+ # * +:tracking_number+ - (String)
69
+ # * +:log_bucket+ - (String)
70
+ # * +:log_key+ - (String)
71
+ # * +:error_count+ - (Integer)
72
+ # * +:signature+ - (String)
73
+ # * +:signature_file_contents+ - (String)
74
+ # * +:current_manifest+ - (String)
75
+ # * +:creation_date+ - (Time)
76
+
77
+ # @!method list_jobs(options = {})
78
+ # Calls the ListJobs API operation.
79
+ # @param [Hash] options
80
+ # * +:max_jobs+ - (Integer)
81
+ # * +:marker+ - (String)
82
+ # @return [Core::Response]
83
+ # The #data method of the response object returns
84
+ # a hash with the following structure:
85
+ # * +:jobs+ - (Array<Hash>)
86
+ # * +:job_id+ - (String)
87
+ # * +:creation_date+ - (Time)
88
+ # * +:is_canceled+ - (Boolean)
89
+ # * +:job_type+ - (String)
90
+ # * +:is_truncated+ - (Boolean)
91
+
92
+ # @!method update_job(options = {})
93
+ # Calls the UpdateJob API operation.
94
+ # @param [Hash] options
95
+ # * +:job_id+ - *required* - (String)
96
+ # * +:manifest+ - *required* - (String)
97
+ # * +:job_type+ - *required* - (String)
98
+ # * +:validate_only+ - *required* - (Boolean)
99
+ # @return [Core::Response]
100
+ # The #data method of the response object returns
101
+ # a hash with the following structure:
102
+ # * +:success+ - (Boolean)
103
+ # * +:warning_message+ - (String)
104
+
105
+ ## end client methods ##
106
+
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,19 @@
1
+
2
+ # Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # may not use this file except in compliance with the License. A copy of
6
+ # the License is located at
7
+ #
8
+ # http://aws.amazon.com/apache2.0/
9
+ #
10
+ # or in the "license" file accompanying this file. This file is
11
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # ANY KIND, either express or implied. See the License for the specific
13
+ # language governing permissions and limitations under the License.
14
+
15
+ AWS::Core::Configuration.module_eval do
16
+
17
+ add_service 'ImportExport', 'import_export', 'importexport.amazonaws.com'
18
+
19
+ end
@@ -0,0 +1,22 @@
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 ImportExport
16
+ module Errors
17
+
18
+ extend Core::LazyErrorClasses
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
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 ImportExport
16
+
17
+ # @private
18
+ class Request < Core::Http::Request
19
+ include Core::Signature::Version2
20
+ end
21
+
22
+ end
23
+ end
@@ -15,7 +15,7 @@ module AWS
15
15
  class Route53
16
16
 
17
17
  # Client class for Route53.
18
- class Client < Core::RESTClient
18
+ class Client < Core::RESTXMLClient
19
19
 
20
20
  define_client_methods('2012-02-29')
21
21
 
@@ -17,62 +17,74 @@ require 'uuidtools'
17
17
  module AWS
18
18
  class S3
19
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.
20
+ # A lifecycle configuration specify {Rule rules} that manage the way
21
+ # Amazon S3 stores objects. The rules apply to objects whose keys match
22
+ # the rule's prefix.
23
23
  #
24
24
  # == Rules
25
25
  #
26
- # Each lifecycle configuration has a list of rules. Each rule has the
27
- # following attributes:
26
+ # A rule is comprised primarily of an id, prefix and set of
27
+ # configuration options. Configuration options on the rules can specify:
28
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).
29
+ # * When to expire an object
30
+ # * When to transition an object to Glacier
31
+ # * Whether the rule is enabled or disabled
41
32
  #
42
33
  # See {Rule} for more information on all of the attributes and methods
43
34
  # available for rules.
44
35
  #
45
- # == Adding Rules
36
+ # == Expiring Objects
37
+ #
38
+ # You can add a rule to a bucket lifecycle configuration using {#add_rule}
39
+ # inside of an {#update} block that will expire an object after a given
40
+ # number of days:
41
+ #
42
+ # # delete backups after they are 1 year old
43
+ # bucket.lifecycle_configuration.update do
44
+ # add_rule('backups/', :expiration_time => 365)
45
+ # end
46
+ #
47
+ # You can also define the rule to expire objects at a specific date:
48
+ #
49
+ # # delete backups on January 1st of next year
50
+ # bucket.lifecycle_configuration.update do
51
+ # date = Date.new(Time.now.year + 1, 01, 01)
52
+ # add_rule('backups/', :expiration_time => date)
53
+ # end
54
+ #
55
+ # == Transitioning Objects to Glacier
46
56
  #
47
- # You can add a rule to a bucket lifecycle configuration using {#add_rule}.
57
+ # You can add a rule to a bucket lifecycle configuration using {#add_rule}
58
+ # inside of an {#update} block that will transition objects to Glacier
59
+ # after a given number of days:
48
60
  #
49
- # # add a rule that deletes backups after they are 1 year old
61
+ # # move backups to Glacier after 3 days
50
62
  # bucket.lifecycle_configuration.update do
51
- # add_rule('backups/', 365)
63
+ # add_rule('backups/', :glacier_transition_time => 3)
52
64
  # end
53
65
  #
54
- # If you perfer to specify a rule's ID or status (defaults to 'Enabled')
55
- # you can do this with {#add_rule}.
66
+ # You can also define the rule to transition objects at a specific date:
56
67
  #
57
- # # add a rule that deletes backups after they are 1 year old
68
+ # # transition all backups on January 1st of next year
58
69
  # bucket.lifecycle_configuration.update do
59
- # add_rule('backups/', 365, :id => 'backup-rule', :disabled => true
70
+ # date = Date.new(Time.now.year + 1, 01, 01)
71
+ # add_rule('backups/', :glacier_transition_time => date)
60
72
  # end
61
73
  #
62
74
  # == Replacing Rules
63
75
  #
64
76
  # If you prefer to completely replace a lifecycle configuration, call
65
- # {#add_rule} inside a #replace block instead of an #update block:
77
+ # {#add_rule} inside a {#replace} block instead of an +#update+ block:
66
78
  #
67
79
  # # replace all existing rules with the following
68
80
  # bucket.lifecycle_configuration.replace do
69
- # add_rule('backups/', 30)
70
- # add_rule('temp/', 10)
81
+ # add_rule('backups/', :glacier_transition_time => 10)
82
+ # add_rule('temp/', :expiration_time => 30)
71
83
  # end
72
84
  #
73
85
  # == Removing Rules
74
86
  #
75
- # You can delete specific rules with #remove_rule.
87
+ # You can delete specific rules with {#remove_rule}.
76
88
  #
77
89
  # # delete all disabled rules
78
90
  # bucket.lifecycle_configuration.update do
@@ -81,7 +93,7 @@ module AWS
81
93
  # end
82
94
  # end
83
95
  #
84
- # You can also remove all rules in a single call:
96
+ # You can also remove all rules in a single call with {#clear}:
85
97
  #
86
98
  # # remove all rules from this lifecycle configuration
87
99
  # bucket.lifecycle_configuration.clear
@@ -93,12 +105,12 @@ module AWS
93
105
  # # change the expiration days to 10 for EVERY rule
94
106
  # bucket.lifecycle_configuration.update do
95
107
  # rules.each do |rule|
96
- # rule.expiration_days = 10
108
+ # rule.expiration_time = 10
97
109
  # end
98
110
  # end
99
111
  #
100
112
  # Please be aware, if you add, remove or edit rules outside of an
101
- # #update or #replace block, then you must call {#update} yourself
113
+ # {#update} or {#replace} block, then you must call +#update+ yourself
102
114
  # or the changes will not be persisted.
103
115
  #
104
116
  class BucketLifecycleConfiguration
@@ -127,26 +139,39 @@ module AWS
127
139
  end
128
140
  end
129
141
 
130
- # @param [String] prefix
131
- #
132
- # @param [Integer] expiration_days Indicates the lifetime for objects
133
- # matching the given prefix.
142
+ # @overload add_rule(prefix, options = {})
143
+ # @param [String] prefix objects whose keys begin with this prefix
144
+ # will be affected by the rule.
134
145
  #
135
- # @param [Hash] options
146
+ # @option options [String] :id A unique ID for this rule. If an ID
147
+ # is not provided, one will be generated.
136
148
  #
137
- # @option options [String] :id A unique ID for this rule. If an ID
138
- # is not provided, one will be generated.
149
+ # @option options [Boolean] :disabled (false) By default, all rules
150
+ # will have the status of enabled. You can override this default
151
+ # by passing +:disabled+ => true.
139
152
  #
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.
153
+ # @option options [Date, Integer] :expiration_time (nil) Indicates
154
+ # the lifetime for objects matching the given prefix.
143
155
  #
144
- # @return [Rule] Returns the rule that was added, as a {Rule} object.
156
+ # @option options [Date, Integer] :glacier_transition_time (nil)
157
+ # Indicates the time before objects matching the given prefix will
158
+ # be transitioned into the Amazon Glacier storage tier.
145
159
  #
146
- def add_rule prefix, expiration_days, options = {}
160
+ # @return [Rule] Returns the rule that was added, as a {Rule} object.
161
+ def add_rule prefix, expiration_time = nil, options = {}
162
+ if Hash === expiration_time
163
+ options = expiration_time
164
+ else
165
+ options[:expiration_time] = expiration_time
166
+ end
167
+
147
168
  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)
169
+ opts = {
170
+ :status => options[:disabled] == true ? 'Disabled' : 'Enabled',
171
+ :expiration_time => options[:expiration_time],
172
+ :glacier_transition_time => options[:glacier_transition_time]
173
+ }
174
+ rule = Rule.new(self, id, prefix, opts)
150
175
  self.rules << rule
151
176
  rule
152
177
  end
@@ -188,7 +213,7 @@ module AWS
188
213
  # # set the number of days before expiration for all rules to 10
189
214
  # config = bucket.lifecycle_configuration
190
215
  # config.rules.each do |rule|
191
- # rule.expiration_days = 10
216
+ # rule.expiration_time = 10
192
217
  # end
193
218
  # config.update
194
219
  #
@@ -197,7 +222,7 @@ module AWS
197
222
  #
198
223
  # # shorter version of the example above
199
224
  # bucket.lifecycle_configuration.update do
200
- # rules.each {|rule| rule.expiration_days = 10 }
225
+ # rules.each {|rule| rule.expiration_time = 10 }
201
226
  # end
202
227
  #
203
228
  # A block method for updating a BucketLifecycleConfiguration.
@@ -265,8 +290,22 @@ module AWS
265
290
  xml.Prefix rule.prefix
266
291
  xml.Status rule.status
267
292
  xml.Expiration do
268
- xml.Days rule.expiration_days
269
- end
293
+ if Integer === rule.expiration_time
294
+ xml.Days rule.expiration_time
295
+ else
296
+ date = rule.expiration_time.to_s
297
+ xml.Date "#{date}T00:00:00Z"
298
+ end
299
+ end if rule.expiration_time
300
+ xml.Transition do
301
+ xml.StorageClass 'GLACIER'
302
+ if Integer === rule.glacier_transition_time
303
+ xml.Days rule.glacier_transition_time
304
+ else
305
+ date = rule.glacier_transition_time.to_s
306
+ xml.Date "#{date}T00:00:00Z"
307
+ end
308
+ end if rule.glacier_transition_time
270
309
  end
271
310
  end
272
311
  end
@@ -284,13 +323,6 @@ module AWS
284
323
  end
285
324
  end
286
325
 
287
- protected
288
- def parse_xml xml
289
- Client::XML::GetBucketLifecycleConfiguration.parse(xml).rules.map do |r|
290
- Rule.new(self, r.id, r.prefix, r.expiration.days, r.status)
291
- end
292
- end
293
-
294
326
  # Represents a single rule from an Amazon S3 bucket lifecycle
295
327
  # configuration.
296
328
  #
@@ -303,12 +335,21 @@ module AWS
303
335
  #
304
336
  class Rule
305
337
 
306
- def initialize configuration, id, prefix, expiration_days, status
338
+ # @private
339
+ def initialize configuration, id, prefix, expiration_time = nil, status = nil
307
340
  @configuration = configuration
308
341
  @id = id
309
342
  @prefix = prefix
310
- @expiration_days = expiration_days
311
- @status = status
343
+
344
+ if Hash === expiration_time
345
+ options = expiration_time
346
+ options.each do |key, value|
347
+ send("#{key}=", value) if respond_to?("#{key}=")
348
+ end
349
+ else
350
+ self.expiration_time = expiration_time
351
+ self.status = status
352
+ end
312
353
  end
313
354
 
314
355
  # @return [BucketLifecycleConfiguration]
@@ -320,8 +361,30 @@ module AWS
320
361
  # @return [String]
321
362
  attr_accessor :prefix
322
363
 
323
- # @return [Integer]
324
- attr_accessor :expiration_days
364
+ # @return [Date] the date the objects will expire
365
+ # @return [Integer] if the value is an integer, returns the number
366
+ # of days before the object will expire.
367
+ attr_reader :expiration_time
368
+
369
+ # Converts any time values to Date objects
370
+ def expiration_time=(value)
371
+ @expiration_time = convert_time_value(value)
372
+ end
373
+
374
+ alias expiration_days expiration_time
375
+ alias expiration_days= expiration_time=
376
+
377
+ # @return [Date] the date the objects will be
378
+ # transitioned into the Amazon Glacier storage tier.
379
+ # @return [Integer] if the value is an integer, returns the number
380
+ # of days before the object is transitioned into the Amazon Glacier
381
+ # storage tier.
382
+ attr_reader :glacier_transition_time
383
+
384
+ # Converts any time values to Date objects
385
+ def glacier_transition_time=(value)
386
+ @glacier_transition_time = convert_time_value(value)
387
+ end
325
388
 
326
389
  # @return [String] Returns the rule status, 'Enabled' or 'Disabled'
327
390
  attr_accessor :status
@@ -348,11 +411,45 @@ module AWS
348
411
  other.configuration.bucket == configuration.bucket and
349
412
  other.id == id and
350
413
  other.prefix == prefix and
351
- other.expiration_days == expiration_days and
414
+ other.expiration_time == expiration_time and
415
+ other.glacier_transition_time == glacier_transition_time and
352
416
  other.status == status
353
417
  end
354
418
  alias_method :==, :eql?
355
419
 
420
+ private
421
+
422
+ # If an integer, returns the integer as days, otherwise
423
+ # converts any time-like values into Date objects
424
+ # @return [Integer] if the value is an integer
425
+ # @return [Date] if the value is a time-like object
426
+ # @return [nil] if the value is nil
427
+ def convert_time_value(value)
428
+ return nil if value.nil?
429
+ return value if value.is_a?(Integer)
430
+ Date.parse(value.to_s)
431
+ end
432
+
433
+ end
434
+
435
+ protected
436
+
437
+ def parse_xml xml
438
+ Client::XML::GetBucketLifecycleConfiguration.parse(xml).rules.map do |r|
439
+ opts = { :status => r[:status] }
440
+
441
+ if r[:expiration]
442
+ opts[:expiration_time] =
443
+ r[:expiration][:days] || r[:expiration][:date]
444
+ end
445
+
446
+ if r[:transition]
447
+ opts[:glacier_transition_time] =
448
+ r[:transition][:days] || r[:transition][:date]
449
+ end
450
+
451
+ Rule.new(self, r[:id], r[:prefix], opts)
452
+ end
356
453
  end
357
454
 
358
455
  end