Class: Fog::Storage::AWS::Real

Inherits:
Object
  • Object
show all
Includes:
AWS::CredentialFetcher::ConnectionMethods, GetObjectHttpUrl, GetObjectHttpsUrl, GetObjectUrl, 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_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/put_bucket_cors.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_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/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/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

Instance Attribute Summary

Attributes included from Utils

#region

Instance Method Summary collapse

Methods included from GetObjectHttpsUrl

#get_object_https_url

Methods included from GetObjectHttpUrl

#get_object_http_url

Methods included from PutObjectUrl

#put_object_url

Methods included from GetObjectUrl

#get_object_url

Methods included from AWS::CredentialFetcher::ConnectionMethods

#refresh_credentials_if_expired

Methods included from Utils

#cdn, #http_url, #https_url, #request_url, #signed_url, #url

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.



412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/fog/aws/storage.rb', line 412

def initialize(options={})
  require 'fog/core/parser'

  @use_iam_profile = options[:use_iam_profile]
  setup_credentials(options)
  @connection_options     = options[:connection_options] || {}
  @persistent = options.fetch(:persistent, false)

  @path_style = options[:path_style]  || false

  if @endpoint = options[:endpoint]
    endpoint = URI.parse(@endpoint)
    @host = endpoint.host
    @scheme = endpoint.scheme
    @port = endpoint.port
  else
    @region     = options[:region]      || DEFAULT_REGION
    @host       = options[:host]        || region_to_host(@region)
    @scheme     = options[:scheme]      || DEFAULT_SCHEME
    @port       = options[:port]        || DEFAULT_SCHEME_PORT[@scheme]
  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

Note:

This request could fail and still return 200 OK, so it’s important that you check the response.

Complete a multipart upload



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/aws/requests/storage/complete_multipart_upload.rb', line 28

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::Storage::AWS::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

Options Hash (options):

  • x-amz-metadata-directive (String)

    Specifies whether to copy metadata from source or replace with data in request. Must be in [‘COPY’, ‘REPLACE’]

  • x-amz-copy_source-if-match (String)

    Copies object if its etag matches this value

  • x-amz-copy_source-if-modified_since (Time)

    Copies object it it has been modified since this time

  • x-amz-copy_source-if-none-match (String)

    Copies object if its etag does not match this value

  • x-amz-copy_source-if-unmodified-since (Time)

    Copies object it it has not been modified since this time

  • x-amz-storage-class (String)

    Default is ‘STANDARD’, set to ‘REDUCED_REDUNDANCY’ for non-critical, reproducable data

See Also:



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/aws/requests/storage/copy_object.rb', line 31

def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
  headers = { 'x-amz-copy-source' => "/#{source_bucket_name}/#{CGI.escape(source_object_name)}" }.merge!(options)
  request({
    :expects  => 200,
    :headers  => headers,
    :bucket_name => target_bucket_name,
    :object_name => target_object_name,
    :method   => 'PUT',
    :parser   => Fog::Parsers::Storage::AWS::CopyObject.new,
  })
end

#delete_bucket(bucket_name) ⇒ Excon::Response

Delete an S3 bucket



15
16
17
18
19
20
21
22
# File 'lib/fog/aws/requests/storage/delete_bucket.rb', line 15

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.



15
16
17
18
19
20
21
22
23
# File 'lib/fog/aws/requests/storage/delete_bucket_cors.rb', line 15

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



15
16
17
18
19
20
21
22
23
# File 'lib/fog/aws/requests/storage/delete_bucket_lifecycle.rb', line 15

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



15
16
17
18
19
20
21
22
23
# File 'lib/fog/aws/requests/storage/delete_bucket_policy.rb', line 15

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



15
16
17
18
19
20
21
22
23
# File 'lib/fog/aws/requests/storage/delete_bucket_tagging.rb', line 15

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



