Skip to content

Commit

Permalink
#1086, right_aws active_support dependency removal
Browse files Browse the repository at this point in the history
git-svn-id: https://wush.net/svn/rightscale/right_aws/trunk@3678 9f0cbaf6-ce18-0410-ad37-d14a22affa91
  • Loading branch information
Konstantin Dzreyev committed Apr 29, 2008
1 parent 6896e6f commit 171db3a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/s3/right_s3_interface.rb
Expand Up @@ -33,7 +33,8 @@ class S3Interface < RightAwsBase
DEFAULT_PORT = 443
DEFAULT_PROTOCOL = 'https'
REQUEST_TTL = 30
DEFAULT_EXPIRES_AFTER = 1 * 24 * 60 * 60 # One day's worth of seconds
DEFAULT_EXPIRES_AFTER = 1 * 24 * 60 * 60 # One day's worth of seconds
ONE_YEAR_IN_SECONDS = 365 * 24 * 60 * 60
AMAZON_HEADER_PREFIX = 'x-amz-'
AMAZON_METADATA_PREFIX = 'x-amz-meta-'

Expand Down Expand Up @@ -601,7 +602,7 @@ def generate_link(method, headers={}, expires=nil) #:nodoc:
end
# expiration time
expires ||= DEFAULT_EXPIRES_AFTER
expires = Time.now.utc.since(expires) if expires.is_a?(Fixnum) && (expires<1.year)
expires = Time.now.utc + expires if expires.is_a?(Fixnum) && (expires < ONE_YEAR_IN_SECONDS)
expires = expires.to_i
# remove unset(==optional) and symbolyc keys
headers.each{ |key, value| headers.delete(key) if (value.nil? || key.is_a?(Symbol)) }
Expand Down Expand Up @@ -669,8 +670,16 @@ def put_link(bucket, key, data=nil, expires=nil, headers={})

# Generates link for 'GetObject'.
#
# s3.get_link('my_awesome_bucket',key) #=> url string
# if a bucket comply with virtual hosting naming then retuns a link with the
# bucket as a part of host name:
#
# s3.get_link('my-awesome-bucket',key) #=> https://my-awesome-bucket.s3.amazonaws.com:443/asia%2Fcustomers?Signature=nh7...
#
# otherwise returns an old style link (the bucket is a part of path):
#
# s3.get_link('my_awesome_bucket',key) #=> https://s3.amazonaws.com:443/my_awesome_bucket/asia%2Fcustomers?Signature=QAO...
#
# see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/VirtualHosting.html
def get_link(bucket, key, expires=nil, headers={})
generate_link('GET', headers.merge(:url=>"#{bucket}/#{CGI::escape key}"), expires)
rescue
Expand Down

0 comments on commit 171db3a

Please sign in to comment.