aws 2.4.5 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +9 -75
- data/lib/acf/acf_interface.rb +6 -4
- data/lib/aws.rb +2 -1
- data/lib/awsbase/awsbase.rb +98 -65
- data/lib/awsbase/errors.rb +9 -5
- data/lib/awsbase/parsers.rb +226 -226
- data/lib/awsbase/utils.rb +255 -207
- data/lib/ec2/ec2.rb +243 -105
- data/lib/ec2/mon_interface.rb +2 -1
- data/lib/iam/iam.rb +31 -25
- data/lib/right_aws.rb +1 -1
- data/lib/s3/bucket.rb +7 -8
- data/lib/s3/grantee.rb +238 -238
- data/lib/s3/key.rb +281 -281
- data/lib/s3/s3.rb +2 -1
- data/lib/s3/s3_interface.rb +45 -35
- data/lib/sdb/active_sdb.rb +19 -22
- data/lib/sdb/sdb_interface.rb +4 -5
- data/lib/ses/ses.rb +123 -0
- data/lib/sqs/sqs.rb +5 -0
- data/lib/sqs/sqs_interface.rb +3 -3
- metadata +53 -104
- data/lib/awsbase/support.rb +0 -142
- data/test/acf/test_acf.rb +0 -148
- data/test/acf/test_helper.rb +0 -2
- data/test/ec2/test_ec2.rb +0 -205
- data/test/ec2/test_helper.rb +0 -2
- data/test/ec2/test_mon.rb +0 -17
- data/test/elb/test_elb.rb +0 -51
- data/test/http_connection.rb +0 -87
- data/test/iam/test_iam.rb +0 -36
- data/test/rds/test_rds.rb +0 -181
- data/test/s3/s3_test_base.rb +0 -23
- data/test/s3/test_helper.rb +0 -3
- data/test/s3/test_s3.rb +0 -162
- data/test/s3/test_s3_class.rb +0 -179
- data/test/s3/test_s3_rights.rb +0 -139
- data/test/s3/test_s3_stubbed.rb +0 -97
- data/test/sdb/test_active_sdb.rb +0 -338
- data/test/sdb/test_helper.rb +0 -3
- data/test/sdb/test_sdb.rb +0 -220
- data/test/sqs/test_helper.rb +0 -2
- data/test/sqs/test_sqs.rb +0 -232
- data/test/test_credentials.rb +0 -54
- data/test/ts_right_aws.rb +0 -13
data/lib/s3/key.rb
CHANGED
@@ -1,281 +1,281 @@
|
|
1
|
-
module Aws
|
2
|
-
|
3
|
-
|
4
|
-
class S3::Key
|
5
|
-
|
6
|
-
attr_reader :bucket, :name, :last_modified, :e_tag, :size, :storage_class, :owner
|
7
|
-
attr_accessor :headers, :meta_headers
|
8
|
-
attr_writer :data
|
9
|
-
|
10
|
-
# Separate Amazon meta headers from other headers
|
11
|
-
def self.split_meta(headers) #:nodoc:
|
12
|
-
hash = headers.dup
|
13
|
-
meta = {}
|
14
|
-
hash.each do |key, value|
|
15
|
-
if key[/^#{S3Interface::AMAZON_METADATA_PREFIX}/]
|
16
|
-
meta[key.gsub(S3Interface::AMAZON_METADATA_PREFIX, '')] = value
|
17
|
-
hash.delete(key)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
[hash, meta]
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.add_meta_prefix(meta_headers, prefix=S3Interface::AMAZON_METADATA_PREFIX)
|
24
|
-
meta = {}
|
25
|
-
meta_headers.each do |meta_header, value|
|
26
|
-
if meta_header[/#{prefix}/]
|
27
|
-
meta[meta_header] = value
|
28
|
-
else
|
29
|
-
meta["#{S3Interface::AMAZON_METADATA_PREFIX}#{meta_header}"] = value
|
30
|
-
end
|
31
|
-
end
|
32
|
-
meta
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
# Create a new Key instance, but do not create the actual key.
|
37
|
-
# The +name+ is a +String+.
|
38
|
-
# Returns a new Key instance.
|
39
|
-
#
|
40
|
-
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
41
|
-
# key.exists? #=> true | false
|
42
|
-
# key.put('Woohoo!') #=> true
|
43
|
-
# key.exists? #=> true
|
44
|
-
#
|
45
|
-
def self.create(bucket, name, data=nil, meta_headers={})
|
46
|
-
new(bucket, name, data, {}, meta_headers)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Create a new Key instance, but do not create the actual key.
|
50
|
-
# In normal use this method should not be called directly.
|
51
|
-
# Use Aws::S3::Key.create or bucket.key() instead.
|
52
|
-
#
|
53
|
-
def initialize(bucket, name, data=nil, headers={}, meta_headers={},
|
54
|
-
last_modified=nil, e_tag=nil, size=nil, storage_class=nil, owner=nil)
|
55
|
-
raise 'Bucket must be a Bucket instance.' unless bucket.is_a?(S3::Bucket)
|
56
|
-
@bucket = bucket
|
57
|
-
@name = name
|
58
|
-
@data = data
|
59
|
-
@e_tag = e_tag
|
60
|
-
@size = size.to_i
|
61
|
-
@storage_class = storage_class
|
62
|
-
@owner = owner
|
63
|
-
@last_modified = last_modified
|
64
|
-
if @last_modified && !@last_modified.is_a?(Time)
|
65
|
-
@last_modified = Time.parse(@last_modified)
|
66
|
-
end
|
67
|
-
@headers, @meta_headers = self.class.split_meta(headers)
|
68
|
-
@meta_headers.merge!(meta_headers)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Return key name as a String.
|
72
|
-
#
|
73
|
-
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
74
|
-
# puts key #=> 'logs/today/1.log'
|
75
|
-
#
|
76
|
-
def to_s
|
77
|
-
@name.to_s
|
78
|
-
end
|
79
|
-
|
80
|
-
# Return the full S3 path to this key (bucket/key).
|
81
|
-
#
|
82
|
-
# key.full_name #=> 'my_awesome_bucket/cool_key'
|
83
|
-
#
|
84
|
-
def full_name(separator='/')
|
85
|
-
"#{@bucket.to_s}#{separator}#{@name}"
|
86
|
-
end
|
87
|
-
|
88
|
-
# Return a public link to a key.
|
89
|
-
#
|
90
|
-
# key.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket/cool_key'
|
91
|
-
#
|
92
|
-
def public_link
|
93
|
-
params = @bucket.s3.interface.params
|
94
|
-
"#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name('/')}"
|
95
|
-
end
|
96
|
-
|
97
|
-
# Return Key data. Retrieve this data from Amazon if it is the first time call.
|
98
|
-
# TODO TRB 6/19/07 What does the above mean? Clarify.
|
99
|
-
#
|
100
|
-
def data
|
101
|
-
get if !@data and exists?
|
102
|
-
@data
|
103
|
-
end
|
104
|
-
|
105
|
-
# Retrieve object data and attributes from Amazon.
|
106
|
-
# Returns a +String+.
|
107
|
-
#
|
108
|
-
def get(headers={}, &block)
|
109
|
-
response = @bucket.s3.interface.get(@bucket.name, @name, headers, &block)
|
110
|
-
@data = response[:object]
|
111
|
-
@headers, @meta_headers = self.class.split_meta(response[:headers])
|
112
|
-
# refresh(false) Holy moly, this was doing two extra hits to s3 for making 3 hits for every get!!
|
113
|
-
@data
|
114
|
-
end
|
115
|
-
|
116
|
-
# Store object data on S3.
|
117
|
-
# Parameter +data+ is a +String+ or S3Object instance.
|
118
|
-
# Returns +true+.
|
119
|
-
#
|
120
|
-
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
|
121
|
-
# key.data = 'Qwerty'
|
122
|
-
# key.put #=> true
|
123
|
-
# ...
|
124
|
-
# key.put('Olala!') #=> true
|
125
|
-
#
|
126
|
-
def put(data=nil, perms=nil, headers={})
|
127
|
-
headers['x-amz-acl'] = perms if perms
|
128
|
-
@data = data || @data
|
129
|
-
meta = self.class.add_meta_prefix(@meta_headers)
|
130
|
-
@bucket.s3.interface.put(@bucket.name, @name, @data, meta.merge(headers))
|
131
|
-
end
|
132
|
-
|
133
|
-
# Rename an object. Returns new object name.
|
134
|
-
#
|
135
|
-
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
136
|
-
# key.rename('logs/today/2.log') #=> 'logs/today/2.log'
|
137
|
-
# puts key.name #=> 'logs/today/2.log'
|
138
|
-
# key.exists? #=> true
|
139
|
-
#
|
140
|
-
def rename(new_name)
|
141
|
-
@bucket.s3.interface.rename(@bucket.name, @name, new_name)
|
142
|
-
@name = new_name
|
143
|
-
end
|
144
|
-
|
145
|
-
# Create an object copy. Returns a destination Aws::S3::Key instance.
|
146
|
-
#
|
147
|
-
# # Key instance as destination
|
148
|
-
# key1 = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
149
|
-
# key2 = Aws::S3::Key.create(bucket, 'logs/today/2.log') #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
150
|
-
# key1.put('Olala!') #=> true
|
151
|
-
# key1.copy(key2) #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
152
|
-
# key1.exists? #=> true
|
153
|
-
# key2.exists? #=> true
|
154
|
-
# puts key2.data #=> 'Olala!'
|
155
|
-
#
|
156
|
-
# # String as destination
|
157
|
-
# key = Aws::S3::Key.create(bucket, 'logs/today/777.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
158
|
-
# key.put('Olala!') #=> true
|
159
|
-
# new_key = key.copy('logs/today/888.log') #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
160
|
-
# key.exists? #=> true
|
161
|
-
# new_key.exists? #=> true
|
162
|
-
#
|
163
|
-
def copy(new_key_or_name)
|
164
|
-
new_key_or_name = S3::Key.create(@bucket, new_key_or_name.to_s) unless new_key_or_name.is_a?(S3::Key)
|
165
|
-
@bucket.s3.interface.copy(@bucket.name, @name, new_key_or_name.bucket.name, new_key_or_name.name)
|
166
|
-
new_key_or_name
|
167
|
-
end
|
168
|
-
|
169
|
-
# Move an object to other location. Returns a destination Aws::S3::Key instance.
|
170
|
-
#
|
171
|
-
# # Key instance as destination
|
172
|
-
# key1 = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
173
|
-
# key2 = Aws::S3::Key.create(bucket, 'logs/today/2.log') #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
174
|
-
# key1.put('Olala!') #=> true
|
175
|
-
# key1.move(key2) #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
176
|
-
# key1.exists? #=> false
|
177
|
-
# key2.exists? #=> true
|
178
|
-
# puts key2.data #=> 'Olala!'
|
179
|
-
#
|
180
|
-
# # String as destination
|
181
|
-
# key = Aws::S3::Key.create(bucket, 'logs/today/777.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
182
|
-
# key.put('Olala!') #=> true
|
183
|
-
# new_key = key.move('logs/today/888.log') #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
184
|
-
# key.exists? #=> false
|
185
|
-
# new_key.exists? #=> true
|
186
|
-
#
|
187
|
-
def move(new_key_or_name)
|
188
|
-
new_key_or_name = S3::Key.create(@bucket, new_key_or_name.to_s) unless new_key_or_name.is_a?(S3::Key)
|
189
|
-
@bucket.s3.interface.move(@bucket.name, @name, new_key_or_name.bucket.name, new_key_or_name.name)
|
190
|
-
new_key_or_name
|
191
|
-
end
|
192
|
-
|
193
|
-
# Retrieve key info from bucket and update attributes.
|
194
|
-
# Refresh meta-headers (by calling +head+ method) if +head+ is set.
|
195
|
-
# Returns +true+ if the key exists in bucket and +false+ otherwise.
|
196
|
-
#
|
197
|
-
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
|
198
|
-
# key.e_tag #=> nil
|
199
|
-
# key.meta_headers #=> {}
|
200
|
-
# key.refresh #=> true
|
201
|
-
# key.e_tag #=> '12345678901234567890bf11094484b6'
|
202
|
-
# key.meta_headers #=> {"family"=>"qwerty", "name"=>"asdfg"}
|
203
|
-
#
|
204
|
-
def refresh(head=true)
|
205
|
-
new_key = @bucket.key(self)
|
206
|
-
@last_modified = new_key.last_modified
|
207
|
-
@e_tag = new_key.e_tag
|
208
|
-
@size = new_key.size
|
209
|
-
@storage_class = new_key.storage_class
|
210
|
-
@owner = new_key.owner
|
211
|
-
if @last_modified
|
212
|
-
self.head
|
213
|
-
true
|
214
|
-
else
|
215
|
-
@headers = @meta_headers = {}
|
216
|
-
false
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
# Updates headers and meta-headers from S3.
|
221
|
-
# Returns +true+.
|
222
|
-
#
|
223
|
-
# key.meta_headers #=> {"family"=>"qwerty"}
|
224
|
-
# key.head #=> true
|
225
|
-
# key.meta_headers #=> {"family"=>"qwerty", "name"=>"asdfg"}
|
226
|
-
#
|
227
|
-
def head
|
228
|
-
@headers, @meta_headers = self.class.split_meta(@bucket.s3.interface.head(@bucket, @name))
|
229
|
-
true
|
230
|
-
end
|
231
|
-
|
232
|
-
# Reload meta-headers only. Returns meta-headers hash.
|
233
|
-
#
|
234
|
-
# key.reload_meta #=> {"family"=>"qwerty", "name"=>"asdfg"}
|
235
|
-
#
|
236
|
-
def reload_meta
|
237
|
-
@meta_headers = self.class.split_meta(@bucket.s3.interface.head(@bucket, @name)).last
|
238
|
-
end
|
239
|
-
|
240
|
-
# Replace meta-headers by new hash at S3. Returns new meta-headers hash.
|
241
|
-
#
|
242
|
-
# key.reload_meta #=> {"family"=>"qwerty", "name"=>"asdfg"}
|
243
|
-
# key.save_meta #=> {"family"=>"oops", "race" => "troll"}
|
244
|
-
# key.reload_meta #=> {"family"=>"oops", "race" => "troll"}
|
245
|
-
#
|
246
|
-
def save_meta(meta_headers)
|
247
|
-
meta = self.class.add_meta_prefix(meta_headers)
|
248
|
-
@bucket.s3.interface.copy(@bucket.name, @name, @bucket.name, @name, :replace, meta)
|
249
|
-
@meta_headers = self.class.split_meta(meta)[1]
|
250
|
-
end
|
251
|
-
|
252
|
-
# Check for existence of the key in the given bucket.
|
253
|
-
# Returns +true+ or +false+.
|
254
|
-
#
|
255
|
-
# key = Aws::S3::Key.create(bucket,'logs/today/1.log')
|
256
|
-
# key.exists? #=> false
|
257
|
-
# key.put('Woohoo!') #=> true
|
258
|
-
# key.exists? #=> true
|
259
|
-
#
|
260
|
-
def exists?
|
261
|
-
@bucket.key(self).last_modified ? true : false
|
262
|
-
end
|
263
|
-
|
264
|
-
# Remove key from bucket.
|
265
|
-
# Returns +true+.
|
266
|
-
#
|
267
|
-
# key.delete #=> true
|
268
|
-
#
|
269
|
-
def delete
|
270
|
-
raise 'Key name must be specified.' if
|
271
|
-
@bucket.s3.interface.delete(@bucket, @name)
|
272
|
-
end
|
273
|
-
|
274
|
-
# Return a list of grantees.
|
275
|
-
#
|
276
|
-
def grantees
|
277
|
-
|
278
|
-
end
|
279
|
-
|
280
|
-
end
|
281
|
-
end
|
1
|
+
module Aws
|
2
|
+
|
3
|
+
|
4
|
+
class S3::Key
|
5
|
+
|
6
|
+
attr_reader :bucket, :name, :last_modified, :e_tag, :size, :storage_class, :owner
|
7
|
+
attr_accessor :headers, :meta_headers
|
8
|
+
attr_writer :data
|
9
|
+
|
10
|
+
# Separate Amazon meta headers from other headers
|
11
|
+
def self.split_meta(headers) #:nodoc:
|
12
|
+
hash = headers.dup
|
13
|
+
meta = {}
|
14
|
+
hash.each do |key, value|
|
15
|
+
if key[/^#{S3Interface::AMAZON_METADATA_PREFIX}/]
|
16
|
+
meta[key.gsub(S3Interface::AMAZON_METADATA_PREFIX, '')] = value
|
17
|
+
hash.delete(key)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
[hash, meta]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.add_meta_prefix(meta_headers, prefix=S3Interface::AMAZON_METADATA_PREFIX)
|
24
|
+
meta = {}
|
25
|
+
meta_headers.each do |meta_header, value|
|
26
|
+
if meta_header[/#{prefix}/]
|
27
|
+
meta[meta_header] = value
|
28
|
+
else
|
29
|
+
meta["#{S3Interface::AMAZON_METADATA_PREFIX}#{meta_header}"] = value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
meta
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# Create a new Key instance, but do not create the actual key.
|
37
|
+
# The +name+ is a +String+.
|
38
|
+
# Returns a new Key instance.
|
39
|
+
#
|
40
|
+
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
41
|
+
# key.exists? #=> true | false
|
42
|
+
# key.put('Woohoo!') #=> true
|
43
|
+
# key.exists? #=> true
|
44
|
+
#
|
45
|
+
def self.create(bucket, name, data=nil, meta_headers={})
|
46
|
+
new(bucket, name, data, {}, meta_headers)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Create a new Key instance, but do not create the actual key.
|
50
|
+
# In normal use this method should not be called directly.
|
51
|
+
# Use Aws::S3::Key.create or bucket.key() instead.
|
52
|
+
#
|
53
|
+
def initialize(bucket, name, data=nil, headers={}, meta_headers={},
|
54
|
+
last_modified=nil, e_tag=nil, size=nil, storage_class=nil, owner=nil)
|
55
|
+
raise 'Bucket must be a Bucket instance.' unless bucket.is_a?(S3::Bucket)
|
56
|
+
@bucket = bucket
|
57
|
+
@name = name
|
58
|
+
@data = data
|
59
|
+
@e_tag = e_tag
|
60
|
+
@size = size.to_i
|
61
|
+
@storage_class = storage_class
|
62
|
+
@owner = owner
|
63
|
+
@last_modified = last_modified
|
64
|
+
if @last_modified && !@last_modified.is_a?(Time)
|
65
|
+
@last_modified = Time.parse(@last_modified)
|
66
|
+
end
|
67
|
+
@headers, @meta_headers = self.class.split_meta(headers)
|
68
|
+
@meta_headers.merge!(meta_headers)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Return key name as a String.
|
72
|
+
#
|
73
|
+
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
74
|
+
# puts key #=> 'logs/today/1.log'
|
75
|
+
#
|
76
|
+
def to_s
|
77
|
+
@name.to_s
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return the full S3 path to this key (bucket/key).
|
81
|
+
#
|
82
|
+
# key.full_name #=> 'my_awesome_bucket/cool_key'
|
83
|
+
#
|
84
|
+
def full_name(separator='/')
|
85
|
+
"#{@bucket.to_s}#{separator}#{@name}"
|
86
|
+
end
|
87
|
+
|
88
|
+
# Return a public link to a key.
|
89
|
+
#
|
90
|
+
# key.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket/cool_key'
|
91
|
+
#
|
92
|
+
def public_link
|
93
|
+
params = @bucket.s3.interface.params
|
94
|
+
"#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name('/')}"
|
95
|
+
end
|
96
|
+
|
97
|
+
# Return Key data. Retrieve this data from Amazon if it is the first time call.
|
98
|
+
# TODO TRB 6/19/07 What does the above mean? Clarify.
|
99
|
+
#
|
100
|
+
def data
|
101
|
+
get if !@data and exists?
|
102
|
+
@data
|
103
|
+
end
|
104
|
+
|
105
|
+
# Retrieve object data and attributes from Amazon.
|
106
|
+
# Returns a +String+.
|
107
|
+
#
|
108
|
+
def get(headers={}, &block)
|
109
|
+
response = @bucket.s3.interface.get(@bucket.name, @name, headers, &block)
|
110
|
+
@data = response[:object]
|
111
|
+
@headers, @meta_headers = self.class.split_meta(response[:headers])
|
112
|
+
# refresh(false) Holy moly, this was doing two extra hits to s3 for making 3 hits for every get!!
|
113
|
+
@data
|
114
|
+
end
|
115
|
+
|
116
|
+
# Store object data on S3.
|
117
|
+
# Parameter +data+ is a +String+ or S3Object instance.
|
118
|
+
# Returns +true+.
|
119
|
+
#
|
120
|
+
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
|
121
|
+
# key.data = 'Qwerty'
|
122
|
+
# key.put #=> true
|
123
|
+
# ...
|
124
|
+
# key.put('Olala!') #=> true
|
125
|
+
#
|
126
|
+
def put(data=nil, perms=nil, headers={})
|
127
|
+
headers['x-amz-acl'] = perms if perms
|
128
|
+
@data = data || @data
|
129
|
+
meta = self.class.add_meta_prefix(@meta_headers)
|
130
|
+
@bucket.s3.interface.put(@bucket.name, @name, @data, meta.merge(headers))
|
131
|
+
end
|
132
|
+
|
133
|
+
# Rename an object. Returns new object name.
|
134
|
+
#
|
135
|
+
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
136
|
+
# key.rename('logs/today/2.log') #=> 'logs/today/2.log'
|
137
|
+
# puts key.name #=> 'logs/today/2.log'
|
138
|
+
# key.exists? #=> true
|
139
|
+
#
|
140
|
+
def rename(new_name)
|
141
|
+
@bucket.s3.interface.rename(@bucket.name, @name, new_name)
|
142
|
+
@name = new_name
|
143
|
+
end
|
144
|
+
|
145
|
+
# Create an object copy. Returns a destination Aws::S3::Key instance.
|
146
|
+
#
|
147
|
+
# # Key instance as destination
|
148
|
+
# key1 = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
149
|
+
# key2 = Aws::S3::Key.create(bucket, 'logs/today/2.log') #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
150
|
+
# key1.put('Olala!') #=> true
|
151
|
+
# key1.copy(key2) #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
152
|
+
# key1.exists? #=> true
|
153
|
+
# key2.exists? #=> true
|
154
|
+
# puts key2.data #=> 'Olala!'
|
155
|
+
#
|
156
|
+
# # String as destination
|
157
|
+
# key = Aws::S3::Key.create(bucket, 'logs/today/777.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
158
|
+
# key.put('Olala!') #=> true
|
159
|
+
# new_key = key.copy('logs/today/888.log') #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
160
|
+
# key.exists? #=> true
|
161
|
+
# new_key.exists? #=> true
|
162
|
+
#
|
163
|
+
def copy(new_key_or_name)
|
164
|
+
new_key_or_name = S3::Key.create(@bucket, new_key_or_name.to_s) unless new_key_or_name.is_a?(S3::Key)
|
165
|
+
@bucket.s3.interface.copy(@bucket.name, @name, new_key_or_name.bucket.name, new_key_or_name.name)
|
166
|
+
new_key_or_name
|
167
|
+
end
|
168
|
+
|
169
|
+
# Move an object to other location. Returns a destination Aws::S3::Key instance.
|
170
|
+
#
|
171
|
+
# # Key instance as destination
|
172
|
+
# key1 = Aws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
173
|
+
# key2 = Aws::S3::Key.create(bucket, 'logs/today/2.log') #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
174
|
+
# key1.put('Olala!') #=> true
|
175
|
+
# key1.move(key2) #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
176
|
+
# key1.exists? #=> false
|
177
|
+
# key2.exists? #=> true
|
178
|
+
# puts key2.data #=> 'Olala!'
|
179
|
+
#
|
180
|
+
# # String as destination
|
181
|
+
# key = Aws::S3::Key.create(bucket, 'logs/today/777.log') #=> #<Aws::S3::Key:0xb7b1e240 ... >
|
182
|
+
# key.put('Olala!') #=> true
|
183
|
+
# new_key = key.move('logs/today/888.log') #=> #<Aws::S3::Key:0xb7b5e240 ... >
|
184
|
+
# key.exists? #=> false
|
185
|
+
# new_key.exists? #=> true
|
186
|
+
#
|
187
|
+
def move(new_key_or_name)
|
188
|
+
new_key_or_name = S3::Key.create(@bucket, new_key_or_name.to_s) unless new_key_or_name.is_a?(S3::Key)
|
189
|
+
@bucket.s3.interface.move(@bucket.name, @name, new_key_or_name.bucket.name, new_key_or_name.name)
|
190
|
+
new_key_or_name
|
191
|
+
end
|
192
|
+
|
193
|
+
# Retrieve key info from bucket and update attributes.
|
194
|
+
# Refresh meta-headers (by calling +head+ method) if +head+ is set.
|
195
|
+
# Returns +true+ if the key exists in bucket and +false+ otherwise.
|
196
|
+
#
|
197
|
+
# key = Aws::S3::Key.create(bucket, 'logs/today/1.log')
|
198
|
+
# key.e_tag #=> nil
|
199
|
+
# key.meta_headers #=> {}
|
200
|
+
# key.refresh #=> true
|
201
|
+
# key.e_tag #=> '12345678901234567890bf11094484b6'
|
202
|
+
# key.meta_headers #=> {"family"=>"qwerty", "name"=>"asdfg"}
|
203
|
+
#
|
204
|
+
def refresh(head=true)
|
205
|
+
new_key = @bucket.key(self)
|
206
|
+
@last_modified = new_key.last_modified
|
207
|
+
@e_tag = new_key.e_tag
|
208
|
+
@size = new_key.size
|
209
|
+
@storage_class = new_key.storage_class
|
210
|
+
@owner = new_key.owner
|
211
|
+
if @last_modified
|
212
|
+
self.head
|
213
|
+
true
|
214
|
+
else
|
215
|
+
@headers = @meta_headers = {}
|
216
|
+
false
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# Updates headers and meta-headers from S3.
|
221
|
+
# Returns +true+.
|
222
|
+
#
|
223
|
+
# key.meta_headers #=> {"family"=>"qwerty"}
|
224
|
+
# key.head #=> true
|
225
|
+
# key.meta_headers #=> {"family"=>"qwerty", "name"=>"asdfg"}
|
226
|
+
#
|
227
|
+
def head
|
228
|
+
@headers, @meta_headers = self.class.split_meta(@bucket.s3.interface.head(@bucket, @name))
|
229
|
+
true
|
230
|
+
end
|
231
|
+
|
232
|
+
# Reload meta-headers only. Returns meta-headers hash.
|
233
|
+
#
|
234
|
+
# key.reload_meta #=> {"family"=>"qwerty", "name"=>"asdfg"}
|
235
|
+
#
|
236
|
+
def reload_meta
|
237
|
+
@meta_headers = self.class.split_meta(@bucket.s3.interface.head(@bucket, @name)).last
|
238
|
+
end
|
239
|
+
|
240
|
+
# Replace meta-headers by new hash at S3. Returns new meta-headers hash.
|
241
|
+
#
|
242
|
+
# key.reload_meta #=> {"family"=>"qwerty", "name"=>"asdfg"}
|
243
|
+
# key.save_meta #=> {"family"=>"oops", "race" => "troll"}
|
244
|
+
# key.reload_meta #=> {"family"=>"oops", "race" => "troll"}
|
245
|
+
#
|
246
|
+
def save_meta(meta_headers)
|
247
|
+
meta = self.class.add_meta_prefix(meta_headers)
|
248
|
+
@bucket.s3.interface.copy(@bucket.name, @name, @bucket.name, @name, :replace, meta)
|
249
|
+
@meta_headers = self.class.split_meta(meta)[1]
|
250
|
+
end
|
251
|
+
|
252
|
+
# Check for existence of the key in the given bucket.
|
253
|
+
# Returns +true+ or +false+.
|
254
|
+
#
|
255
|
+
# key = Aws::S3::Key.create(bucket,'logs/today/1.log')
|
256
|
+
# key.exists? #=> false
|
257
|
+
# key.put('Woohoo!') #=> true
|
258
|
+
# key.exists? #=> true
|
259
|
+
#
|
260
|
+
def exists?
|
261
|
+
@bucket.key(self).last_modified ? true : false
|
262
|
+
end
|
263
|
+
|
264
|
+
# Remove key from bucket.
|
265
|
+
# Returns +true+.
|
266
|
+
#
|
267
|
+
# key.delete #=> true
|
268
|
+
#
|
269
|
+
def delete
|
270
|
+
raise 'Key name must be specified.' if Aws::Utils.blank?(@name)
|
271
|
+
@bucket.s3.interface.delete(@bucket, @name)
|
272
|
+
end
|
273
|
+
|
274
|
+
# Return a list of grantees.
|
275
|
+
#
|
276
|
+
def grantees
|
277
|
+
S3::Grantee::grantees(self)
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
end
|