15
16
17
18
19
20
21
22
23
# File 'lib/fog/aws/requests/storage/delete_bucket_website.rb', line 15

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

Note:

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



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/delete_multiple_objects.rb', line 34

def delete_multiple_objects(bucket_name, object_names, options = {})
  headers = options.dup
  data = "<Delete>"
  data << "<Quiet>true</Quiet>" if headers.delete(:quiet)
  version_ids = headers.delete('versionId')
  object_names.each do |object_name|
    data << "<Object>"
    data << "<Key>#{CGI.escapeHTML(object_name)}</Key>"
    object_version = version_ids.nil? ? nil : version_ids[object_name]
    if object_version
      data << "<VersionId>#{CGI.escapeHTML(object_version)}</VersionId>"
    end
    data << "</Object>"
  end
  data << "</Delete>"

  headers['Content-Length'] = data.length
  headers['Content-MD5'] = Base64.encode64(Digest::MD5.digest(data)).
                           gsub("\n", '')

  request({
    :body       => data,
    :expects    => 200,
    :headers    => headers,
    :bucket_name => bucket_name,
    :method     => 'POST',
    :parser     => Fog::Parsers::Storage::AWS::DeleteMultipleObjects.new,
    :query      => {'delete' => nil}
  })
end

#delete_object(bucket_name, object_name, options = {}) ⇒ Excon::Response

Delete an object from S3



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 16

def delete_object(bucket_name, object_name, options = {})
  if version_id = options.delete('versionId')
    path = "#{CGI.escape(object_name)}?versionId=#{CGI.escape(version_id)}"
  else
    path = CGI.escape(object_name)
  end

  headers = options
  request({
    :expects    => 204,
    :headers    => headers,
    :bucket_name => bucket_name,
    :idempotent => true,
    :method     => 'DELETE',
    :path       => path
  })
end

#get_bucket(bucket_name, options = {}) ⇒ Excon::Response

List information about objects in an S3 bucket

Options Hash (options):

  • delimiter (String)

    causes keys with the same string between the prefix value and the first occurence of delimiter to be rolled up

  • marker (String)

    limits object keys to only those that appear lexicographically after its value.

  • max-keys (Integer)

    limits number of object keys returned

  • prefix (String)

    limits object keys to those beginning with its value.

See Also:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fog/aws/requests/storage/get_bucket.rb', line 40

def get_bucket(bucket_name, options = {})
  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::Storage::AWS::GetBucket.new,
    :query    => options
  })
end

#get_bucket_acl(bucket_name) ⇒ Excon::Response

Get access control list for an S3 bucket



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/aws/requests/storage/get_bucket_acl.rb', line 29

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::Storage::AWS::AccessControlList.new,
    :query      => {'acl' => nil}
  })
end

#get_bucket_cors(bucket_name) ⇒ Excon::Response

Gets the CORS configuration for an S3 bucket



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/aws/requests/storage/get_bucket_cors.rb', line 25

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::Storage::AWS::CorsConfiguration.new,
    :query      => {'cors' => nil}
  })
end

#get_bucket_lifecycle(bucket_name) ⇒ Excon::Response

Get bucket lifecycle configuration



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/aws/requests/storage/get_bucket_lifecycle.rb', line 22

def get_bucket_lifecycle(bucket_name)
  request({
            :expects  => 200,
            :headers  => {},
            :bucket_name => bucket_name,
            :idempotent => true,
            :method   => 'GET',
            :parser   => Fog::Parsers::Storage::AWS::GetBucketLifecycle.new,
            :query    => {'lifecycle' => nil}
          })
end

#get_bucket_location(bucket_name) ⇒ Excon::Response

Get location constraint for an S3 bucket



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/aws/requests/storage/get_bucket_location.rb', line 18

def get_bucket_location(bucket_name)
  request({
    :expects  => 200,
    :headers  => {},
    :bucket_name => bucket_name,
    :idempotent => true,
    :method   => 'GET',
    :parser   => Fog::Parsers::Storage::AWS::GetBucketLocation.new,
    :query    => {'location' => nil}
  })
