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:
parent
bcfb5fe1df
commit
a28ecc4398
4 changed files with 4 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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}"
|
||||
|
|
|
@ -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','/')
|
||||
|
|
|
@ -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}"]
|
||||
|
|
Loading…
Reference in a new issue