aws 2.4.3 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/ec2/ec2.rb +37 -0
  2. data/lib/s3/bucket.rb +267 -265
  3. data/lib/s3/s3_interface.rb +1 -1
  4. metadata +10 -10
data/lib/ec2/ec2.rb CHANGED
@@ -1132,6 +1132,21 @@ module Aws
1132
1132
  on_exception
1133
1133
  end
1134
1134
 
1135
+ # Creates an Amazon EBS-backed AMI from an Amazon EBS-backed instance
1136
+ # Instance must be either the running or stopped state
1137
+ #
1138
+ # ec2.create_image('i-4jhdmaw', 'New image')
1139
+ #
1140
+ def create_image(instance_id, name, description="")
1141
+ link = generate_request("CreateImage",
1142
+ "InstanceId" => instance_id,
1143
+ "Name" => name,
1144
+ "Description" => description)
1145
+ request_info(link, QEc2CreateImageParser.new(:logger => @logger))
1146
+ rescue
1147
+ on_exception
1148
+ end
1149
+
1135
1150
  # Attach the specified EBS volume to a specified instance, exposing the
1136
1151
  # volume using the specified device name.
1137
1152
  #
@@ -1573,6 +1588,10 @@ module Aws
1573
1588
  :ami_launch_index => '',
1574
1589
  :ssh_key_name => '',
1575
1590
  :aws_state => '',
1591
+ :root_device_type => '',
1592
+ :root_device_name => '',
1593
+ :architecture => '',
1594
+ :block_device_mappings => [],
1576
1595
  :aws_product_codes => [],
1577
1596
  :tags => {}}
1578
1597
  end
@@ -1580,6 +1599,12 @@ module Aws
1580
1599
 
1581
1600
  def tagend(name)
1582
1601
  case name
1602
+ when 'rootDeviceType' then
1603
+ @instance[:root_device_type] = @text
1604
+ when 'architecture' then
1605
+ @instance[:architecture] = @text
1606
+ when 'rootDeviceName' then
1607
+ @instance[:root_device_name] = @text
1583
1608
  # reservation
1584
1609
  when 'reservationId' then
1585
1610
  @reservation[:aws_reservation_id] = @text
@@ -1626,6 +1651,10 @@ module Aws
1626
1651
  @tag_key = @text
1627
1652
  when 'value' then
1628
1653
  @tag_value = @text
1654
+ when 'deviceName' then
1655
+ @device_name = @text
1656
+ when 'volumeId' then
1657
+ @volume_id = @text
1629
1658
  when 'state'
1630
1659
  if @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet/item/monitoring' || # DescribeInstances property
1631
1660
  @xmlpath == 'RunInstancesResponse/instancesSet/item/monitoring' # RunInstances property
@@ -1634,6 +1663,8 @@ module Aws
1634
1663
  when 'item'
1635
1664
  if @xmlpath=='DescribeInstancesResponse/reservationSet/item/instancesSet/item/tagSet' # Tags
1636
1665
  @instance[:tags][@tag_key] = @tag_value
1666
+ elsif @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet/item/blockDeviceMapping' # Block device mappings
1667
+ @instance[:block_device_mappings] << { @device_name => @volume_id }
1637
1668
  elsif @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet' || # DescribeInstances property
1638
1669
  @xmlpath == 'RunInstancesResponse/instancesSet' # RunInstances property
1639
1670
  @reservation[:instances_set] << @instance
@@ -1677,6 +1708,12 @@ module Aws
1677
1708
  end
1678
1709
  end
1679
1710
 
1711
+ class QEc2CreateImageParser < AwsParser #:nodoc:
1712
+ def tagend(name)
1713
+ @result = @text if name == 'imageId'
1714
+ end
1715
+ end
1716
+
1680
1717
 
1681
1718
  class QEc2TerminateInstancesParser < AwsParser #:nodoc:
1682
1719
  def tagstart(name, attributes)