end

#get_bucket_logging(bucket_name) ⇒ Excon::Response

Get logging status for an S3 bucket



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/aws/requests/storage/get_bucket_logging.rb', line 29

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::Storage::AWS::GetBucketLogging.new,
    :query      => {'logging' => nil}
  })
end

#get_bucket_object_versions(bucket_name, options = {}) ⇒ Excon::Response

List information about object versions in an S3 bucket

Options Hash (options):

  • delimiter (String)

    causes keys with the same string between the prefix value and the first occurence of delimiter to be rolled up

  • key-marker (String)

    limits object keys to only those that appear lexicographically after its value.

  • max-keys (Integer)

    limits number of object keys returned

  • prefix (String)

    limits object keys to those beginning with its value.

  • version-id-marker (String)

    limits object versions to only those that appear lexicographically after its value

See Also:



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fog/aws/requests/storage/get_bucket_object_versions.rb', line 51

def get_bucket_object_versions(bucket_name, options = {})
  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::Storage::AWS::GetBucketObjectVersions.new,
    :query    => {'versions' => nil}.merge!(options)          })
end

#get_bucket_policy(bucket_name) ⇒ Excon::Response

Get bucket policy for an S3 bucket



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/aws/requests/storage/get_bucket_policy.rb', line 15

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/aws/requests/storage/get_bucket_tagging.rb', line 19

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::Storage::AWS::GetBucketTagging.new,
    :query      => {'tagging' => nil}
  })
end

#get_bucket_versioning(bucket_name) ⇒ Excon::Response

Get versioning status for an S3 bucket



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/aws/requests/storage/get_bucket_versioning.rb', line 19

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::Storage::AWS::GetBucketVersioning.new,
    :query      => {'versioning' => nil}
  })
end

#get_bucket_website(bucket_name) ⇒ Excon::Response

Get website configuration for an S3 bucket



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/aws/requests/storage/get_bucket_website.rb', line 22

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::Storage::AWS::GetBucketWebsite.new,
    :query      => {'website' => nil}
  })
end

#get_object(bucket_name, object_name, options = {}, &block) ⇒ Excon::Response

Get an object from S3

Options Hash (options):

  • If-Match (String)

    Returns object only if its etag matches this value, otherwise returns 412 (Precondition Failed).

  • If-Modified-Since (Time)

    Returns object only if it has been modified since this time, otherwise returns 304 (Not Modified).

  • If-None-Match (String)

    Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)

  • If-Unmodified-Since (Time)

    Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).

  • Range (String)

    Range of object to download

  • versionId (String)

    specify a particular version to retrieve

  • query (Hash)

    specify additional query string

See Also:



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/get_object.rb', line 29

def get_object(bucket_name, object_name, options = {}, &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] = options.delete('query') || {}

  if version_id = options.delete('versionId')
    params[:query] = params[:query].merge({'versionId' => version_id})
  end
  params[:headers].merge!(options)
  if options['If-Modified-Since']
    params[:headers]['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header
  end
  if options['If-Unmodified-Since']
    params[:headers]['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header
  end

  if block_given?
    params[:response_block] = Proc.new
  end

  request(params.merge!({
    :expects  => [ 200, 206 ],
    :bucket_name => bucket_name,
    :object_name => object_name,
    :idempotent => true,
    :method   => 'GET',
  }))
end

#get_object_acl(bucket_name, object_name, options = {}) ⇒ Excon::Response

Get access control list for an S3 object

Options Hash (options):

  • versionId (String)

    specify a particular version to retrieve

See Also:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fog/aws/requests/storage/get_object_acl.rb', line 32

def get_object_acl(bucket_name, object_name, options = {})
  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 = options.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::Storage::AWS::AccessControlList.new,
    :query      => query
  })
end

