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

Merge pull request #3109 from fwiesel/region_check_amazon

Check region against static list, only if host is a subdomain of amazonaws
This commit is contained in:
Wesley Beary 2014-08-14 10:44:19 -05:00
commit 70c3ffe198
3 changed files with 29 additions and 6 deletions

View file

@ -294,7 +294,22 @@ module Fog
@aws_credentials_expire_at = Time::now + 20
setup_credentials(options)
@region = options[:region] || 'us-east-1'
validate_aws_region @region
if @endpoint = options[:endpoint]
endpoint = URI.parse(@endpoint)
@host = endpoint.host
@path = endpoint.path
@port = endpoint.port
@scheme = endpoint.scheme
else
@host = options[:host] || "ec2.#{options[:region]}.amazonaws.com"
@path = options[:path] || '/'
@persistent = options[:persistent] || false
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
end
validate_aws_region(@host, @region)
end
def region_data
@ -443,8 +458,6 @@ module Fog
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.compute'
@version = options[:version] || '2014-06-15'
validate_aws_region @region
if @endpoint = options[:endpoint]
endpoint = URI.parse(@endpoint)
@host = endpoint.host
@ -458,6 +471,8 @@ module Fog
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
end
validate_aws_region(@host, @region)
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
end

View file

@ -1,8 +1,8 @@
module Fog
module AWS
module RegionMethods
def validate_aws_region region
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(region)
def validate_aws_region host, region
if host.end_with?('.amazonaws.com') and not ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(region)
raise ArgumentError, "Unknown region: #{region.inspect}"
end
end

View file

@ -24,11 +24,19 @@ Shindo.tests('Fog::Compute[:aws] | region requests', ['aws']) do
Fog::Compute::AWS.new({:aws_access_key_id => 'dummykey',
:aws_secret_access_key => 'dummysecret',
:aws_session_token => 'dummytoken',
:region => "world-antarctica-1"})
:region => 'world-antarctica-1'})
end
end
tests("#unknown_endpoint").formats(@regions_format) do
Fog::Compute::AWS.new({:aws_access_key_id => 'dummykey',
:aws_secret_access_key => 'dummysecret',
:aws_session_token => 'dummytoken',
:region => 'world-antarctica-1',
:endpoint => 'aws-clone.example'}).describe_regions.body
end
end
end