class Aws::Plugins::RegionalEndpoint
@api private
Private Class Methods
env_global_endpoint(cfg)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 211 def env_global_endpoint(cfg) return unless endpoint = ENV['AWS_ENDPOINT_URL'] cfg.logger&.debug( "Endpoint configured from ENV['AWS_ENDPOINT_URL']: #{endpoint}\n") endpoint end
env_service_endpoint(cfg)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 201 def env_service_endpoint(cfg) service_id = cfg.api.metadata['serviceId'] || cfg.api.metadata['endpointPrefix'] env_service_id = service_id.gsub(" ", "_").upcase return unless endpoint = ENV["AWS_ENDPOINT_URL_#{env_service_id}"] cfg.logger&.debug( "Endpoint configured from ENV['AWS_ENDPOINT_URL_#{env_service_id}']: #{endpoint}\n") endpoint end
handle_legacy_pseudo_regions(cfg)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 235 def handle_legacy_pseudo_regions(cfg) region = cfg.region new_region = region.gsub('fips-', '').gsub('-fips', '') if region != new_region warn("Legacy region #{region} was transformed to #{new_region}."\ '`use_fips_endpoint` config was set to true.') cfg.override_config(:use_fips_endpoint, true) cfg.override_config(:region, new_region) end end
resolve_custom_config_endpoint(cfg)
click to toggle source
get a custom configured endpoint from ENV or configuration
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 194 def resolve_custom_config_endpoint(cfg) return if cfg.ignore_configured_endpoint_urls env_service_endpoint(cfg) || env_global_endpoint(cfg) || shared_config_endpoint(cfg) end
resolve_endpoint(cfg)
click to toggle source
NOTE: with Endpoints
2.0, some of this logic is deprecated but because new old service gems may depend on new core versions we must preserve that behavior. Additional behavior controls the setting of the custom SDK::Endpoint parameter. When the ‘regional_endpoint` config is set to true - this indicates to Endpoints2.0 that a custom endpoint has NOT been configured by the user.
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 176 def resolve_endpoint(cfg) endpoint = resolve_custom_config_endpoint(cfg) endpoint_prefix = cfg.api.metadata['endpointPrefix'] return endpoint unless endpoint.nil? && cfg.region && endpoint_prefix validate_region!(cfg.region) handle_legacy_pseudo_regions(cfg) # set regional_endpoint flag - this indicates to Endpoints 2.0 # that a custom endpoint has NOT been configured by the user cfg.override_config(:regional_endpoint, true) # a default endpoint is resolved in after_initialize nil end
resolve_ignore_configured_endpoint_urls(cfg)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 163 def resolve_ignore_configured_endpoint_urls(cfg) value = ENV['AWS_IGNORE_CONFIGURED_ENDPOINT_URLS'] value ||= Aws.shared_config.ignore_configured_endpoint_urls(profile: cfg.profile) Aws::Util.str_2_bool(value&.downcase) || false end
resolve_region(cfg)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 135 def resolve_region(cfg) keys = %w[AWS_REGION AMAZON_REGION AWS_DEFAULT_REGION] env_region = ENV.values_at(*keys).compact.first env_region = nil if env_region == '' cfg_region = Aws.shared_config.region(profile: cfg.profile) env_region || cfg_region end
resolve_sigv4a_signing_region_set(cfg)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 143 def resolve_sigv4a_signing_region_set(cfg) value = ENV['AWS_SIGV4A_SIGNING_REGION_SET'] value ||= Aws.shared_config.sigv4a_signing_region_set(profile: cfg.profile) value.split(',') if value end
resolve_use_dualstack_endpoint(cfg)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 149 def resolve_use_dualstack_endpoint(cfg) value = ENV['AWS_USE_DUALSTACK_ENDPOINT'] value ||= Aws.shared_config.use_dualstack_endpoint( profile: cfg.profile ) Aws::Util.str_2_bool(value) || false end
resolve_use_fips_endpoint(cfg)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 157 def resolve_use_fips_endpoint(cfg) value = ENV['AWS_USE_FIPS_ENDPOINT'] value ||= Aws.shared_config.use_fips_endpoint(profile: cfg.profile) Aws::Util.str_2_bool(value) || false end
validate_region!(region)
click to toggle source
check region is a valid RFC host label
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 229 def validate_region!(region) unless Seahorse::Util.host_label?(region) raise Errors::InvalidRegionError end end
Public Instance Methods
after_initialize(client)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 82 def after_initialize(client) region = client.config.region raise Errors::MissingRegionError if region.nil? || region == '' # resolve a default endpoint to preserve legacy behavior initialize_default_endpoint(client) if client.config.endpoint.nil? region_set = client.config.sigv4a_signing_region_set return if region_set.nil? raise Errors::InvalidRegionSetError unless region_set.is_a?(Array) region_set = region_set.compact.reject(&:empty?) raise Errors::InvalidRegionSetError if region_set.empty? client.config.sigv4a_signing_region_set = region_set end
Private Instance Methods
initialize_default_endpoint(client)
click to toggle source
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 101 def initialize_default_endpoint(client) client_module = Object.const_get(client.class.name.rpartition('::').first) param_class = client_module.const_get(:EndpointParameters) endpoint_provider = client.config.endpoint_provider params = param_class.create(client.config) endpoint = endpoint_provider.resolve_endpoint(params) client.config.endpoint = endpoint.url rescue ArgumentError, NameError # fallback to legacy client.config.endpoint = resolve_legacy_endpoint(client.config) end
resolve_legacy_endpoint(cfg)
click to toggle source
set a default endpoint in config using legacy (endpoints.json) resolver
# File lib/aws-sdk-core/plugins/regional_endpoint.rb, line 114 def resolve_legacy_endpoint(cfg) endpoint_prefix = cfg.api.metadata['endpointPrefix'] if cfg.respond_to?(:sts_regional_endpoints) sts_regional = cfg.sts_regional_endpoints end endpoint = Aws::Partitions::EndpointProvider.resolve( cfg.region, endpoint_prefix, sts_regional, { dualstack: cfg.use_dualstack_endpoint, fips: cfg.use_fips_endpoint } ) URI(endpoint) end