data/lib/s3/bucket.rb CHANGED
@@ -1,265 +1,267 @@
1
- module Aws
2
-
3
-
4
- class S3::Bucket
5
- attr_reader :s3, :name, :owner, :creation_date
6
-
7
- # Create a Bucket instance.
8
- # If the bucket does not exist and +create+ is set, a new bucket
9
- # is created on S3. Launching this method with +create+=+true+ may
10
- # affect on the bucket's ACL if the bucket already exists.
11
- # Returns Bucket instance or +nil+ if the bucket does not exist
12
- # and +create+ is not set.
13
- #
14
- # s3 = Aws::S3.new(aws_access_key_id, aws_secret_access_key)
15
- # ...
16
- # bucket1 = Aws::S3::Bucket.create(s3, 'my_awesome_bucket_1')
17
- # bucket1.keys #=> exception here if the bucket does not exists
18
- # ...
19
- # bucket2 = Aws::S3::Bucket.create(s3, 'my_awesome_bucket_2', true)
20
- # bucket2.keys #=> list of keys
21
- # # create a bucket at the European location with public read access
22
- # bucket3 = Aws::S3::Bucket.create(s3,'my-awesome-bucket-3', true, 'public-read', :location => :eu)
23
- #
24
- # see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html
25
- # (section: Canned Access Policies)
26
- #
27
- def self.create(s3, name, create=false, perms=nil, headers={})
28
- s3.bucket(name, create, perms, headers)
29
- end
30
-
31
-
32
- # Create a bucket instance. In normal use this method should
33
- # not be called directly.
34
- # Use Aws::S3::Bucket.create or Aws::S3.bucket instead.
35
- def initialize(s3, name, creation_date=nil, owner=nil)
36
- @s3 = s3
37
- @name = name
38
- @owner = owner
39
- @creation_date = creation_date
40
- if @creation_date && !@creation_date.is_a?(Time)
41
- @creation_date = Time.parse(@creation_date)
42
- end
43
- end
44
-
45
- # Return bucket name as a String.
46
- #
47
- # bucket = Aws::S3.bucket('my_awesome_bucket')
48
- # puts bucket #=> 'my_awesome_bucket'
49
- #
50
- def to_s
51
- @name.to_s
52
- end
53
-
54
- alias_method :full_name, :to_s
55
-
56
- # Return a public link to bucket.
57
- #
58
- # bucket.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket'
59
- #
60
- def public_link
61
- params = @s3.interface.params
62
- "#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name}"
63
- end
64
-
65
- # Returns the bucket location
66
- def location
67
- @location ||= @s3.interface.bucket_location(@name)
68
- end
69
-
70
- # Retrieves the logging configuration for a bucket.
71
- # Returns a hash of {:enabled, :targetbucket, :targetprefix}
72
- #
73
- # bucket.logging_info()
74
- # => {:enabled=>true, :targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/"}
75
- def logging_info
76
- @s3.interface.get_logging_parse(:bucket => @name)
77
- end
78
-
79
- # Enables S3 server access logging on a bucket. The target bucket must have been properly configured to receive server
80
- # access logs.
81
- # Params:
82
- # :targetbucket - either the target bucket object or the name of the target bucket
83
- # :targetprefix - the prefix under which all logs should be stored
84
- #
85
- # bucket.enable_logging(:targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/")
86
- # => true
87
- def enable_logging(params)
88
- AwsUtils.mandatory_arguments([:targetbucket, :targetprefix], params)
89
- AwsUtils.allow_only([:targetbucket, :targetprefix], params)
90
- xmldoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><LoggingEnabled><TargetBucket>#{params[:targetbucket]}</TargetBucket><TargetPrefix>#{params[:targetprefix]}</TargetPrefix></LoggingEnabled></BucketLoggingStatus>"
91
- @s3.interface.put_logging(:bucket => @name, :xmldoc => xmldoc)
92
- end
93
-
94
- # Disables S3 server access logging on a bucket. Takes no arguments.
95
- def disable_logging
96
- xmldoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"></BucketLoggingStatus>"
97
- @s3.interface.put_logging(:bucket => @name, :xmldoc => xmldoc)
98
- end
99
-
100
- # Retrieve a group of keys from Amazon.
101
- # +options+ is a hash: { 'prefix'=>'', 'marker'=>'', 'max-keys'=>5, 'delimiter'=>'' }).
102
- # Retrieves meta-headers information if +head+ it +true+.
103
- # Returns an array of Key instances.
104
- #
105
- # bucket.keys #=> # returns all keys from bucket
106
- # bucket.keys('prefix' => 'logs') #=> # returns all keys that starts with 'logs'
107
- #
108
- def keys(options={}, head=false)
109
- keys_and_service(options, head)[0]
110
- end
111
-
112
- # Same as +keys+ method but return an array of [keys, service_data].
113
- # where +service_data+ is a hash with additional output information.
114
- #
115
- # keys, service = bucket.keys_and_service({'max-keys'=> 2, 'prefix' => 'logs'})
116
- # p keys #=> # 2 keys array
117
- # p service #=> {"max-keys"=>"2", "prefix"=>"logs", "name"=>"my_awesome_bucket", "marker"=>"", "is_truncated"=>true}
118
- #
119
- def keys_and_service(options={}, head=false)
120
- opt = {}; options.each { |key, value| opt[key.to_s] = value }
121
- service_data = {}
122
- thislist = {}
123
- list = []
124
- @s3.interface.incrementally_list_bucket(@name, opt) do |thislist|
125
- thislist[:contents].each do |entry|
126
- owner = S3::Owner.new(entry[:owner_id], entry[:owner_display_name])
127
- key = S3::Key.new(self, entry[:key], nil, {}, {}, entry[:last_modified], entry[:e_tag], entry[:size], entry[:storage_class], owner)
128
- key.head if head
129
- list << key
130
- end
131
- end
132
- thislist.each_key do |key|
133
- service_data[key] = thislist[key] unless (key == :contents || key == :common_prefixes)
134
- end
135
- [list, service_data]
136
- end
137
-
138
- # Retrieve key information from Amazon.
139
- # The +key_name+ is a +String+ or Key instance.
140
- # Retrieves meta-header information if +head+ is +true+.
141
- # Returns new Key instance.
142
- #
143
- # key = bucket.key('logs/today/1.log', true) #=> #<Aws::S3::Key:0xb7b1e240 ... >
144
- # # is the same as:
145
- # key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
146
- # key.head
147
- #
148
- def key(key_name, head=false)
149
- raise 'Key name can not be empty.' if key_name.blank?
150
- key_instance = nil
151
- # if this key exists - find it ....
152
- keys({'prefix'=>key_name}, head).each do |key|
153
- if key.name == key_name.to_s
154
- key_instance = key
155
- break
156
- end
157
- end
158
- # .... else this key is unknown
159
- unless key_instance
160
- key_instance = S3::Key.create(self, key_name.to_s)
161
- end
162
- key_instance
163
- end
164
-
165
- # Store object data.
166
- # The +key+ is a +String+ or Key instance.
167
- # Returns +true+.
168
- #
169
- # bucket.put('logs/today/1.log', 'Olala!') #=> true
170
- #
171
- def put(key, data=nil, meta_headers={}, perms=nil, headers={})
172
- key = S3::Key.create(self, key.to_s, data, meta_headers) unless key.is_a?(S3::Key)
173
- key.put(data, perms, headers)
174
- end
175
-
176
- # Retrieve object data from Amazon.
177
- # The +key+ is a +String+ or Key.
178
- # Returns Key instance.
179
- #
180
- # key = bucket.get('logs/today/1.log') #=>
181
- # puts key.data #=> 'sasfasfasdf'
182
- #
183
- def get(key, headers={})
184
- key = S3::Key.create(self, key.to_s) unless key.is_a?(S3::Key)
185
- key.get(headers)
186
- end
187
-
188
- # Rename object. Returns Aws::S3::Key instance.
189
- #
190
- # new_key = bucket.rename_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
191
- # puts key.name #=> 'logs/today/2.log'
192
- # key.exists? #=> true
193
- #
194
- def rename_key(old_key_or_name, new_name)
195
- old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
196
- old_key_or_name.rename(new_name)
197
- old_key_or_name
198
- end
199
-
200
- # Create an object copy. Returns a destination Aws::S3::Key instance.
201
- #
202
- # new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
203
- # puts key.name #=> 'logs/today/2.log'
204
- # key.exists? #=> true
205
- #
206
- def copy_key(old_key_or_name, new_key_or_name)
207
- old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
208
- old_key_or_name.copy(new_key_or_name)
209
- end
210
-
211
- # Move an object to other location. Returns a destination Aws::S3::Key instance.
212
- #
213
- # new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
214
- # puts key.name #=> 'logs/today/2.log'
215
- # key.exists? #=> true
216
- #
217
- def move_key(old_key_or_name, new_key_or_name)
218
- old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
219
- old_key_or_name.move(new_key_or_name)
220
- end
221
-
222
- # Remove all keys from a bucket.
223
- # Returns +true+.
224
- #
225
- # bucket.clear #=> true
226
- #
227
- def clear
228
- @s3.interface.clear_bucket(@name)
229
- end
230
-
231
- # Delete all keys where the 'folder_key' can be interpreted
232
- # as a 'folder' name.
233
- # Returns an array of string keys that have been deleted.
234
- #
235
- # bucket.keys.map{|key| key.name}.join(', ') #=> 'test, test/2/34, test/3, test1, test1/logs'
236
- # bucket.delete_folder('test') #=> ['test','test/2/34','test/3']
237
- #
238
- def delete_folder(folder, separator='/')
239
- @s3.interface.delete_folder(@name, folder, separator)
240
- end
241
-
242
- # Delete a bucket. Bucket must be empty.
243
- # If +force+ is set, clears and deletes the bucket.
244
- # Returns +true+.
245
- #
246
- # bucket.delete(true) #=> true
247
- #
248
- def delete(force=false)
249
- force ? @s3.interface.force_delete_bucket(@name) : @s3.interface.delete_bucket(@name)
250
- end
251
-
252
- # Deletes an object from s3 in this bucket.
253
- def delete_key(key)
254
- @s3.interface.delete(name, key)
255
- end
256
-
257
- # Return a list of grantees.
258
- #
259
- def grantees
260
- Grantee::grantees(self)
261
- end
262
-
263
- end
264
-
265
- end
1
+ module Aws
2
+
3
+
4
+ class S3::Bucket
5
+ attr_reader :s3, :name, :owner, :creation_date
6
+
7
+ # Create a Bucket instance.
8
+ # If the bucket does not exist and +create+ is set, a new bucket
9
+ # is created on S3. Launching this method with +create+=+true+ may
10
+ # affect on the bucket's ACL if the bucket already exists.
11
+ # Returns Bucket instance or +nil+ if the bucket does not exist
12
+ # and +create+ is not set.
13
+ #
14
+ # s3 = Aws::S3.new(aws_access_key_id, aws_secret_access_key)
15
+ # ...
16
+ # bucket1 = Aws::S3::Bucket.create(s3, 'my_awesome_bucket_1')
17
+ # bucket1.keys #=> exception here if the bucket does not exists
18
+ # ...
19
+ # bucket2 = Aws::S3::Bucket.create(s3, 'my_awesome_bucket_2', true)
20
+ # bucket2.keys #=> list of keys
21
+ # # create a bucket at the European location with public read access
22
+ # bucket3 = Aws::S3::Bucket.create(s3,'my-awesome-bucket-3', true, 'public-read', :location => :eu)
23
+ #
24
+ # see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html
25
+ # (section: Canned Access Policies)
26
+ #
27
+ def self.create(s3, name, create=false, perms=nil, headers={})
28
+ s3.bucket(name, create, perms, headers)
29
+ end
30
+
31
+
32
+ # Create a bucket instance. In normal use this method should
33
+ # not be called directly.
34
+ # Use Aws::S3::Bucket.create or Aws::S3.bucket instead.
35
+ def initialize(s3, name, creation_date=nil, owner=nil)
36
+ @s3 = s3
37
+ @name = name
38
+ @owner = owner
39
+ @creation_date = creation_date
40
+ if @creation_date && !@creation_date.is_a?(Time)
41
+ @creation_date = Time.parse(@creation_date)
42
+ end
43
+ end
44
+
45
+ # Return bucket name as a String.
46
+ #
47
+ # bucket = Aws::S3.bucket('my_awesome_bucket')
48
+ # puts bucket #=> 'my_awesome_bucket'
49
+ #
50
+ def to_s
51
+ @name.to_s
52
+ end
53
+
54
+ alias_method :full_name, :to_s
55
+
56
+ # Return a public link to bucket.
57
+ #
58
+ # bucket.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket'
59
+ #
60
+ def public_link
61
+ params = @s3.interface.params
62
+ "#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name}"
63
+ end
64
+
65
+ # Returns the bucket location
66
+ def location
67
+ @location ||= @s3.interface.bucket_location(@name)
68
+ end
69
+
70
+ # Retrieves the logging configuration for a bucket.
71
+ # Returns a hash of {:enabled, :targetbucket, :targetprefix}
72
+ #
73
+ # bucket.logging_info()
74
+ # => {:enabled=>true, :targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/"}
75
+ def logging_info
76
+ @s3.interface.get_logging_parse(:bucket => @name)
77
+ end
78
+
79
+ # Enables S3 server access logging on a bucket. The target bucket must have been properly configured to receive server
80
+ # access logs.
81
+ # Params:
82
+ # :targetbucket - either the target bucket object or the name of the target bucket
83
+ # :targetprefix - the prefix under which all logs should be stored
84
+ #
85
+ # bucket.enable_logging(:targetbucket=>"mylogbucket", :targetprefix=>"loggylogs/")
86
+ # => true
87
+ def enable_logging(params)
88
+ AwsUtils.mandatory_arguments([:targetbucket, :targetprefix], params)
89
+ AwsUtils.allow_only([:targetbucket, :targetprefix], params)
90
+ xmldoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><LoggingEnabled><TargetBucket>#{params[:targetbucket]}</TargetBucket><TargetPrefix>#{params[:targetprefix]}</TargetPrefix></LoggingEnabled></BucketLoggingStatus>"
91
+ @s3.interface.put_logging(:bucket => @name, :xmldoc => xmldoc)
92
+ end
93
+
94
+ # Disables S3 server access logging on a bucket. Takes no arguments.
95
+ def disable_logging
96
+ xmldoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"></BucketLoggingStatus>"
97
+ @s3.interface.put_logging(:bucket => @name, :xmldoc => xmldoc)
98
+ end
99
+
100
+ # Retrieve a group of keys from Amazon.
101
+ # +options+ is a hash: { 'prefix'=>'', 'marker'=>'', 'max-keys'=>5, 'delimiter'=>'' }).
102
+ # Retrieves meta-headers information if +head+ it +true+.
103
+ # Returns an array of Key instances.
104
+ #
105
+ # bucket.keys #=> # returns all keys from bucket
106
+ # bucket.keys('prefix' => 'logs') #=> # returns all keys that starts with 'logs'
107
+ #
108
+ def keys(options={}, head=false)
109
+ keys_and_service(options, head)[0]
110
+ end
111
+
112
+ # Same as +keys+ method but return an array of [keys, service_data].
113
+ # where +service_data+ is a hash with additional output information.
114
+ #
115
+ # keys, service = bucket.keys_and_service({'max-keys'=> 2, 'prefix' => 'logs'})
116
+ # p keys #=> # 2 keys array
117
+ # p service #=> {"max-keys"=>"2", "prefix"=>"logs", "name"=>"my_awesome_bucket", "marker"=>"", "is_truncated"=>true}
118
+ #
119
+ def keys_and_service(options={}, head=false)
120
+ opt = {}; options.each { |key, value| opt[key.to_s] = value }
121
+ service_data = {}
122
+ service_list = {}
123
+ thislist = {}
124
+ list = []
125
+ @s3.interface.incrementally_list_bucket(@name, opt) do |thislist|
126
+ service_list = thislist
127
+ thislist[:contents].each do |entry|
128
+ owner = S3::Owner.new(entry[:owner_id], entry[:owner_display_name])
129
+ key = S3::Key.new(self, entry[:key], nil, {}, {}, entry[:last_modified], entry[:e_tag], entry[:size], entry[:storage_class], owner)
130
+ key.head if head
131
+ list << key
132
+ end
133
+ end
134
+ service_list.each_key do |key|
135
+ service_data[key] = service_list[key] unless (key == :contents || key == :common_prefixes)
136
+ end
137
+ [list, service_data]
138
+ end
139
+
140
+ # Retrieve key information from Amazon.
141
+ # The +key_name+ is a +String+ or Key instance.
142
+ # Retrieves meta-header information if +head+ is +true+.
143
+ # Returns new Key instance.
144
+ #
145
+ # key = bucket.key('logs/today/1.log', true) #=> #<Aws::S3::Key:0xb7b1e240 ... >
146
+ # # is the same as:
147
+ # key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
148
+ # key.head
149
+ #
150
+ def key(key_name, head=false)
151
+ raise 'Key name can not be empty.' if key_name.blank?
152
+ key_instance = nil
153
+ # if this key exists - find it ....
154
+ keys({'prefix'=>key_name}, head).each do |key|
155
+ if key.name == key_name.to_s
156
+ key_instance = key
157
+ break
158
+ end
159
+ end
160
+ # .... else this key is unknown
161
+ unless key_instance
162
+ key_instance = S3::Key.create(self, key_name.to_s)
163
+ end
164
+ key_instance
165
+ end
166
+
167
+ # Store object data.
168
+ # The +key+ is a +String+ or Key instance.
169
+ # Returns +true+.
170
+ #
171
+ # bucket.put('logs/today/1.log', 'Olala!') #=> true
172
+ #
173
+ def put(key, data=nil, meta_headers={}, perms=nil, headers={})
174
+ key = S3::Key.create(self, key.to_s, data, meta_headers) unless key.is_a?(S3::Key)
175
+ key.put(data, perms, headers)
176
+ end
177
+
178
+ # Retrieve object data from Amazon.
179
+ # The +key+ is a +String+ or Key.
180
+ # Returns Key instance.
181
+ #
182
+ # key = bucket.get('logs/today/1.log') #=>
183
+ # puts key.data #=> 'sasfasfasdf'
184
+ #
185
+ def get(key, headers={})
186
+ key = S3::Key.create(self, key.to_s) unless key.is_a?(S3::Key)
187
+ key.get(headers)
188
+ end
189
+
190
+ # Rename object. Returns Aws::S3::Key instance.
191
+ #
192
+ # new_key = bucket.rename_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
193
+ # puts key.name #=> 'logs/today/2.log'
194
+ # key.exists? #=> true
195
+ #
196
+ def rename_key(old_key_or_name, new_name)
197
+ old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
198
+ old_key_or_name.rename(new_name)
199
+ old_key_or_name
200
+ end
201
+
202
+ # Create an object copy. Returns a destination Aws::S3::Key instance.
203
+ #
204
+ # new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
205
+ # puts key.name #=> 'logs/today/2.log'
206
+ # key.exists? #=> true
207
+ #
208
+ def copy_key(old_key_or_name, new_key_or_name)
209
+ old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
210
+ old_key_or_name.copy(new_key_or_name)
211
+ end
212
+
213
+ # Move an object to other location. Returns a destination Aws::S3::Key instance.
214
+ #
215
+ # new_key = bucket.copy_key('logs/today/1.log','logs/today/2.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
216
+ # puts key.name #=> 'logs/today/2.log'
217
+ # key.exists? #=> true
218
+ #
219
+ def move_key(old_key_or_name, new_key_or_name)
220
+ old_key_or_name = S3::Key.create(self, old_key_or_name.to_s) unless old_key_or_name.is_a?(S3::Key)
221
+ old_key_or_name.move(new_key_or_name)
222
+ end
223
+
224
+ # Remove all keys from a bucket.
225
+ # Returns +true+.
226
+ #
227
+ # bucket.clear #=> true
228
+ #
229
+ def clear
230
+ @s3.interface.clear_bucket(@name)
231
+ end
232
+
233
+ # Delete all keys where the 'folder_key' can be interpreted
234
+ # as a 'folder' name.
235
+ # Returns an array of string keys that have been deleted.
236
+ #
237
+ # bucket.keys.map{|key| key.name}.join(', ') #=> 'test, test/2/34, test/3, test1, test1/logs'
238
+ # bucket.delete_folder('test') #=> ['test','test/2/34','test/3']
239
+ #
240
+ def delete_folder(folder, separator='/')
241
+ @s3.interface.delete_folder(@name, folder, separator)
242
+ end
243
+
244
+ # Delete a bucket. Bucket must be empty.
245
+ # If +force+ is set, clears and deletes the bucket.
246
+ # Returns +true+.
247
+ #
248
+ # bucket.delete(true) #=> true
249
+ #
250
+ def delete(force=false)
251
+ force ? @s3.interface.force_delete_bucket(@name) : @s3.interface.delete_bucket(@name)
252
+ end
253
+
254
+ # Deletes an object from s3 in this bucket.
255
+ def delete_key(key)
256
+ @s3.interface.delete(name, key)
257
+ end
258
+
259
+ # Return a list of grantees.
260
+ #
261
+ def grantees
262
+ Grantee::grantees(self)
263
+ end
264
+
265
+ end
266
+
267
+ end
@@ -1249,7 +1249,7 @@ module Aws
1249
1249
  class S3HttpResponseBodyParser < S3HttpResponseParser # :nodoc:
