Class: Fog::AWS::Storage::Real
- Inherits:
-
Object
- Object
- Fog::AWS::Storage::Real
- Includes:
- CredentialFetcher::ConnectionMethods, DeleteObjectUrl, GetObjectHttpUrl, GetObjectHttpsUrl, GetObjectUrl, HeadObjectUrl, PostObjectHiddenFields, PutObjectUrl, Utils
- Defined in:
- lib/fog/aws/storage.rb,
lib/fog/aws/requests/storage/get_bucket.rb,
lib/fog/aws/requests/storage/get_object.rb,
lib/fog/aws/requests/storage/list_parts.rb,
lib/fog/aws/requests/storage/put_bucket.rb,
lib/fog/aws/requests/storage/put_object.rb,
lib/fog/aws/requests/storage/sync_clock.rb,
lib/fog/aws/requests/storage/copy_object.rb,
lib/fog/aws/requests/storage/get_service.rb,
lib/fog/aws/requests/storage/head_bucket.rb,
lib/fog/aws/requests/storage/head_object.rb,
lib/fog/aws/requests/storage/upload_part.rb,
lib/fog/aws/requests/storage/delete_bucket.rb,
lib/fog/aws/requests/storage/delete_object.rb,
lib/fog/aws/requests/storage/get_bucket_acl.rb,
lib/fog/aws/requests/storage/get_object_acl.rb,
lib/fog/aws/requests/storage/get_object_url.rb,
lib/fog/aws/requests/storage/put_bucket_acl.rb,
lib/fog/aws/requests/storage/put_object_acl.rb,
lib/fog/aws/requests/storage/put_object_url.rb,
lib/fog/aws/requests/storage/get_bucket_cors.rb,
lib/fog/aws/requests/storage/head_object_url.rb,
lib/fog/aws/requests/storage/put_bucket_cors.rb,
lib/fog/aws/requests/storage/upload_part_copy.rb,
lib/fog/aws/requests/storage/delete_object_url.rb,
lib/fog/aws/requests/storage/get_bucket_policy.rb,
lib/fog/aws/requests/storage/put_bucket_policy.rb,
lib/fog/aws/requests/storage/delete_bucket_cors.rb,
lib/fog/aws/requests/storage/get_bucket_logging.rb,
lib/fog/aws/requests/storage/get_bucket_tagging.rb,
lib/fog/aws/requests/storage/get_bucket_website.rb,
lib/fog/aws/requests/storage/get_object_tagging.rb,
lib/fog/aws/requests/storage/get_object_torrent.rb,
lib/fog/aws/requests/storage/put_bucket_logging.rb,
lib/fog/aws/requests/storage/put_bucket_tagging.rb,
lib/fog/aws/requests/storage/put_bucket_website.rb,
lib/fog/aws/requests/storage/put_object_tagging.rb,
lib/fog/aws/requests/storage/get_bucket_location.rb,
lib/fog/aws/requests/storage/get_object_http_url.rb,
lib/fog/aws/requests/storage/get_request_payment.rb,
lib/fog/aws/requests/storage/post_object_restore.rb,
lib/fog/aws/requests/storage/put_request_payment.rb,
lib/fog/aws/requests/storage/delete_bucket_policy.rb,
lib/fog/aws/requests/storage/get_bucket_lifecycle.rb,
lib/fog/aws/requests/storage/get_object_https_url.rb,
lib/fog/aws/requests/storage/put_bucket_lifecycle.rb,
lib/fog/aws/requests/storage/delete_bucket_tagging.rb,
lib/fog/aws/requests/storage/delete_bucket_website.rb,
lib/fog/aws/requests/storage/get_bucket_versioning.rb,
lib/fog/aws/requests/storage/put_bucket_versioning.rb,
lib/fog/aws/requests/storage/abort_multipart_upload.rb,
lib/fog/aws/requests/storage/list_multipart_uploads.rb,
lib/fog/aws/requests/storage/delete_bucket_lifecycle.rb,
lib/fog/aws/requests/storage/delete_multiple_objects.rb,
lib/fog/aws/requests/storage/get_bucket_notification.rb,
lib/fog/aws/requests/storage/put_bucket_notification.rb,
lib/fog/aws/requests/storage/complete_multipart_upload.rb,
lib/fog/aws/requests/storage/initiate_multipart_upload.rb,
lib/fog/aws/requests/storage/post_object_hidden_fields.rb,
lib/fog/aws/requests/storage/get_bucket_object_versions.rb
Defined Under Namespace
Classes: S3Streamer
Instance Attribute Summary
Attributes included from Utils
#disable_content_md5_validation, #max_copy_chunk_size, #max_put_chunk_size, #region
Class Method Summary collapse
-
.conforming_to_us_ascii!(keys, hash) ⇒ Excon::Response
Create an object in an S3 bucket.
Instance Method Summary collapse
-
#abort_multipart_upload(bucket_name, object_name, upload_id) ⇒ Object
Abort a multipart upload.
-
#complete_multipart_upload(bucket_name, object_name, upload_id, parts) ⇒ Excon::Response
Complete a multipart upload.
-
#copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {}) ⇒ Excon::Response
Copy an object from one S3 bucket to another.
-
#delete_bucket(bucket_name) ⇒ Excon::Response
Delete an S3 bucket.
-
#delete_bucket_cors(bucket_name) ⇒ Excon::Response
Deletes the cors configuration information set for the bucket.
-
#delete_bucket_lifecycle(bucket_name) ⇒ Excon::Response
Delete lifecycle configuration for a bucket.
-
#delete_bucket_policy(bucket_name) ⇒ Excon::Response
Delete policy for a bucket.
-
#delete_bucket_tagging(bucket_name) ⇒ Excon::Response
Delete tagging for a bucket.
-
#delete_bucket_website(bucket_name) ⇒ Excon::Response
Delete website configuration for a bucket.
-
#delete_multiple_objects(bucket_name, object_names, options = {}) ⇒ Excon::Response
Delete multiple objects from S3.
-
#delete_object(bucket_name, object_name, options = {}) ⇒ Excon::Response
Delete an object from S3.
-
#get_bucket(bucket_name, options = {}) ⇒ Excon::Response
List information about objects in an S3 bucket.
-
#get_bucket_acl(bucket_name) ⇒ Excon::Response
Get access control list for an S3 bucket.
-
#get_bucket_cors(bucket_name) ⇒ Excon::Response
Gets the CORS configuration for an S3 bucket.
-
#get_bucket_lifecycle(bucket_name) ⇒ Excon::Response
Get bucket lifecycle configuration.
-
#get_bucket_location(bucket_name) ⇒ Excon::Response
Get location constraint for an S3 bucket.
-
#get_bucket_logging(bucket_name) ⇒ Excon::Response
Get logging status for an S3 bucket.
-
#get_bucket_notification(bucket_name) ⇒ Excon::Response
Get bucket notification configuration.
-
#get_bucket_object_versions(bucket_name, options = {}) ⇒ Excon::Response
List information about object versions in an S3 bucket.
-
#get_bucket_policy(bucket_name) ⇒ Excon::Response
Get bucket policy for an S3 bucket.
-
#get_bucket_tagging(bucket_name) ⇒ Excon::Response
Get tags for an S3 bucket.
-
#get_bucket_versioning(bucket_name) ⇒ Excon::Response
Get versioning status for an S3 bucket.
-
#get_bucket_website(bucket_name) ⇒ Excon::Response
Get website configuration for an S3 bucket.
-
#get_object(bucket_name, object_name, options = {}, &block) ⇒ Excon::Response
Get an object from S3.
-
#get_object_acl(bucket_name, object_name, options = {}) ⇒ Excon::Response
Get access control list for an S3 object.
-
#get_object_tagging(bucket_name, object_name) ⇒ Excon::Response
Get tags for an S3 object.
-
#get_object_torrent(bucket_name, object_name) ⇒ Excon::Response
Get torrent for an S3 object.
-
#get_request_payment(bucket_name) ⇒ Excon::Response
Get configured payer for an S3 bucket.
-
#get_service ⇒ Excon::Response
List information about S3 buckets for authorized user.
-
#head_bucket(bucket_name) ⇒ Excon::Response
Get headers for an S3 bucket, used to verify if it exists and if you have permission to access it.
-
#head_object(bucket_name, object_name, options = {}) ⇒ Excon::Response
Get headers for an object from S3.
-
#initialize(options = {}) ⇒ Real
constructor
Initialize connection to S3.
-
#initiate_multipart_upload(bucket_name, object_name, options = {}) ⇒ Excon::Response
Initiate a multipart upload to an S3 bucket.
-
#list_multipart_uploads(bucket_name, options = {}) ⇒ Excon::Response
List multipart uploads for a bucket.
-
#list_parts(bucket_name, object_name, upload_id, options = {}) ⇒ Excon::Response
List parts for a multipart upload.
-
#post_object_restore(bucket_name, object_name, days = 100000) ⇒ Excon::Response
Restore an object from Glacier to its original S3 path.
-
#put_bucket(bucket_name, options = {}) ⇒ Excon::Response
Create an S3 bucket.
-
#put_bucket_acl(bucket_name, acl) ⇒ Object
Change access control list for an S3 bucket.
-
#put_bucket_cors(bucket_name, cors) ⇒ Object
Sets the cors configuration for your bucket.
-
#put_bucket_lifecycle(bucket_name, lifecycle) ⇒ Object
Change lifecycle configuration for an S3 bucket.
-
#put_bucket_logging(bucket_name, logging_status) ⇒ Object
Change logging status for an S3 bucket.
-
#put_bucket_notification(bucket_name, notification) ⇒ Object
Change notification configuration for an S3 bucket.
-
#put_bucket_policy(bucket_name, policy) ⇒ Object
Change bucket policy for an S3 bucket.
-
#put_bucket_tagging(bucket_name, tags) ⇒ Object
Change tag set for an S3 bucket.
-
#put_bucket_versioning(bucket_name, status) ⇒ Object
Change versioning status for an S3 bucket.
-
#put_bucket_website(bucket_name, options, options_to_be_deprecated = {}) ⇒ Object
Change website configuration for an S3 bucket.
- #put_object(bucket_name, object_name, data, options = {}) ⇒ Object
-
#put_object_acl(bucket_name, object_name, acl, options = {}) ⇒ Object
Change access control list for an S3 object.
-
#put_object_tagging(bucket_name, object_name, tags) ⇒ Object
Change tag set for an S3 object.
-
#put_request_payment(bucket_name, payer) ⇒ Object
Change who pays for requests to an S3 bucket.
- #reload ⇒ Object
-
#sync_clock ⇒ Object
Sync clock against S3 to avoid skew errors.
-
#upload_part(bucket_name, object_name, upload_id, part_number, data, options = {}) ⇒ Excon::Response
Upload a part for a multipart upload.
-
#upload_part_copy(target_bucket_name, target_object_name, upload_id, part_number, options = {}) ⇒ Excon::Response
Upload a part for a multipart copy.
Methods included from PostObjectHiddenFields
Methods included from GetObjectHttpsUrl
Methods included from GetObjectHttpUrl
Methods included from DeleteObjectUrl
Methods included from HeadObjectUrl
Methods included from PutObjectUrl
Methods included from GetObjectUrl
Methods included from CredentialFetcher::ConnectionMethods
#refresh_credentials_if_expired
Methods included from Utils
#cdn, #http_url, #https_url, #request_url, #require_mime_types, #signed_url, #url, #validate_chunk_size
Constructor Details
#initialize(options = {}) ⇒ Real
Initialize connection to S3
Notes
options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection
Examples
s3 = Fog::Storage.new(
:provider => "AWS",
:aws_access_key_id => your_aws_access_key_id,
:aws_secret_access_key => your_aws_secret_access_key
)
Parameters
-
options<~Hash> - config arguments for connection. Defaults to {}.
Returns
-
S3 object with connection to aws.
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
# File 'lib/fog/aws/storage.rb', line 548 def initialize(={}) require_mime_types @use_iam_profile = [:use_iam_profile] @instrumentor = [:instrumentor] @instrumentor_name = [:instrumentor_name] || 'fog.aws.storage' @connection_options = DEFAULT_CONNECTION_OPTIONS.merge([:connection_options] || {}) @persistent = .fetch(:persistent, false) @acceleration = .fetch(:acceleration, false) @signature_version = .fetch(:aws_signature_version, 4) @enable_signature_v4_streaming = .fetch(:enable_signature_v4_streaming, false) validate_signature_version! @path_style = [:path_style] || false init_max_put_chunk_size!() init_max_copy_chunk_size!() @disable_content_md5_validation = [:disable_content_md5_validation] || false @region = [:region] || DEFAULT_REGION if @endpoint = [:endpoint] endpoint = URI.parse(@endpoint) @host = endpoint.host @scheme = endpoint.scheme @port = endpoint.port else @host = [:host] || region_to_host(@region) @scheme = [:scheme] || DEFAULT_SCHEME @port = [:port] || DEFAULT_SCHEME_PORT[@scheme] end @host = ACCELERATION_HOST if @acceleration setup_credentials() end |
Class Method Details
.conforming_to_us_ascii!(keys, hash) ⇒ Excon::Response
Create an object in an S3 bucket
34 35 36 37 38 39 40 41 |
# File 'lib/fog/aws/requests/storage/put_object.rb', line 34 def self.conforming_to_us_ascii!(keys, hash) keys.each do |k| v = hash[k] if !v.encode(::Encoding::US_ASCII, :undef => :replace).eql?(v) raise Excon::Errors::BadRequest.new("invalid #{k} header: value must be us-ascii") end end end |
Instance Method Details
#abort_multipart_upload(bucket_name, object_name, upload_id) ⇒ Object
Abort a multipart upload
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/aws/requests/storage/abort_multipart_upload.rb', line 14 def abort_multipart_upload(bucket_name, object_name, upload_id) request({ :expects => 204, :headers => {}, :bucket_name => bucket_name, :object_name => object_name, :method => 'DELETE', :query => {'uploadId' => upload_id} }) end |
#complete_multipart_upload(bucket_name, object_name, upload_id, parts) ⇒ Excon::Response
This request could fail and still return 200 OK, so it’s important that you check the response.
Complete a multipart upload
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/aws/requests/storage/complete_multipart_upload.rb', line 27 def complete_multipart_upload(bucket_name, object_name, upload_id, parts) data = "<CompleteMultipartUpload>" parts.each_with_index do |part, index| data << "<Part>" data << "<PartNumber>#{index + 1}</PartNumber>" data << "<ETag>#{part}</ETag>" data << "</Part>" end data << "</CompleteMultipartUpload>" request({ :body => data, :expects => 200, :headers => { 'Content-Length' => data.length }, :bucket_name => bucket_name, :object_name => object_name, :method => 'POST', :parser => Fog::Parsers::AWS::Storage::CompleteMultipartUpload.new, :query => {'uploadId' => upload_id} }) end |
#copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {}) ⇒ Excon::Response
Copy an object from one S3 bucket to another
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/aws/requests/storage/copy_object.rb', line 30 def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, = {}) headers = { 'x-amz-copy-source' => "/#{source_bucket_name}#{object_to_path(source_object_name)}" }.merge!() request({ :expects => 200, :headers => headers, :bucket_name => target_bucket_name, :object_name => target_object_name, :idempotent => true, :method => 'PUT', :parser => Fog::Parsers::AWS::Storage::CopyObject.new, }) end |
#delete_bucket(bucket_name) ⇒ Excon::Response
Delete an S3 bucket
14 15 16 17 18 19 20 21 |
# File 'lib/fog/aws/requests/storage/delete_bucket.rb', line 14 def delete_bucket(bucket_name) request({ :expects => 204, :headers => {}, :bucket_name => bucket_name, :method => 'DELETE' }) end |
#delete_bucket_cors(bucket_name) ⇒ Excon::Response
Deletes the cors configuration information set for the bucket.
14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/aws/requests/storage/delete_bucket_cors.rb', line 14 def delete_bucket_cors(bucket_name) request({ :expects => 204, :headers => {}, :bucket_name => bucket_name, :method => 'DELETE', :query => {'cors' => nil} }) end |
#delete_bucket_lifecycle(bucket_name) ⇒ Excon::Response
Delete lifecycle configuration for a bucket
14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/aws/requests/storage/delete_bucket_lifecycle.rb', line 14 def delete_bucket_lifecycle(bucket_name) request({ :expects => 204, :headers => {}, :bucket_name => bucket_name, :method => 'DELETE', :query => {'lifecycle' => nil} }) end |
#delete_bucket_policy(bucket_name) ⇒ Excon::Response
Delete policy for a bucket
14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/aws/requests/storage/delete_bucket_policy.rb', line 14 def delete_bucket_policy(bucket_name) request({ :expects => 204, :headers => {}, :bucket_name => bucket_name, :method => 'DELETE', :query => {'policy' => nil} }) end |
#delete_bucket_tagging(bucket_name) ⇒ Excon::Response
Delete tagging for a bucket
14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/aws/requests/storage/delete_bucket_tagging.rb', line 14 def delete_bucket_tagging(bucket_name) request({ :expects => 204, :headers => {}, :bucket_name => bucket_name, :method => 'DELETE', :query => {'tagging' => nil} }) end |
#delete_bucket_website(bucket_name) ⇒ Excon::Response
Delete website configuration for a bucket
14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/aws/requests/storage/delete_bucket_website.rb', line 14 def delete_bucket_website(bucket_name) request({ :expects => 204, :headers => {}, :bucket_name => bucket_name, :method => 'DELETE', :query => {'website' => nil} }) end |
#delete_multiple_objects(bucket_name, object_names, options = {}) ⇒ Excon::Response
For versioned deletes, options should include a version_ids hash, which maps from filename to an array of versions. The semantics are that for each (object_name, version) tuple, the caller must insert the object_name and an associated version (if desired), so for n versions, the object must be inserted n times.
Delete multiple objects from S3
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/aws/requests/storage/delete_multiple_objects.rb', line 33 def delete_multiple_objects(bucket_name, object_names, = {}) headers = .dup data = "<Delete>" data << "<Quiet>true</Quiet>" if headers.delete(:quiet) version_ids = headers.delete('versionId') object_names.each do |object_name| object_version = version_ids.nil? ? nil : version_ids[object_name] if object_version object_version = object_version.is_a?(String) ? [object_version] : object_version object_version.each do |version_id| data << "<Object>" data << "<Key>#{CGI.escapeHTML(object_name)}</Key>" data << "<VersionId>#{CGI.escapeHTML(version_id)}</VersionId>" data << "</Object>" end else data << "<Object>" data << "<Key>#{CGI.escapeHTML(object_name)}</Key>" data << "</Object>" end end data << "</Delete>" headers['Content-Length'] = data.bytesize headers['Content-MD5'] = Base64.encode64(OpenSSL::Digest::MD5.digest(data)). gsub("\n", '') request({ :body => data, :expects => 200, :headers => headers, :bucket_name => bucket_name, :method => 'POST', :parser => Fog::Parsers::AWS::Storage::DeleteMultipleObjects.new, :query => {'delete' => nil} }) end |
#delete_object(bucket_name, object_name, options = {}) ⇒ Excon::Response
Delete an object from S3
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/aws/requests/storage/delete_object.rb', line 15 def delete_object(bucket_name, object_name, = {}) if version_id = .delete('versionId') query = {'versionId' => version_id} else query = {} end headers = request({ :expects => 204, :headers => headers, :bucket_name => bucket_name, :object_name => object_name, :idempotent => true, :method => 'DELETE', :query => query }) end |
#get_bucket(bucket_name, options = {}) ⇒ Excon::Response
List information about objects in an S3 bucket
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fog/aws/requests/storage/get_bucket.rb', line 39 def get_bucket(bucket_name, = {}) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetBucket.new, :query => }) end |
#get_bucket_acl(bucket_name) ⇒ Excon::Response
Get access control list for an S3 bucket
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/aws/requests/storage/get_bucket_acl.rb', line 28 def get_bucket_acl(bucket_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::AccessControlList.new, :query => {'acl' => nil} }) end |
#get_bucket_cors(bucket_name) ⇒ Excon::Response
Gets the CORS configuration for an S3 bucket
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/aws/requests/storage/get_bucket_cors.rb', line 24 def get_bucket_cors(bucket_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::CorsConfiguration.new, :query => {'cors' => nil} }) end |
#get_bucket_lifecycle(bucket_name) ⇒ Excon::Response
Get bucket lifecycle configuration
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/aws/requests/storage/get_bucket_lifecycle.rb', line 21 def get_bucket_lifecycle(bucket_name) request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetBucketLifecycle.new, :query => {'lifecycle' => nil} }) end |
#get_bucket_location(bucket_name) ⇒ Excon::Response
Get location constraint for an S3 bucket
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/aws/requests/storage/get_bucket_location.rb', line 17 def get_bucket_location(bucket_name) request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetBucketLocation.new, :query => {'location' => nil} }) end |
#get_bucket_logging(bucket_name) ⇒ Excon::Response
Get logging status for an S3 bucket
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/aws/requests/storage/get_bucket_logging.rb', line 28 def get_bucket_logging(bucket_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetBucketLogging.new, :query => {'logging' => nil} }) end |
#get_bucket_notification(bucket_name) ⇒ Excon::Response
Get bucket notification configuration
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/aws/requests/storage/get_bucket_notification.rb', line 28 def get_bucket_notification(bucket_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetBucketNotification.new, :query => {'notification' => nil} }) end |
#get_bucket_object_versions(bucket_name, options = {}) ⇒ Excon::Response
List information about object versions in an S3 bucket
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fog/aws/requests/storage/get_bucket_object_versions.rb', line 50 def get_bucket_object_versions(bucket_name, = {}) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetBucketObjectVersions.new, :query => {'versions' => nil}.merge!() }) end |
#get_bucket_policy(bucket_name) ⇒ Excon::Response
Get bucket policy for an S3 bucket
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/aws/requests/storage/get_bucket_policy.rb', line 14 def get_bucket_policy(bucket_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end response = request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :query => {'policy' => nil} }) response.body = Fog::JSON.decode(response.body) unless response.body.nil? end |
#get_bucket_tagging(bucket_name) ⇒ Excon::Response
Get tags for an S3 bucket
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/aws/requests/storage/get_bucket_tagging.rb', line 18 def get_bucket_tagging(bucket_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetBucketTagging.new, :query => {'tagging' => nil} }) end |
#get_bucket_versioning(bucket_name) ⇒ Excon::Response
Get versioning status for an S3 bucket
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/aws/requests/storage/get_bucket_versioning.rb', line 18 def get_bucket_versioning(bucket_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetBucketVersioning.new, :query => {'versioning' => nil} }) end |
#get_bucket_website(bucket_name) ⇒ Excon::Response
Get website configuration for an S3 bucket
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fog/aws/requests/storage/get_bucket_website.rb', line 21 def get_bucket_website(bucket_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetBucketWebsite.new, :query => {'website' => nil} }) end |
#get_object(bucket_name, object_name, options = {}, &block) ⇒ Excon::Response
Get an object from S3
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fog/aws/requests/storage/get_object.rb', line 28 def get_object(bucket_name, object_name, = {}, &block) unless bucket_name raise ArgumentError.new('bucket_name is required') end unless object_name raise ArgumentError.new('object_name is required') end params = { :headers => {} } params[:query] = .delete('query') || {} if version_id = .delete('versionId') params[:query] = params[:query].merge({'versionId' => version_id}) end params[:headers].merge!() if ['If-Modified-Since'] params[:headers]['If-Modified-Since'] = Fog::Time.at(['If-Modified-Since'].to_i).to_date_header end if ['If-Unmodified-Since'] params[:headers]['If-Unmodified-Since'] = Fog::Time.at(['If-Unmodified-Since'].to_i).to_date_header end idempotent = true if block_given? params[:response_block] = Proc.new(&block) idempotent = false end request(params.merge!({ :expects => [ 200, 206 ], :bucket_name => bucket_name, :object_name => object_name, :idempotent => idempotent, :method => 'GET', })) end |
#get_object_acl(bucket_name, object_name, options = {}) ⇒ Excon::Response
Get access control list for an S3 object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fog/aws/requests/storage/get_object_acl.rb', line 31 def get_object_acl(bucket_name, object_name, = {}) unless bucket_name raise ArgumentError.new('bucket_name is required') end unless object_name raise ArgumentError.new('object_name is required') end query = {'acl' => nil} if version_id = .delete('versionId') query['versionId'] = version_id end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :object_name => object_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::AccessControlList.new, :query => query }) end |
#get_object_tagging(bucket_name, object_name) ⇒ Excon::Response
Get tags for an S3 object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/aws/requests/storage/get_object_tagging.rb', line 19 def get_object_tagging(bucket_name, object_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end unless object_name raise ArgumentError.new('object_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :object_name => object_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetObjectTagging.new, :query => {'tagging' => nil} }) end |
#get_object_torrent(bucket_name, object_name) ⇒ Excon::Response
Get torrent for an S3 object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/aws/requests/storage/get_object_torrent.rb', line 25 def get_object_torrent(bucket_name, object_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end unless object_name raise ArgumentError.new('object_name is required') end request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :object_name => object_name, :idempotent => true, :method => 'GET', :query => {'torrent' => nil} }) end |
#get_request_payment(bucket_name) ⇒ Excon::Response
Get configured payer for an S3 bucket
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/aws/requests/storage/get_request_payment.rb', line 17 def get_request_payment(bucket_name) request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetRequestPayment.new, :query => {'requestPayment' => nil} }) end |
#get_service ⇒ Excon::Response
List information about S3 buckets for authorized user
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/aws/requests/storage/get_service.rb', line 20 def get_service request({ :expects => 200, :headers => {}, :host => @host || region_to_host(DEFAULT_REGION), :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::GetService.new }) end |
#head_bucket(bucket_name) ⇒ Excon::Response
Get headers for an S3 bucket, used to verify if it exists and if you have permission to access it
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/aws/requests/storage/head_bucket.rb', line 16 def head_bucket(bucket_name) unless bucket_name raise ArgumentError.new('bucket_name is required') end request({ :expects => 200, :bucket_name => bucket_name, :idempotent => true, :method => 'HEAD', }) end |
#head_object(bucket_name, object_name, options = {}) ⇒ Excon::Response
Get headers for an object from S3
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/aws/requests/storage/head_object.rb', line 27 def head_object(bucket_name, object_name, ={}) unless bucket_name raise ArgumentError.new('bucket_name is required') end unless object_name raise ArgumentError.new('object_name is required') end if version_id = .delete('versionId') query = {'versionId' => version_id} end headers = {} headers['If-Modified-Since'] = Fog::Time.at(['If-Modified-Since'].to_i).to_date_header if ['If-Modified-Since'] headers['If-Unmodified-Since'] = Fog::Time.at(['If-Unmodified-Since'].to_i).to_date_header if ['If-Modified-Since'] headers.merge!() request({ :expects => 200, :headers => headers, :bucket_name => bucket_name, :object_name => object_name, :idempotent => true, :method => 'HEAD', :query => query }) end |
#initiate_multipart_upload(bucket_name, object_name, options = {}) ⇒ Excon::Response
Initiate a multipart upload to an S3 bucket
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/aws/requests/storage/initiate_multipart_upload.rb', line 28 def initiate_multipart_upload(bucket_name, object_name, = {}) request({ :expects => 200, :headers => , :bucket_name => bucket_name, :object_name => object_name, :method => 'POST', :parser => Fog::Parsers::AWS::Storage::InitiateMultipartUpload.new, :query => {'uploads' => nil} }) end |
#list_multipart_uploads(bucket_name, options = {}) ⇒ Excon::Response
List multipart uploads for a bucket
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fog/aws/requests/storage/list_multipart_uploads.rb', line 38 def list_multipart_uploads(bucket_name, = {}) request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::ListMultipartUploads.new, :query => .merge!({'uploads' => nil}) }) end |
#list_parts(bucket_name, object_name, upload_id, options = {}) ⇒ Excon::Response
List parts for a multipart upload
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/aws/requests/storage/list_parts.rb', line 37 def list_parts(bucket_name, object_name, upload_id, = {}) ['uploadId'] = upload_id request({ :expects => 200, :headers => {}, :bucket_name => bucket_name, :object_name => object_name, :idempotent => true, :method => 'GET', :parser => Fog::Parsers::AWS::Storage::ListParts.new, :query => .merge!({'uploadId' => upload_id}) }) end |
#post_object_restore(bucket_name, object_name, days = 100000) ⇒ Excon::Response
Restore an object from Glacier to its original S3 path
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/aws/requests/storage/post_object_restore.rb', line 18 def post_object_restore(bucket_name, object_name, days = 100000) raise ArgumentError.new('bucket_name is required') unless bucket_name raise ArgumentError.new('object_name is required') unless object_name data = '<RestoreRequest xmlns="http://s3.amazonaws.com/doc/2006-3-01"><Days>' + days.to_s + '</Days></RestoreRequest>' headers = {} headers['Content-MD5'] = Base64.encode64(OpenSSL::Digest::MD5.digest(data)).strip headers['Content-Type'] = 'application/xml' headers['Date'] = Fog::Time.now.to_date_header request({ :headers => headers, :bucket_name => bucket_name, :expects => [200, 202, 409], :body => data, :method => 'POST', :query => {'restore' => nil}, :object_name => object_name }) end |
#put_bucket(bucket_name, options = {}) ⇒ Excon::Response
Create an S3 bucket
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fog/aws/requests/storage/put_bucket.rb', line 17 def put_bucket(bucket_name, = {}) if location_constraint = .delete('LocationConstraint') data = <<-DATA <CreateBucketConfiguration> <LocationConstraint>#{location_constraint}</LocationConstraint> </CreateBucketConfiguration> DATA else data = nil end request({ :expects => 200, :body => data, :headers => , :idempotent => true, :bucket_name => bucket_name, :method => 'PUT' }) end |
#put_bucket_acl(bucket_name, acl) ⇒ Object
Change access control list for an S3 bucket
-
acl [String] Permissions, must be in [‘private’, ‘public-read’, ‘public-read-write’, ‘authenticated-read’]
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fog/aws/requests/storage/put_bucket_acl.rb', line 27 def put_bucket_acl(bucket_name, acl) data = "" headers = {} if acl.is_a?(Hash) data = Fog::AWS::Storage.hash_to_acl(acl) else if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl) raise Excon::Errors::BadRequest.new('invalid x-amz-acl') end headers['x-amz-acl'] = acl end headers['Content-MD5'] = Base64.encode64(OpenSSL::Digest::MD5.digest(data)).strip headers['Content-Type'] = 'application/json' headers['Date'] = Fog::Time.now.to_date_header request({ :body => data, :expects => 200, :headers => headers, :bucket_name => bucket_name, :method => 'PUT', :query => {'acl' => nil} }) end |
#put_bucket_cors(bucket_name, cors) ⇒ Object
Sets the cors configuration for your bucket. If the configuration exists, Amazon S3 replaces it.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/aws/requests/storage/put_bucket_cors.rb', line 21 def put_bucket_cors(bucket_name, cors) data = Fog::AWS::Storage.hash_to_cors(cors) headers = {} headers['Content-MD5'] = Base64.encode64(OpenSSL::Digest::MD5.digest(data)).strip headers['Content-Type'] = 'application/json' headers['Date'] = Fog::Time.now.to_date_header request({ :body => data, :expects => 200, :headers => headers, :bucket_name => bucket_name, :method => 'PUT', :query => {'cors' => nil} }) end |
#put_bucket_lifecycle(bucket_name, lifecycle) ⇒ Object
Change lifecycle configuration for an S3 bucket
-
lifecycle [Hash]:
-
Rules [Array] object expire rules
-
ID [String] Unique identifier for the rule
-
Prefix [String] Prefix identifying one or more objects to which the rule applies
-
Enabled [Boolean] if rule is currently being applied
- NoncurrentVersion]Expiration [Hash
-
Container for the object expiration rule.
- Noncurrent]Days [Integer
-
lifetime, in days, of the objects that are subject to the rule
-
Date [Date] Indicates when the specific rule take effect. The date value must conform to the ISO 8601 format. The time is always midnight UTC.
- NoncurrentVersion]Transition [Hash
-
Container for the transition rule that describes when objects transition
to the Glacier storage class
- Noncurrent]Days [Integer
-
lifetime, in days, of the objects that are subject to the rule
-
Date [Date] Indicates when the specific rule take effect. The date value must conform to the ISO 8601 format. The time is always midnight UTC.
-
StorageClass [String] Indicates the Amazon S3 storage class to which you want the object to transition to.
-
-
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/fog/aws/requests/storage/put_bucket_lifecycle.rb', line 28 def put_bucket_lifecycle(bucket_name, lifecycle) builder = Nokogiri::XML::Builder.new do LifecycleConfiguration { lifecycle['Rules'].each do |rule| Rule { ID rule['ID'] Prefix rule['Prefix'] Status rule['Enabled'] ? 'Enabled' : 'Disabled' unless (rule['Expiration'] or rule['Transition'] or rule['NoncurrentVersionExpiration'] or rule['NoncurrentVersionTransition']) Expiration { Days rule['Days'] } else if rule['Expiration'] if rule['Expiration']['Days'] Expiration { Days rule['Expiration']['Days'] } elsif rule['Expiration']['Date'] Expiration { Date rule['Expiration']['Date'].is_a?(Time) ? rule['Expiration']['Date'].utc.iso8601 : Time.parse(rule['Expiration']['Date']).utc.iso8601 } end end if rule['NoncurrentVersionExpiration'] if rule['NoncurrentVersionExpiration']['NoncurrentDays'] NoncurrentVersionExpiration { NoncurrentDays rule['NoncurrentVersionExpiration']['NoncurrentDays'] } elsif rule['NoncurrentVersionExpiration']['Date'] NoncurrentVersionExpiration { if Date rule['NoncurrentVersionExpiration']['Date'].is_a?(Time) rule['NoncurrentVersionExpiration']['Date'].utc.iso8601 else Time.parse(rule['NoncurrentVersionExpiration']['Date']).utc.iso8601 end } end end if rule['Transition'] Transition { if rule['Transition']['Days'] Days rule['Transition']['Days'] elsif rule['Transition']['Date'] Date rule['Transition']['Date'].is_a?(Time) ? time.utc.iso8601 : Time.parse(time).utc.iso8601 end StorageClass rule['Transition']['StorageClass'].nil? ? 'GLACIER' : rule['Transition']['StorageClass'] } end if rule['NoncurrentVersionTransition'] NoncurrentVersionTransition { if rule['NoncurrentVersionTransition']['NoncurrentDays'] NoncurrentDays rule['NoncurrentVersionTransition']['NoncurrentDays'] elsif rule['NoncurrentVersionTransition']['Date'] Date rule['NoncurrentVersionTransition']['Date'].is_a?(Time) ? time.utc.iso8601 : Time.parse(time).utc.iso8601 end StorageClass rule['NoncurrentVersionTransition']['StorageClass'].nil? ? 'GLACIER' : rule['NoncurrentVersionTransition']['StorageClass'] } end end } end } end body = builder.to_xml body.gsub! /<([^<>]+)\/>/, '<\1></\1>' request({ :body => body, :expects => 200, :headers => {'Content-MD5' => Base64.encode64(OpenSSL::Digest::MD5.digest(body)).chomp!, 'Content-Type' => 'application/xml'}, :bucket_name => bucket_name, :method => 'PUT', :query => {'lifecycle' => nil} }) end |
#put_bucket_logging(bucket_name, logging_status) ⇒ Object
Change logging status for an S3 bucket
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fog/aws/requests/storage/put_bucket_logging.rb', line 25 def put_bucket_logging(bucket_name, logging_status) if logging_status['LoggingEnabled'].empty? data = <<-DATA <BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01" /> DATA else data = <<-DATA <BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01"> <LoggingEnabled> <TargetBucket>#{logging_status['LoggingEnabled']['TargetBucket']}</TargetBucket> <TargetPrefix>#{logging_status['LoggingEnabled']['TargetBucket']}</TargetPrefix> <TargetGrants> DATA logging_status['AccessControlList'].each do |grant| data << " <Grant>" type = case grant['Grantee'].keys.sort when ['DisplayName', 'ID'] 'CanonicalUser' when ['EmailAddress'] 'AmazonCustomerByEmail' when ['URI'] 'Group' end data << " <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"#{type}\">" for key, value in grant['Grantee'] data << " <#{key}>#{value}</#{key}>" end data << " </Grantee>" data << " <Permission>#{grant['Permission']}</Permission>" data << " </Grant>" end data << <<-DATA </TargetGrants> </LoggingEnabled> </BucketLoggingStatus> DATA end request({ :body => data, :expects => 200, :headers => {}, :bucket_name => bucket_name, :method => 'PUT', :query => {'logging' => nil} }) end |
#put_bucket_notification(bucket_name, notification) ⇒ Object
Change notification configuration for an S3 bucket
-
notifications [Hash]:
-
Topics [Array] SNS topic configurations for the notification
-
ID [String] Unique identifier for the configuration
-
Topic [String] Amazon SNS topic ARN to which Amazon S3 will publish a message when it detects events of specified type
-
Event [String] Bucket event for which to send notifications
-
-
Queues [Array] SQS queue configurations for the notification
-
ID [String] Unique identifier for the configuration
-
Queue [String] Amazon SQS queue ARN to which Amazon S3 will publish a message when it detects events of specified type
-
Event [String] Bucket event for which to send notifications
-
-
CloudFunctions [Array] AWS Lambda notification configurations
-
ID [String] Unique identifier for the configuration
-
CloudFunction [String] Lambda cloud function ARN that Amazon S3 can invoke when it detects events of the specified type
-
InvocationRole [String] IAM role ARN that Amazon S3 can assume to invoke the specified cloud function on your behalf
-
Event [String] Bucket event for which to send notifications
-
-
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fog/aws/requests/storage/put_bucket_notification.rb', line 25 def put_bucket_notification(bucket_name, notification) builder = Nokogiri::XML::Builder.new do NotificationConfiguration do notification.fetch('Topics', []).each do |topic| TopicConfiguration do Id topic['Id'] Topic topic['Topic'] Event topic['Event'] end end notification.fetch('Queues', []).each do |queue| QueueConfiguration do Id queue['Id'] Queue queue['Queue'] Event queue['Event'] end end notification.fetch('CloudFunctions', []).each do |func| CloudFunctionConfiguration do Id func['Id'] CloudFunction func['CloudFunction'] InvocationRole func['InvocationRole'] Event func['Event'] end end end end body = builder.to_xml body.gsub!(/<([^<>]+)\/>/, '<\1></\1>') request({ :body => body, :expects => 200, :headers => {'Content-MD5' => Base64.encode64(OpenSSL::Digest::MD5.digest(body)).chomp!, 'Content-Type' => 'application/xml'}, :bucket_name => bucket_name, :method => 'PUT', :query => {'notification' => nil} }) end |
#put_bucket_policy(bucket_name, policy) ⇒ Object
Change bucket policy for an S3 bucket
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/aws/requests/storage/put_bucket_policy.rb', line 12 def put_bucket_policy(bucket_name, policy) request({ :body => Fog::JSON.encode(policy), :expects => 204, :headers => {}, :bucket_name => bucket_name, :method => 'PUT', :query => {'policy' => nil} }) end |
#put_bucket_tagging(bucket_name, tags) ⇒ Object
Change tag set for an S3 bucket
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/aws/requests/storage/put_bucket_tagging.rb', line 14 def put_bucket_tagging(bucket_name, ) tagging = .map do |k,v| "<Tag><Key>#{k}</Key><Value>#{v}</Value></Tag>" end.join("\n") data = <<-DATA <Tagging xmlns="http://doc.s3.amazonaws.com/2006-03-01" > <TagSet> #{tagging} </TagSet> </Tagging> DATA request({ :body => data, :expects => 204, :headers => {'Content-MD5' => Base64.encode64(OpenSSL::Digest::MD5.digest(data)).chomp!, 'Content-Type' => 'application/xml'}, :bucket_name => bucket_name, :method => 'PUT', :query => {'tagging' => nil} }) end |
#put_bucket_versioning(bucket_name, status) ⇒ Object
Change versioning status for an S3 bucket
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/aws/requests/storage/put_bucket_versioning.rb', line 12 def put_bucket_versioning(bucket_name, status) data = <<-DATA <VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Status>#{status}</Status> </VersioningConfiguration> DATA request({ :body => data, :expects => 200, :headers => {}, :bucket_name => bucket_name, :method => 'PUT', :query => {'versioning' => nil} }) end |
#put_bucket_website(bucket_name, options, options_to_be_deprecated = {}) ⇒ Object
Change website configuration for an S3 bucket
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/aws/requests/storage/put_bucket_website.rb', line 15 def put_bucket_website(bucket_name, , = {}) ||= {} # Method used to be called with the suffix as the second parameter. Warn user that this is not the case any more and move on if .is_a?(String) Fog::Logger.deprecation("put_bucket_website with #{.class} param is deprecated, use put_bucket_website('#{bucket_name}', :IndexDocument => '#{}') instead [light_black](#{caller.first})[/]") = { :IndexDocument => } end # Parameter renamed from "key" to "ErrorDocument" if [:key] Fog::Logger.deprecation("put_bucket_website with three parameters is deprecated, use put_bucket_website('#{bucket_name}', :ErrorDocument => '#{[:key]}') instead [light_black](#{caller.first})[/]") [:ErrorDocument] = [:key] end .merge!() { |key, o1, o2| o1 } data = "<WebsiteConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">" if [:RedirectAllRequestsTo] # Redirect precludes all other options data << <<-DATA <RedirectAllRequestsTo> <HostName>#{[:RedirectAllRequestsTo]}</HostName> </RedirectAllRequestsTo> DATA else if [:IndexDocument] data << <<-DATA <IndexDocument> <Suffix>#{[:IndexDocument]}</Suffix> </IndexDocument> DATA end if [:ErrorDocument] data << <<-DATA <ErrorDocument> <Key>#{[:ErrorDocument]}</Key> </ErrorDocument> DATA end end data << '</WebsiteConfiguration>' request({ :body => data, :expects => 200, :headers => {}, :bucket_name => bucket_name, :method => 'PUT', :query => {'website' => nil} }) end |
#put_object(bucket_name, object_name, data, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fog/aws/requests/storage/put_object.rb', line 43 def put_object(bucket_name, object_name, data, = {}) data = Fog::Storage.parse_data(data) headers = data[:headers].merge!() self.class.conforming_to_us_ascii! headers.keys.grep(/^x-amz-meta-/), headers request({ :body => data[:body], :expects => 200, :headers => headers, :bucket_name => bucket_name, :object_name => object_name, :idempotent => true, :method => 'PUT', }) end |
#put_object_acl(bucket_name, object_name, acl, options = {}) ⇒ Object
Change access control list for an S3 object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/aws/requests/storage/put_object_acl.rb', line 30 def put_object_acl(bucket_name, object_name, acl, = {}) query = {'acl' => nil} if version_id = .delete('versionId') query['versionId'] = version_id end data = "" headers = {} if acl.is_a?(Hash) data = Fog::AWS::Storage.hash_to_acl(acl) else if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl) raise Excon::Errors::BadRequest.new('invalid x-amz-acl') end headers['x-amz-acl'] = acl end headers['Content-MD5'] = Base64.encode64(OpenSSL::Digest::MD5.digest(data)).strip headers['Content-Type'] = 'application/json' headers['Date'] = Fog::Time.now.to_date_header request({ :body => data, :expects => 200, :headers => headers, :bucket_name => bucket_name, :object_name => object_name, :method => 'PUT', :query => query }) end |
#put_object_tagging(bucket_name, object_name, tags) ⇒ Object
Change tag set for an S3 object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/aws/requests/storage/put_object_tagging.rb', line 16 def put_object_tagging(bucket_name, object_name, ) tagging = .map do |k,v| "<Tag><Key>#{k}</Key><Value>#{v}</Value></Tag>" end.join("\n") data = <<-DATA <Tagging xmlns="http://doc.s3.amazonaws.com/2006-03-01" > <TagSet> #{tagging} </TagSet> </Tagging> DATA request({ :body => data, :expects => 200, :headers => {'Content-MD5' => Base64.encode64(OpenSSL::Digest::MD5.digest(data)).chomp!, 'Content-Type' => 'application/xml'}, :bucket_name => bucket_name, :object_name => object_name, :method => 'PUT', :query => {'tagging' => nil} }) end |
#put_request_payment(bucket_name, payer) ⇒ Object
Change who pays for requests to an S3 bucket
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/aws/requests/storage/put_request_payment.rb', line 12 def put_request_payment(bucket_name, payer) data = <<-DATA <RequestPaymentConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Payer>#{payer}</Payer> </RequestPaymentConfiguration> DATA request({ :body => data, :expects => 200, :headers => {}, :bucket_name => bucket_name, :method => 'PUT', :query => {'requestPayment' => nil} }) end |
#reload ⇒ Object
585 586 587 |
# File 'lib/fog/aws/storage.rb', line 585 def reload @connection.reset if @connection end |
#sync_clock ⇒ Object
Sync clock against S3 to avoid skew errors
7 8 9 10 11 12 13 14 |
# File 'lib/fog/aws/requests/storage/sync_clock.rb', line 7 def sync_clock response = begin Excon.get(sync_clock_url) rescue Excon::Errors::HTTPStatusError => error error.response end Fog::Time.now = Time.parse(response.headers['Date']) end |
#upload_part(bucket_name, object_name, upload_id, part_number, data, options = {}) ⇒ Excon::Response
Upload a part for a multipart upload
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/aws/requests/storage/upload_part.rb', line 21 def upload_part(bucket_name, object_name, upload_id, part_number, data, = {}) data = Fog::Storage.parse_data(data) headers = headers['Content-Length'] = data[:headers]['Content-Length'] request({ :body => data[:body], :expects => 200, :idempotent => true, :headers => headers, :bucket_name => bucket_name, :object_name => object_name, :method => 'PUT', :query => {'uploadId' => upload_id, 'partNumber' => part_number} }) end |
#upload_part_copy(target_bucket_name, target_object_name, upload_id, part_number, options = {}) ⇒ Excon::Response
Upload a part for a multipart copy
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fog/aws/requests/storage/upload_part_copy.rb', line 47 def upload_part_copy(target_bucket_name, target_object_name, upload_id, part_number, = {}) headers = request({ :expects => 200, :idempotent => true, :headers => headers, :bucket_name => target_bucket_name, :object_name => target_object_name, :method => 'PUT', :query => {'uploadId' => upload_id, 'partNumber' => part_number}, :parser => Fog::Parsers::AWS::Storage::UploadPartCopyObject.new, }) end |