1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Introduce AWS::COMPLIANT_BUCKET_NAMES constant

This commit is contained in:
Stephan Kaag 2012-12-05 21:12:25 +01:00
parent bcfb5fe1df
commit a28ecc4398
4 changed files with 4 additions and 3 deletions

View file

@ -3,6 +3,7 @@ require 'fog/aws/credential_fetcher'
require 'fog/aws/signaturev4'
module Fog
module AWS
COMPLIANT_BUCKET_NAMES = /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\-(?![\.])){1,61}[a-z0-9]$/
extend Fog::Provider

View file

@ -86,7 +86,7 @@ module Fog
def public_url
requires :key
if connection.get_bucket_acl(key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
if key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\-(?![\.])){1,61}[a-z0-9]$/
if key.to_s =~ Fog::AWS::COMPLIANT_BUCKET_NAMES
"https://#{key}.s3.amazonaws.com"
else
"https://s3.amazonaws.com/#{key}"

View file

@ -100,7 +100,7 @@ module Fog
def public_url
requires :directory, :key
if connection.get_object_acl(directory.key, key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
if directory.key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\-(?![\.])){1,61}[a-z0-9]$/
if directory.key.to_s =~ Fog::AWS::COMPLIANT_BUCKET_NAMES
"https://#{directory.key}.s3.amazonaws.com/#{Fog::AWS.escape(key)}".gsub('%2F','/')
else
"https://s3.amazonaws.com/#{directory.key}/#{Fog::AWS.escape(key)}".gsub('%2F','/')

View file

@ -11,7 +11,7 @@ module Fog
unless object_name
raise ArgumentError.new('object_name is required')
end
host, path = if bucket_name =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\-(?![\.])){1,61}[a-z0-9]$/
host, path = if bucket_name =~ Fog::AWS::COMPLIANT_BUCKET_NAMES
["#{bucket_name}.#{@host}", object_name]
else
[@host, "#{bucket_name}/#{object_name}"]