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

standardize region validation

* remove RegionMethods
* static (but not immutable) list of regions
This commit is contained in:
Josh Lane 2015-08-13 09:04:19 -07:00
parent 1add8cfc16
commit ff252c3979
13 changed files with 43 additions and 67 deletions

View file

@ -27,7 +27,6 @@ module Fog
autoload :CredentialFetcher, File.expand_path('../aws/credential_fetcher', __FILE__)
autoload :Errors, File.expand_path('../aws/errors', __FILE__)
autoload :Mock, File.expand_path('../aws/mock', __FILE__)
autoload :RegionMethods, File.expand_path('../aws/region_methods', __FILE__)
autoload :SignatureV4, File.expand_path('../aws/signaturev4', __FILE__)
# Services
@ -223,5 +222,15 @@ module Fog
return false unless response && response.headers
response.get_header('Content-Type') =~ %r{application/.*json.*}i ? true : false
end
def self.regions
@regions ||= ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1', 'cn-north-1']
end
def self.validate_region!(region, host=nil)
if (!host || host.end_with?('.amazonaws.com')) && !regions.include?(region)
raise ArgumentError, "Unknown region: #{region.inspect}"
end
end
end
end

View file

@ -253,9 +253,7 @@ module Fog
setup_credentials(options)
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
end
def region_data

View file

@ -52,9 +52,7 @@ module Fog
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
end
def data

View file

@ -185,7 +185,6 @@ module Fog
}
include Fog::AWS::CredentialFetcher::ConnectionMethods
include Fog::AWS::RegionMethods
def self.data
@data ||= Hash.new do |hash, region|
@ -315,7 +314,7 @@ module Fog
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
end
validate_aws_region(@host, @region)
Fog::AWS.validate_region!(@region, @host)
end
def region_data
@ -429,7 +428,6 @@ module Fog
class Real
include Fog::AWS::CredentialFetcher::ConnectionMethods
include Fog::AWS::RegionMethods
# Initialize connection to EC2
#
# ==== Notes
@ -478,7 +476,7 @@ module Fog
@scheme = options[:scheme] || 'https'
end
validate_aws_region(@host, @region)
Fog::AWS.validate_region!(@region, @host)
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
end

View file

@ -163,9 +163,7 @@ module Fog
@use_iam_profile = options[:use_iam_profile]
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
setup_credentials(options)
end

View file

@ -88,9 +88,7 @@ module Fog
@region = options[:region] || 'us-east-1'
setup_credentials(options)
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
end
def setup_credentials(options)

View file

@ -149,9 +149,7 @@ module Fog
@aws_access_key_id = options[:aws_access_key_id]
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
end
def data

View file

@ -49,9 +49,7 @@ module Fog
@region = options[:region] || 'us-east-1'
setup_credentials(options)
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
end
def setup_credentials(options)

View file

@ -49,9 +49,7 @@ module Fog
@account_id = Fog::AWS::Mock.owner_id
@module = "lambda"
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
end
def data

View file

@ -143,9 +143,7 @@ module Fog
@use_iam_profile = options[:use_iam_profile]
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
setup_credentials(options)
end

View file

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

View file

@ -47,9 +47,7 @@ module Fog
@account_id = Fog::AWS::Mock.owner_id
@module = "sns"
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
end
def data

View file

@ -38,9 +38,7 @@ module Fog
setup_credentials(options)
@region = options[:region] || 'us-east-1'
unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
Fog::AWS.validate_region!(@region)
end
def data