Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions libraries/s3_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module S3FileLib

module SigV2
def self.sign(request, bucket, path, *args)
def self.sign(request, bucket, path, *args)
token = args[2] if args[2]
now = Time.now().utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
string_to_sign = "#{request.method}\n\n\n%s\n" % [now]
Expand Down Expand Up @@ -87,7 +87,7 @@ def self.with_region_detect(region = nil)
end
end

def self.do_request(method, url, bucket, path, *args, public_bucket: public_bucket)
def self.do_request(method, url, bucket, path, *args, public_bucket: self.public_bucket)
region = args[3]
url = build_endpoint_url(bucket, region) if url.nil?

Expand Down Expand Up @@ -135,26 +135,23 @@ def self.get_digests_from_headers(headers)
return {"md5" => etag}.merge(digests)
end

def self.get_digests_from_s3(bucket, url, path, *args, timeout: 300,open_timeout: 10, retries: 5, public_bucket: public_bucket)
now, auth_string = get_s3_auth("HEAD", bucket, path, args[1], args[2], args[3])
def self.get_digests_from_s3(bucket, url, path, *args, retries: 5, public_bucket: self.public_bucket)
max_tries = retries + 1
headers = build_headers(now, auth_string, token)
saved_exception = nil

while (max_tries > 0)
while max_tries > 0
begin

response = RestClient.head('https://%s.s3.amazonaws.com%s' % [bucket,path], headers)

response = do_request('HEAD', url, bucket, path, args[0], args[1], args[2], args[3], public_bucket: public_bucket)
etag = response.headers[:etag].gsub('"','')
digest = response.headers[:x_amz_meta_digest]
digests = digest.nil? ? {} : Hash[digest.split(",").map {|a| a.split("=")}]

return {"md5" => etag}.merge(digests)

rescue => e
max_tries = max_tries - 1
saved_exception = e
rescue => e
max_tries = max_tries - 1
saved_exception = e
end
end
raise saved_exception
Expand Down Expand Up @@ -185,7 +182,7 @@ def self.validate_download_checksum(response)
end


def self.get_from_s3(bucket, url, path, aws_access_key_id, aws_secret_access_key, token, public_bucket: public_bucket, verify_md5: false, region: nil)
def self.get_from_s3(bucket, url, path, aws_access_key_id, aws_secret_access_key, token, public_bucket: self.public_bucket, verify_md5: false, region: nil)
response = nil
retries = 5
for attempts in 0..retries
Expand Down
10 changes: 5 additions & 5 deletions providers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
raise ArgumentError.new 'No credentials provided and no instance profile on this machine.'
end
instance_profile_name = instance_profiles.split.first
instance_profile = JSON.load(client.get(instance_profile_base_url + instance_profile_name), {:'X-aws-ec2-metadata-token' => get_token.call()})
instance_profile = JSON.load(client.get(instance_profile_base_url + instance_profile_name, { :'X-aws-ec2-metadata-token' => get_token.call() }))

aws_access_key_id = instance_profile['AccessKeyId']
aws_secret_access_key = instance_profile['SecretAccessKey']
token = instance_profile['Token']
aws_access_key_id = instance_profile['AccessKeyId']
aws_secret_access_key = instance_profile['SecretAccessKey']
token = instance_profile['Token']

# now try to auto-detect the region from the instance
# now try to auto-detect the region from the instance
if region.nil?
dynamic_doc_base_url = 'http://169.254.169.254/latest/dynamic/instance-identity/document'
begin
Expand Down