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

[aws|region validation] Region validation extracted into a separate class and used by both, mocks and real.

This commit is contained in:
radekg 2014-02-18 11:51:21 +01:00
parent 287129f157
commit f9d0837373
3 changed files with 18 additions and 7 deletions

View file

@ -163,6 +163,7 @@ module Fog
class Mock
include Fog::AWS::CredentialFetcher::ConnectionMethods
include Fog::AWS::RegionMethods
def self.data
@data ||= Hash.new do |hash, region|
@ -278,10 +279,7 @@ module Fog
@aws_credentials_expire_at = Time::now + 20
setup_credentials(options)
@region = options[:region] || 'us-east-1'
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)
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
validate_aws_region @region
end
def region_data
@ -351,6 +349,7 @@ module Fog
class Real
include Fog::AWS::CredentialFetcher::ConnectionMethods
include Fog::AWS::RegionMethods
# Initialize connection to EC2
#
# ==== Notes
@ -385,9 +384,7 @@ module Fog
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.compute'
@version = options[:version] || '2013-10-01'
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?(options[:region])
raise ArgumentError, "Unknown region: #{@region.inspect}"
end
validate_aws_region @region
if @endpoint = options[:endpoint]
endpoint = URI.parse(@endpoint)

View file

@ -1,5 +1,6 @@
require 'fog/core'
require 'fog/aws/credential_fetcher'
require 'fog/aws/region_methods'
require 'fog/aws/signaturev4'
module Fog

View file

@ -0,0 +1,13 @@
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)
raise ArgumentError, "Unknown region: #{region.inspect}"
end
end
end
end
end