Class: AWS::S3::Client
Overview
Client class for Amazon Simple Storage Service (S3).
Defined Under Namespace
Modules: Validators
Constant Summary
collapse
- API_VERSION =
'2006-03-01'
- XMLNS =
"http://s3.amazonaws.com/doc/#{API_VERSION}/"
Instance Attribute Summary
Attributes inherited from Core::Client
#config, #http_read_timeout
Instance Method Summary
collapse
Methods included from Validators
dns_compatible_bucket_name?, json_validation_message, path_style_bucket_name?, require_acl!, require_bucket_name!, require_part_number!, require_policy!, require_upload_id!, set_body_stream_and_content_length, valid_bucket_name?, validate!, validate_bucket_name!, validate_key!, validate_parts!
escape, escape_path
#initialize, #log_warning, #operations, operations, #with_http_handler, #with_options
Instance Method Details
#abort_multipart_upload(options = {}) ⇒ Core::Response
1261
1262
1263
1264
1265
1266
1267
|
# File 'lib/aws/s3/client.rb', line 1261
object_method(:abort_multipart_upload, :delete) do
configure_request do |req, options|
require_upload_id!(options[:upload_id])
super(req, options)
req.add_param('uploadId', options[:upload_id])
end
end
|
#complete_multipart_upload(options = {}) ⇒ Core::Response
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
|
# File 'lib/aws/s3/client.rb', line 1228
object_method(:complete_multipart_upload, :post,
XML::CompleteMultipartUpload) do
configure_request do |req, options|
require_upload_id!(options[:upload_id])
validate_parts!(options[:parts])
super(req, options)
req.add_param('uploadId', options[:upload_id])
parts_xml = options[:parts].map do |part|
"<Part>"+
"<PartNumber>#{part[:part_number].to_i}</PartNumber>"+
"<ETag>#{REXML::Text.normalize(part[:etag].to_s)}</ETag>"+
"</Part>"
end.join
req.body =
"<CompleteMultipartUpload>#{parts_xml}</CompleteMultipartUpload>"
end
process_response do |resp|
(resp)
end
simulate_response do |response|
response.data = {}
end
end
|
#copy_object(options = {}) ⇒ Core::Response
Copies an object from one key to another.
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
|
# File 'lib/aws/s3/client.rb', line 1321
object_method(:copy_object, :put, :header_options => {
:website_redirect_location => 'x-amz-website-redirect-location',
:acl => 'x-amz-acl',
:grant_read => 'x-amz-grant-read',
:grant_write => 'x-amz-grant-write',
:grant_read_acp => 'x-amz-grant-read-acp',
:grant_write_acp => 'x-amz-grant-write-acp',
:grant_full_control => 'x-amz-grant-full-control',
:copy_source => 'x-amz-copy-source',
:cache_control => 'Cache-Control',
:metadata_directive => 'x-amz-metadata-directive',
:content_type => 'Content-Type',
:content_disposition => 'Content-Disposition',
:expires => 'Expires',
}) do
configure_request do |req, options|
validate!(:copy_source, options[:copy_source]) do
"may not be blank" if options[:copy_source].to_s.empty?
end
options = options.merge(:copy_source => escape_path(options[:copy_source]))
super(req, options)
req.metadata = options[:metadata]
req.storage_class = options[:storage_class]
req.server_side_encryption = options[:server_side_encryption]
if options[:version_id]
req.['x-amz-copy-source'] += "?versionId=#{options[:version_id]}"
end
end
process_response do |resp|
(resp)
end
end
|
#create_bucket(options = {}) ⇒ Core::Response
Also known as:
put_bucket
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/aws/s3/client.rb', line 131
bucket_method(:create_bucket, :put, :header_options => {
:acl => 'x-amz-acl',
:grant_read => 'x-amz-grant-read',
:grant_write => 'x-amz-grant-write',
:grant_read_acp => 'x-amz-grant-read-acp',
:grant_write_acp => 'x-amz-grant-write-acp',
:grant_full_control => 'x-amz-grant-full-control',
}) do
configure_request do |req, options|
validate_bucket_name!(options[:bucket_name])
if location = options[:location_constraint]
xmlns = "http://s3.amazonaws.com/doc/#{API_VERSION}/"
req.body = <<-XML
<CreateBucketConfiguration xmlns="#{xmlns}">
<LocationConstraint>#{location}</LocationConstraint>
</CreateBucketConfiguration>
XML
end
super(req, options)
end
end
|
#delete_bucket(options = {}) ⇒ Core::Response
241
|
# File 'lib/aws/s3/client.rb', line 241
bucket_method(:delete_bucket, :delete)
|
#delete_bucket_cors(options = {}) ⇒ Core::Response
385
386
387
388
389
390
|
# File 'lib/aws/s3/client.rb', line 385
bucket_method(:delete_bucket_cors, :delete) do
configure_request do |req, options|
req.add_param('cors')
super(req, options)
end
end
|
#delete_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response
282
283
284
285
286
287
288
289
|
# File 'lib/aws/s3/client.rb', line 282
bucket_method(:delete_bucket_lifecycle_configuration, :delete) do
configure_request do |req, options|
req.add_param('lifecycle')
super(req, options)
end
end
|
#delete_bucket_policy(options = {}) ⇒ Core::Response
Deletes the access policy for a bucket.
507
|
# File 'lib/aws/s3/client.rb', line 507
bucket_method(:delete_bucket_policy, :delete, 'policy')
|
#delete_bucket_tagging(options = {}) ⇒ Core::Response
444
445
446
447
448
449
|
# File 'lib/aws/s3/client.rb', line 444
bucket_method(:delete_bucket_tagging, :delete) do
configure_request do |req, options|
req.add_param('tagging')
super(req, options)
end
end
|
#delete_bucket_website(options = {}) ⇒ Core::Response
234
|
# File 'lib/aws/s3/client.rb', line 234
bucket_method(:delete_bucket_website, :delete, 'website')
|
#delete_object(options = {}) ⇒ Core::Response
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
|
# File 'lib/aws/s3/client.rb', line 996
object_method(:delete_object, :delete, :header_options => { :mfa => "x-amz-mfa" }) do
configure_request do |req, options|
super(req, options)
if options[:version_id]
req.add_param('versionId', options[:version_id])
end
end
process_response do |resp|
resp.data[:version_id] = resp.http_response.('x-amz-version-id')
end
end
|
#delete_objects(options = {}) ⇒ Core::Response
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
|
# File 'lib/aws/s3/client.rb', line 1157
bucket_method(:delete_objects, :post, 'delete', XML::DeleteObjects, :header_options => { :mfa => "x-amz-mfa" }) do
configure_request do |req, options|
super(req, options)
quiet = options.key?(:quiet) ? options[:quiet] : true
keys = options[:objects] || options[:keys]
objects = keys.inject('') do |xml,o|
xml << "<Object><Key>#{REXML::Text.normalize(o[:key])}</Key>"
xml << "<VersionId>#{o[:version_id]}</VersionId>" if o[:version_id]
xml << "</Object>"
end
xml = '<?xml version="1.0" encoding="UTF-8"?>'
xml << "<Delete><Quiet>#{quiet}</Quiet>#{objects}</Delete>"
req.body = xml
req.['content-md5'] = md5(xml)
end
end
|
#get_bucket_acl(options = {}) ⇒ Core::Response
Gets the access control list for a bucket.
673
|
# File 'lib/aws/s3/client.rb', line 673
bucket_method(:get_bucket_acl, :get, 'acl', XML::GetBucketAcl)
|
#get_bucket_cors(options = {}) ⇒ Core::Response
368
369
370
371
372
373
374
375
376
377
378
379
|
# File 'lib/aws/s3/client.rb', line 368
bucket_method(:get_bucket_cors, :get) do
configure_request do |req, options|
req.add_param('cors')
super(req, options)
end
process_response do |resp|
resp.data = XML::GetBucketCors.parse(resp.http_response.body)
end
end
|
#get_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/aws/s3/client.rb', line 264
bucket_method(:get_bucket_lifecycle_configuration, :get) do
configure_request do |req, options|
req.add_param('lifecycle')
super(req, options)
end
process_response do |resp|
xml = resp.http_response.body
resp.data = XML::GetBucketLifecycleConfiguration.parse(xml)
end
end
|
#get_bucket_location(options = {}) ⇒ Core::Response
Gets the bucket's location constraint.
545
546
547
548
549
550
551
552
553
|
# File 'lib/aws/s3/client.rb', line 545
bucket_method(:get_bucket_location, :get, 'location') do
process_response do |response|
regex = />(.*)<\/LocationConstraint>/
matches = response.http_response.body.to_s.match(regex)
response.data[:location_constraint] = matches ? matches[1] : nil
end
end
|
#get_bucket_policy(options = {}) ⇒ Core::Response
Gets the access policy for a bucket.
494
495
496
497
498
499
500
|
# File 'lib/aws/s3/client.rb', line 494
bucket_method(:get_bucket_policy, :get, 'policy') do
process_response do |resp|
resp.data[:policy] = resp.http_response.body
end
end
|
#get_bucket_tagging(options = {}) ⇒ Core::Response
427
428
429
430
431
432
433
434
435
436
437
438
|
# File 'lib/aws/s3/client.rb', line 427
bucket_method(:get_bucket_tagging, :get) do
configure_request do |req, options|
req.add_param('tagging')
super(req, options)
end
process_response do |resp|
resp.data = XML::GetBucketTagging.parse(resp.http_response.body)
end
end
|
#get_bucket_versioning(options = {}) ⇒ Core::Response
559
560
|
# File 'lib/aws/s3/client.rb', line 559
bucket_method(:get_bucket_versioning, :get, 'versioning',
XML::GetBucketVersioning)
|
#get_bucket_website(options = {}) ⇒ Core::Response
228
|
# File 'lib/aws/s3/client.rb', line 228
bucket_method(:get_bucket_website, :get, 'website', XML::GetBucketWebsite)
|
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
|
# File 'lib/aws/s3/client.rb', line 928
object_method(:get_object, :get,
:header_options => {
:if_modified_since => "If-Modified-Since",
:if_unmodified_since => "If-Unmodified-Since",
:if_match => "If-Match",
:if_none_match => "If-None-Match"
}) do
configure_request do |req, options|
super(req, options)
if options[:version_id]
req.add_param('versionId', options[:version_id])
end
["If-Modified-Since",
"If-Unmodified-Since"].each do ||
case value = req.[]
when DateTime
req.[] = Time.parse(value.to_s).rfc2822
when Time
req.[] = value.rfc2822
end
end
if options[:range]
range = options[:range]
range = "bytes=#{range.first}-#{range.last}" if range.is_a?(Range)
req.['Range'] = range
end
end
process_response do |resp|
(resp)
resp.data[:data] = resp.http_response.body
end
end
|
#get_object_acl(options = {}) ⇒ Core::Response
Gets the access control list for an object.
767
|
# File 'lib/aws/s3/client.rb', line 767
object_method(:get_object_acl, :get, 'acl', XML::GetBucketAcl)
|
#head_object(options = {}) ⇒ Core::Response
974
975
976
977
978
979
980
981
982
983
984
985
986
987
|
# File 'lib/aws/s3/client.rb', line 974
object_method(:head_object, :head) do
configure_request do |req, options|
super(req, options)
if options[:version_id]
req.add_param('versionId', options[:version_id])
end
end
process_response do |resp|
(resp)
end
end
|
#initiate_multipart_upload(options = {}) ⇒ Core::Response
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
|
# File 'lib/aws/s3/client.rb', line 1095
object_method(:initiate_multipart_upload, :post, 'uploads',
XML::InitiateMultipartUpload,
:header_options => {
:website_redirect_location => 'x-amz-website-redirect-location',
:acl => 'x-amz-acl',
:grant_read => 'x-amz-grant-read',
:grant_write => 'x-amz-grant-write',
:grant_read_acp => 'x-amz-grant-read-acp',
:grant_write_acp => 'x-amz-grant-write-acp',
:grant_full_control => 'x-amz-grant-full-control',
:cache_control => 'Cache-Control',
:content_disposition => 'Content-Disposition',
:content_encoding => 'Content-Encoding',
:content_type => 'Content-Type',
:expires => 'Expires',
}) do
configure_request do |req, options|
req.metadata = options[:metadata]
req.storage_class = options[:storage_class]
req.server_side_encryption = options[:server_side_encryption]
super(req, options)
end
process_response do |resp|
(resp)
end
end
|
#list_buckets(options = {}) ⇒ Core::Response
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
# File 'lib/aws/s3/client.rb', line 454
add_client_request_method(:list_buckets) do
configure_request do |req, options|
req.http_method = "GET"
end
process_response do |resp|
resp.data = XML::ListBuckets.parse(resp.http_response.body)
end
simulate_response do |resp|
resp.data = Core::XML::Parser.new(XML::ListBuckets.rules).simulate
end
end
|
#list_multipart_uploads(options = {}) ⇒ Core::Response
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
|
# File 'lib/aws/s3/client.rb', line 1135
bucket_method(:list_multipart_uploads,
:get, 'uploads',
XML::ListMultipartUploads) do
configure_request do |req, options|
super(req, options)
params = %w(delimiter key_marker max_keys) +
%w(upload_id_marker max_uploads prefix)
params.each do |param|
if options[param.to_sym]
req.add_param(param.gsub(/_/, '-'), options[param.to_sym])
end
end
end
end
|
#list_object_versions(options = {}) ⇒ Core::Response
571
572
573
574
575
576
577
578
579
580
581
582
583
584
|
# File 'lib/aws/s3/client.rb', line 571
bucket_method(:list_object_versions, :get, 'versions',
XML::ListObjectVersions) do
configure_request do |req, options|
super(req, options)
params = %w(delimiter key_marker max_keys prefix version_id_marker)
params.each do |param|
if options[param.to_sym]
req.add_param(param.gsub(/_/, '-'), options[param.to_sym])
end
end
end
end
|
#list_objects(options = {}) ⇒ Core::Response
Also known as:
get_bucket
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
|
# File 'lib/aws/s3/client.rb', line 1050
bucket_method(:list_objects, :get, XML::ListObjects) do
configure_request do |req, options|
super(req, options)
params = %w(delimiter marker max_keys prefix)
params.each do |param|
if options[param.to_sym]
req.add_param(param.gsub(/_/, '-'), options[param.to_sym])
end
end
end
end
|
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
|
# File 'lib/aws/s3/client.rb', line 1277
object_method(:list_parts, :get, XML::ListParts) do
configure_request do |req, options|
require_upload_id!(options[:upload_id])
super(req, options)
req.add_param('uploadId', options[:upload_id])
req.add_param('max-parts', options[:max_parts])
req.add_param('part-number-marker', options[:part_number_marker])
end
end
|
#put_bucket_acl(options = {}) ⇒ Core::Response
Also known as:
set_bucket_acl
Sets the access control list for a bucket. You must specify an ACL
via one of the following methods:
- as a canned ACL (via
:acl)
- as a list of grants (via the
:grant_* options)
- as an access control policy document (via
:access_control_policy)
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
|
# File 'lib/aws/s3/client.rb', line 648
bucket_method(:put_bucket_acl, :put, 'acl', :header_options => {
:acl => 'x-amz-acl',
:grant_read => 'x-amz-grant-read',
:grant_write => 'x-amz-grant-write',
:grant_read_acp => 'x-amz-grant-read-acp',
:grant_write_acp => 'x-amz-grant-write-acp',
:grant_full_control => 'x-amz-grant-full-control',
}) do
configure_request do |req, options|
move_access_control_policy(options)
require_acl!(options)
super(req, options)
req.body = options[:access_control_policy] if
options[:access_control_policy]
end
end
|
#put_bucket_cors(options = {}) ⇒ Core::Response
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
# File 'lib/aws/s3/client.rb', line 320
bucket_method(:put_bucket_cors, :put) do
configure_request do |req, options|
req.add_param('cors')
xml = Nokogiri::XML::Builder.new do |xml|
xml.CORSConfiguration do
options[:rules].each do |rule|
xml.CORSRule do
xml.ID(rule[:id]) if rule[:id]
(rule[:allowed_methods] || []).each do |method|
xml.AllowedMethod(method)
end
(rule[:allowed_origins] || []).each do |origin|
xml.AllowedOrigin(origin)
end
(rule[:allowed_headers] || []).each do ||
xml.AllowedHeader()
end
xml.MaxAgeSeconds(rule[:max_age_seconds]) if
rule[:max_age_seconds]
(rule[:expose_headers] || []).each do ||
xml.ExposeHeader()
end
end
end
end
end.doc.root.to_xml
req.body = xml
req.['content-md5'] = md5(xml)
super(req, options)
end
end
|
#put_bucket_tagging(options = {}) ⇒ Core::Response
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
# File 'lib/aws/s3/client.rb', line 397
bucket_method(:put_bucket_tagging, :put) do
configure_request do |req, options|
req.add_param('tagging')
xml = Nokogiri::XML::Builder.new
xml.Tagging do |xml|
xml.TagSet do
options[:tags].each_pair do |key,value|
xml.Tag do
xml.Key(key)
xml.Value(value)
end
end
end
end
xml = xml.doc.root.to_xml
req.body = xml
req.['content-md5'] = md5(xml)
super(req, options)
end
end
|
#put_bucket_website(options = {}) ⇒ Core::Response
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/aws/s3/client.rb', line 161
bucket_method(:put_bucket_website, :put, 'website') do
configure_request do |req, options|
validate_bucket_name!(options[:bucket_name])
req.body = Nokogiri::XML::Builder.new do |xml|
xml.WebsiteConfiguration(:xmlns => XMLNS) do
if redirect = options[:redirect_all_requests_to]
xml.RedirectAllRequestsTo do
xml.HostName(redirect[:host_name])
xml.Protocol(redirect[:protocol]) if redirect[:protocol]
end
end
if indx = options[:index_document]
xml.IndexDocument do
xml.Suffix(indx[:suffix])
end
end
if err = options[:error_document]
xml.ErrorDocument do
xml.Key(err[:key])
end
end
if rules = options[:routing_rules]
xml.RoutingRules do
rules.each do |rule|
xml.RoutingRule do
redirect = rule[:redirect]
xml.Redirect do
xml.Protocol(redirect[:protocol]) if redirect[:protocol]
xml.HostName(redirect[:host_name]) if redirect[:host_name]
xml.ReplaceKeyPrefixWith(redirect[:replace_key_prefix_with]) if redirect[:replace_key_prefix_with]
xml.ReplaceKeyWith(redirect[:replace_key_with]) if redirect[:replace_key_with]
xml.HttpRedirectCode(redirect[:http_redirect_code]) if redirect[:http_redirect_code]
end
if condition = rule[:condition]
xml.Condition do
xml.KeyPrefixEquals(condition[:key_prefix_equals]) if condition[:key_prefix_equals]
xml.HttpErrorCodeReturnedEquals(condition[:http_error_code_returned_equals]) if condition[:http_error_code_returned_equals]
end
end
end
end
end
end
end
end.doc.root.to_xml
super(req, options)
end
end
|
Puts data into an object, replacing the current contents.
s3_client.put_object({
:bucket_name => 'bucket-name',
:key => 'readme.txt',
:data => 'This is the readme for ...',
})
In block form, this method yields a stream to the block that
accepts data chunks. For example:
s3_client.put_object(
:bucket_name => 'mybucket',
:key => 'some/key'
:content_length => File.size('myfile')
) do |buffer|
File.open('myfile') do |io|
buffer.write(io.read(length)) until io.eof?
end
end
This form is useful if you need finer control over how
potentially large amounts of data are read from another
source before being sent to S3; for example, if you are
using a non-blocking IO model and reading from a large file
on disk or from another network stream. Some HTTP handlers
do not support streaming request bodies, so if you plan to
upload large objects using this interface you should make
sure the HTTP handler you configure for the client meets
your needs.
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
|
# File 'lib/aws/s3/client.rb', line 860
object_method(:put_object, :put, :header_options => {
:website_redirect_location => 'x-amz-website-redirect-location',
:acl => 'x-amz-acl',
:grant_read => 'x-amz-grant-read',
:grant_write => 'x-amz-grant-write',
:grant_read_acp => 'x-amz-grant-read-acp',
:grant_write_acp => 'x-amz-grant-write-acp',
:grant_full_control => 'x-amz-grant-full-control',
:content_md5 => 'Content-MD5',
:cache_control => 'Cache-Control',
:content_disposition => 'Content-Disposition',
:content_encoding => 'Content-Encoding',
:content_type => 'Content-Type',
:expires => 'Expires',
}) do
configure_request do |request, options|
options = compute_write_options(options)
set_body_stream_and_content_length(request, options)
request.metadata = options[:metadata]
request.storage_class = options[:storage_class]
request.server_side_encryption = options[:server_side_encryption]
super(request, options)
end
process_response do |resp|
(resp)
end
simulate_response do |response|
response.data[:etag] = 'abc123'
response.data[:version_id] = nil
end
end
|
#put_object_acl(options = {}) ⇒ Core::Response
Also known as:
set_object_acl
Sets the access control list for an object. You must specify an ACL
via one of the following methods:
- as a canned ACL (via
:acl)
- as a list of grants (via the
:grant_* options)
- as an access control policy document (via
:access_control_policy)
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
# File 'lib/aws/s3/client.rb', line 741
object_method(:put_object_acl, :put, 'acl', :header_options => {
:acl => 'x-amz-acl',
:grant_read => 'x-amz-grant-read',
:grant_write => 'x-amz-grant-write',
:grant_read_acp => 'x-amz-grant-read-acp',
:grant_write_acp => 'x-amz-grant-write-acp',
:grant_full_control => 'x-amz-grant-full-control',
}) do
configure_request do |req, options|
move_access_control_policy(options)
require_acl!(options)
super(req, options)
req.body = options[:access_control_policy] if
options[:access_control_policy]
end
end
|
#restore_object(options = {}) ⇒ Core::Response
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
|
# File 'lib/aws/s3/client.rb', line 1020
object_method(:restore_object, :post, 'restore',
:header_options => { :content_md5 => 'Content-MD5' }) do
configure_request do |req, options|
super(req, options)
validate!(:days, options[:days]) do
"must be greater or equal to 1" if options[:days].to_i <= 0
end
xml = Nokogiri::XML::Builder.new do |xml|
xml.RestoreRequest('xmlns' => XMLNS) do
xml.Days(options[:days].to_i) if options[:days]
end
end.doc.root.to_xml
req.body = xml
req.['content-type'] = 'application/xml'
req.['content-md5'] = md5(xml)
end
end
|
#set_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response
248
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/aws/s3/client.rb', line 248
bucket_method(:set_bucket_lifecycle_configuration, :put) do
configure_request do |req, options|
xml = options[:lifecycle_configuration]
req.add_param('lifecycle')
req.body = xml
req.['content-md5'] = md5(xml)
super(req, options)
end
end
|
#set_bucket_policy(options = {}) ⇒ Core::Response
Sets the access policy for a bucket.
477
478
479
480
481
482
483
484
485
486
487
|
# File 'lib/aws/s3/client.rb', line 477
bucket_method(:set_bucket_policy, :put, 'policy') do
configure_request do |req, options|
require_policy!(options[:policy])
super(req, options)
policy = options[:policy]
policy = policy.to_json unless policy.respond_to?(:to_str)
req.body = policy
end
end
|
#set_bucket_versioning(options = {}) ⇒ Core::Response
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
|
# File 'lib/aws/s3/client.rb', line 516
bucket_method(:set_bucket_versioning, :put, 'versioning', :header_options => { :mfa => "x-amz-mfa" }) do
configure_request do |req, options|
state = options[:state].to_s.downcase.capitalize
unless state =~ /^(Enabled|Suspended)$/
raise ArgumentError, "invalid versioning state `#{state}`"
end
mfa_delete = options[:mfa_delete].to_s.downcase.capitalize if options[:mfa_delete]
req.body = Nokogiri::XML::Builder.new do |xml|
xml.VersioningConfiguration('xmlns' => XMLNS) do
xml.Status(state)
xml.MfaDelete(mfa_delete) if mfa_delete
end
end.doc.root.to_xml
super(req, options)
end
end
|
#upload_part(options = {}) ⇒ Core::Response
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
|
# File 'lib/aws/s3/client.rb', line 1193
object_method(:upload_part, :put,
:header_options => {
:content_md5 => 'Content-MD5'
}) do
configure_request do |request, options|
options = compute_write_options(options)
set_body_stream_and_content_length(request, options)
require_upload_id!(options[:upload_id])
request.add_param('uploadId', options[:upload_id])
require_part_number!(options[:part_number])
request.add_param('partNumber', options[:part_number])
super(request, options)
end
process_response do |resp|
(resp)
end
simulate_response do |response|
response.data[:etag] = 'abc123'
end
end
|