1250
1250
  def parse(response)
1251
1251
  x = response.body
1252
- x.force_encoding("UTF-8")
1252
+ x= x.respond_to?(:force_encoding) ? x.force_encoding("UTF-8") : x
1253
1253
  # puts 'x.encoding = ' + response.body.encoding.to_s
1254
1254
  @result = {
1255
1255
  :object => x,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,12 +11,12 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-02-24 00:00:00.000000000 -08:00
14
+ date: 2011-02-25 00:00:00.000000000 -08:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: uuidtools
19
- requirement: &27201060 !ruby/object:Gem::Requirement
19
+ requirement: &28505268 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *27201060
27
+ version_requirements: *28505268
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: http_connection
30
- requirement: &27200772 !ruby/object:Gem::Requirement
30
+ requirement: &28504980 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '0'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *27200772
38
+ version_requirements: *28504980
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: xml-simple
41
- requirement: &27200484 !ruby/object:Gem::Requirement
41
+ requirement: &28504692 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0'
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *27200484
49
+ version_requirements: *28504692
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: activesupport
52
- requirement: &27200196 !ruby/object:Gem::Requirement
52
+ requirement: &28504404 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: '0'
58
58
  type: :runtime
59
59
  prerelease: false
60
- version_requirements: *27200196
60
+ version_requirements: *28504404
61
61
  description: AWS Ruby Library for interfacing with Amazon Web Services including EC2,
62
62
  S3, SQS, SimpleDB and most of their other services as well. By http://www.appoxy.com
63
63
  email: travis@appoxy.com