#get_object_torrent(bucket_name, object_name) ⇒ Excon::Response

Get torrent for an S3 object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/aws/requests/storage/get_object_torrent.rb', line 26

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



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/aws/requests/storage/get_request_payment.rb', line 18

def get_request_payment(bucket_name)
  request({
    :expects  => 200,
    :headers  => {},
    :bucket_name => bucket_name,
    :idempotent => true,
    :method   => 'GET',
    :parser   => Fog::Parsers::Storage::AWS::GetRequestPayment.new,
    :query    => {'requestPayment' => nil}
  })
end

#get_serviceExcon::Response

List information about S3 buckets for authorized user



21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/aws/requests/storage/get_service.rb', line 21

def get_service
  request({
    :expects  => 200,
    :headers  => {},
    :host     => @host,
    :idempotent => true,
    :method   => 'GET',
    :parser   => Fog::Parsers::Storage::AWS::GetService.new
  })
end

#head_object(bucket_name, object_name, options = {}) ⇒ Excon::Response

Get headers for an object from S3

Options Hash (options):

  • If-Match (String)

    Returns object only if its etag matches this value, otherwise returns 412 (Precondition Failed).

  • If-Modified-Since (Time)

    Returns object only if it has been modified since this time, otherwise returns 304 (Not Modified).

  • If-None-Match (String)

    Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)

  • If-Unmodified-Since (Time)

    Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).

  • Range (String)

    Range of object to download

  • versionId (String)

    specify a particular version to retrieve

See Also:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/aws/requests/storage/head_object.rb', line 28

def head_object(bucket_name, object_name, options={})
  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 = options.delete('versionId')
    query = {'versionId' => version_id}
  end
  headers = {}
  headers['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header if options['If-Modified-Since']
  headers['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header if options['If-Modified-Since']
  headers.merge!(options)
  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

Options Hash (options):

  • Cache-Control (String)

    Caching behaviour

  • Content-Disposition (String)

    Presentational information for the object

  • Content-Encoding (String)

    Encoding of object data

  • Content-MD5 (String)

    Base64 encoded 128-bit MD5 digest of message (defaults to Base64 encoded MD5 of object.read)

  • Content-Type (String)

    Standard MIME type describing contents (defaults to MIME::Types.of.first)

  • x-amz-acl (String)

    Permissions, must be in [‘private’, ‘public-read’, ‘public-read-write’, ‘authenticated-read’]

  • x-amz-meta-#{name} (String)

    Headers to be returned with object, note total size of request without body must be less than 8 KB.

See Also:



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/aws/requests/storage/initiate_multipart_upload.rb', line 29

def initiate_multipart_upload(bucket_name, object_name, options = {})
  request({
    :expects    => 200,
    :headers    => options,
    :bucket_name => bucket_name,
    :object_name => object_name,
    :method     => 'POST',
    :parser     => Fog::Parsers::Storage::AWS::InitiateMultipartUpload.new,
    :query      => {'uploads' => nil}
  })
end

#list_multipart_uploads(bucket_name, options = {}) ⇒ Excon::Response

List multipart uploads for a bucket

Options Hash (options):

  • key-marker (String)

    limits parts to only those that appear lexicographically after this key.

  • max-uploads (Integer)

    limits number of uploads returned

  • upload-id-marker (String)

    limits uploads to only those that appear lexicographically after this upload id.

See Also:



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/aws/requests/storage/list_multipart_uploads.rb', line 39

def list_multipart_uploads(bucket_name, options = {})
  request({
    :expects  => 200,
    :headers  => {},
    :bucket_name => bucket_name,
    :idempotent => true,
    :method   => 'GET',
    :parser   => Fog::Parsers::Storage::AWS::ListMultipartUploads.new,
    :query    => options.merge!({'uploads' => nil})
  })
end

#list_parts(bucket_name, object_name, upload_id, options = {}) ⇒ Excon::Response

List parts for a multipart upload

Options Hash (options):

  • max-parts (Integer)

    limits number of parts returned

  • part-number-marker (String)

    limits parts to only those that appear lexicographically after this part number.

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/aws/requests/storage/list_parts.rb', line 38

def list_parts(bucket_name, object_name, upload_id, options = {})
  options['uploadId'] = upload_id
  request({
    :expects  => 200,
    :headers  => {},
    :bucket_name => bucket_name,
    :object_name => object_name,
    :idempotent => true,
    :method   => 'GET',
    :parser   => Fog::Parsers::Storage::AWS::ListParts.new,
    :query    => options.merge!({'uploadId' => upload_id})
  })
end

#post_object_hidden_fields(options = {}) ⇒ Object

Get a hash of hidden fields for form uploading to S3, in the form => :field_value Form should look like: <form action=“http://#bucket_name.s3.amazonaws.com/” method=“post” enctype=“multipart/form-data”> These hidden fields should then appear, followed by a field named ‘file’ which is either a textarea or file input.

Options Hash (options):

  • acl (String)

    access control list, in [‘private’, ‘public-read’, ‘public-read-write’, ‘authenticated-read’, ‘bucket-owner-read’, ‘bucket-owner-full-control’]

  • Cache-Control (String)

    same as REST header

  • Content-Type (String)

    same as REST header

  • Content-Disposition (String)

    same as REST header

  • Content-Encoding (String)

    same as REST header

  • Expires (Object)

    same as REST header

  • key (Object)

    key for object, set to ‘$filename’ to use filename provided by user

  • policy (Object)

    security policy for upload

  • success_action_redirect (Object)

    url to redirct to upon success

  • success_action_status (Object)

    status code to return on success, in [200, 201, 204]

  • x-amz-security (Object)

    token devpay security token

  • x-amz-meta... (Object)

    meta data tags

See Also:



26
27
28
29
30
31
32
33
# File 'lib/fog/aws/requests/storage/post_object_hidden_fields.rb', line 26

def post_object_hidden_fields(options = {})
  if options['policy']
    options['policy'] = Base64.encode64(Fog::JSON.encode(options['policy'])).gsub("\n", "")
    options['AWSAccessKeyId'] = @aws_access_key_id
    options['Signature'] = Base64.encode64(@hmac.sign(options['policy'])).gsub("\n", "")
  end
  options
end

#post_object_restore(bucket_name, object_name, days = 100000) ⇒ Excon::Response

Restore an object from Glacier to its original S3 path

Options Hash (days):

  • Number (Integer)

    of days to restore object for. Defaults to 100000 (a very long time)

Raises:

  • (ArgumentError)

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/aws/requests/storage/post_object_restore.rb', line 19

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(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},
    :path     => CGI.escape(object_name)
  })
end

#put_bucket(bucket_name, options = {}) ⇒ Excon::Response

Create an S3 bucket

Options Hash (options):

  • config (Hash)

    arguments for bucket. Defaults to {}.

  • LocationConstraint (Symbol)

    sets the location for the bucket

  • x-amz-acl (String)

    Permissions, must be in [‘private’, ‘public-read’, ‘public-read-write’, ‘authenticated-read’]

See Also:



18
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/put_bucket.rb', line 18

def put_bucket(bucket_name, options = {})
  if location_constraint = options.delete('LocationConstraint')
    data =
"  <CreateBucketConfiguration>\n    <LocationConstraint>\#{location_constraint}</LocationConstraint>\n  </CreateBucketConfiguration>\n"
  else
    data = nil
  end
  request({
    :expects    => 200,
    :body       => data,
    :headers    => options,
    :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’]



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
# File 'lib/fog/aws/requests/storage/put_bucket_acl.rb', line 28

def put_bucket_acl(bucket_name, acl)
  data = ""
  headers = {}

  if acl.is_a?(Hash)
    data = Fog::Storage::AWS.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(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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/aws/requests/storage/put_bucket_cors.rb', line 22

def put_bucket_cors(bucket_name, cors)
  data = Fog::Storage::AWS.hash_to_cors(cors)

  headers = {}
  headers['Content-MD5'] = Base64.encode64(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

      • Expiration [Hash] Container for the object expiration rule.

        • 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.

      • Transition [Hash] Container for the transition rule that describes when objects transition to the Glacier storage class

        • 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.



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
# File 'lib/fog/aws/requests/storage/put_bucket_lifecycle.rb', line 29

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'])
            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['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
          end
        }
      end
    }
  end
  body = builder.to_xml
  body.gsub! /<([^<>]+)\/>/, '<\1></\1>'
  request({
            :body     => body,
            :expects  => 200,
            :headers  => {'Content-MD5' => Base64.encode64(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 =
"<BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\" />\n"
  else
    data =
"<BucketLoggingStatus xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\">\n  <LoggingEnabled>\n    <TargetBucket>\#{logging_status['LoggingEnabled']['TargetBucket']}</TargetBucket>\n    <TargetPrefix>\#{logging_status['LoggingEnabled']['TargetBucket']}</TargetPrefix>\n    <TargetGrants>\n"

    acl['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 <<
"    </TargetGrants>\n  </LoggingEnabled>\n</BucketLoggingStatus>\n"
  end

  request({
    :body     => data,
    :expects  => 200,
    :headers  => {},
    :bucket_name => bucket_name,
    :method   => 'PUT',
    :query    => {'logging' => nil}
  })
end

#put_bucket_policy(bucket_name, policy) ⇒ Object

Change bucket policy for an S3 bucket



13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/aws/requests/storage/put_bucket_policy.rb', line 13

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



15
16
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_tagging.rb', line 15

def put_bucket_tagging(bucket_name, tags)
  tagging = tags.map do |k,v|
    "<Tag><Key>#{k}</Key><Value>#{v}</Value></Tag>"
  end.join("\n")
  data =
"<Tagging xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\" >\n  <TagSet>\n    \#{tagging}\n  </TagSet>\n</Tagging>\n"

  request({
    :body     => data,
    :expects  => 204,
    :headers  => {'Content-MD5' => Base64.encode64(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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/aws/requests/storage/put_bucket_versioning.rb', line 13

def put_bucket_versioning(bucket_name, status)
  data =
"<VersioningConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n  <Status>\#{status}</Status>\n</VersioningConfiguration>\n"

  request({
    :body     => data,
    :expects  => 200,
    :headers  => {},
    :bucket_name => bucket_name,
    :method   => 'PUT',
    :query    => {'versioning' => nil}
  })
end

#put_bucket_website(bucket_name, suffix, options = {}) ⇒ Object

Change website configuration for an S3 bucket

Options Hash (options):

  • key (String)

    key to use for 4XX class errors

See Also:



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
# File 'lib/fog/aws/requests/storage/put_bucket_website.rb', line 15

def put_bucket_website(bucket_name, suffix, options = {})
  data =
"<WebsiteConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n    <IndexDocument>\n<Suffix>\#{suffix}</Suffix>\n    </IndexDocument>\n"

  if options[:key]
    data <<
"<ErrorDocument>\n    <Key>\#{options[:key]}</Key>\n</ErrorDocument>\n"
  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 = {}) ⇒ Excon::Response

Create an object in an S3 bucket

Options Hash (options):

  • Cache-Control (String)

    Caching behaviour

  • Content-Disposition (String)

    Presentational information for the object

  • Content-Encoding (String)

    Encoding of object data

  • Content-Length (String)

    Size of object in bytes (defaults to object.read.length)

  • Content-MD5 (String)

    Base64 encoded 128-bit MD5 digest of message

  • Content-Type (String)

    Standard MIME type describing contents (defaults to MIME::Types.of.first)

  • Expires (String)

    Cache expiry

  • x-amz-acl (String)

    Permissions, must be in [‘private’, ‘public-read’, ‘public-read-write’, ‘authenticated-read’]

  • x-amz-storage-class (String)

    Default is ‘STANDARD’, set to ‘REDUCED_REDUNDANCY’ for non-critical, reproducable data

  • x-amz-meta-# (name)

    Headers to be returned with object, note total size of request without body must be less than 8 KB.

See Also:



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/aws/requests/storage/put_object.rb', line 29

def put_object(bucket_name, object_name, data, options = {})
  data = Fog::Storage.parse_data(data)
  headers = data[:headers].merge!(options)
  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

Options Hash (options):

  • versionId (String)

    specify a particular version to retrieve

See Also:



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
# File 'lib/fog/aws/requests/storage/put_object_acl.rb', line 31

def put_object_acl(bucket_name, object_name, acl, options = {})
  query = {'acl' => nil}
  if version_id = options.delete('versionId')
    query['versionId'] = version_id
  end

  data = ""
  headers = {}

  if acl.is_a?(Hash)
    data = Fog::Storage::AWS.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(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_request_payment(bucket_name, payer) ⇒ Object

Change who pays for requests to an S3 bucket



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/aws/requests/storage/put_request_payment.rb', line 13

def put_request_payment(bucket_name, payer)
  data =
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n  <Payer>\#{payer}</Payer>\n</RequestPaymentConfiguration>\n"
  request({
    :body     => data,
    :expects  => 200,
    :headers  => {},
    :bucket_name => bucket_name,
    :method   => 'PUT',
    :query    => {'requestPayment' => nil}
  })
end

#reloadObject



435
436
437
# File 'lib/fog/aws/storage.rb', line 435

def reload
  @connection.reset if @connection
end

#signature(params, expires) ⇒ Object



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/fog/aws/storage.rb', line 439

def signature(params, expires)
  headers = params[:headers] || {}

  string_to_sign =
"\#{params[:method].to_s.upcase}\n\#{headers['Content-MD5']}\n\#{headers['Content-Type']}\n\#{expires}\n"

  amz_headers, canonical_amz_headers = {}, ''
  for key, value in headers
    if key[0..5] == 'x-amz-'
      amz_headers[key] = value
    end
  end
  amz_headers = amz_headers.sort {|x, y| x[0] <=> y[0]}
  for key, value in amz_headers
    canonical_amz_headers << "#{key}:#{value}\n"
  end
  string_to_sign << canonical_amz_headers


  query_string = ''
  if params[:query]
    query_args = []
    for key in params[:query].keys.sort
      if VALID_QUERY_KEYS.include?(key)
        value = params[:query][key]
        if value
          query_args << "#{key}=#{value}"
        else
          query_args << key
        end
      end
    end
    if query_args.any?
      query_string = '?' + query_args.join('&')
    end
  end

  canonical_path = (params[:path] || object_to_path(params[:object_name])).to_s
  canonical_path = '/' + canonical_path if canonical_path[0..0] != '/'
  if params[:bucket_name]
    canonical_resource = "/#{params[:bucket_name]}#{canonical_path}"
  else
    canonical_resource = canonical_path
  end
  canonical_resource << query_string
  string_to_sign << canonical_resource

  signed_string = @hmac.sign(string_to_sign)
  Base64.encode64(signed_string).chomp!
end

#sync_clockObject

Sync clock against S3 to avoid skew errors



8
9
10
11
12
13
14
15
# File 'lib/fog/aws/requests/storage/sync_clock.rb', line 8

def sync_clock
  response = begin
    get_service
  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

Options Hash (options):

  • Content-MD5 (String)

    Base64 encoded 128-bit MD5 digest of message

See Also:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/aws/requests/storage/upload_part.rb', line 22

def upload_part(bucket_name, object_name, upload_id, part_number, data, options = {})
  data = Fog::Storage.parse_data(data)
  headers = options
  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