Skip to content
Merged

1.8.1 #415

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/instance_agent/plugins/codedeploy/command_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ def s3_options
options[:signature_version] = 'v4'

region = ENV['AWS_REGION'] || InstanceMetadata.region
if region == "eusc-de-east-1"
Comment thread
NsTremblay marked this conversation as resolved.
options[:endpoint] = 'https://s3.eusc-de-east-1.amazonaws.eu'
end
options[:region] = region

if !InstanceAgent::Config.config[:s3_endpoint_override].to_s.empty?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,20 @@ class CodeDeployControlTest < InstanceAgentTestCase
assert_equal "codedeploy-commands.us-east-1.amazonaws.com", codedeploy_control_client.get_client.config.endpoint.host
end

should "resolve non .com domains" do
should "resolve China (Beijing) domain" do
codedeploy_control_client = CodeDeployControl.new :region => "cn-north-1"
assert_equal "codedeploy-commands.cn-north-1.amazonaws.com.cn", codedeploy_control_client.get_client.config.endpoint.host
end

should "resolve China (Ningxia) domain" do
codedeploy_control_client = CodeDeployControl.new :region => "cn-northwest-1"
assert_equal "codedeploy-commands.cn-northwest-1.amazonaws.com.cn", codedeploy_control_client.get_client.config.endpoint.host
end

should "resolve eu gov cloud domain" do
codedeploy_control_client = CodeDeployControl.new :region => "eusc-de-east-1"
assert_equal "codedeploy-commands.eusc-de-east-1.amazonaws.eu", codedeploy_control_client.get_client.config.endpoint.host
end
end

context "common config" do
Expand Down
27 changes: 26 additions & 1 deletion test/instance_agent/plugins/codedeploy/command_executor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def github_env_vars()
assert_equal "https://example.override.endpoint.com", @command_executor.s3_options[:endpoint].to_s
end
end

context "when no override endpoint provided and not using fips" do
setup do
InstanceAgent::Config.config[:s3_endpoint_override] = nil
Expand All @@ -523,6 +523,31 @@ def github_env_vars()
assert_true @command_executor.s3_options.include? :endpoint
end
end

context "when region is EU GovCloud with instance metadata" do
setup do
InstanceAgent::Config.config[:s3_endpoint_override] = nil
InstanceAgent::Config.config[:use_fips_mode] = false
ENV['AWS_REGION'] = nil
InstanceMetadata.stubs(:region).returns('eusc-de-east-1')
end
should "use S3 EU GovCloud specific endpoint" do
assert_equal 'eusc-de-east-1', @command_executor.s3_options[:region]
assert_equal 'https://s3.eusc-de-east-1.amazonaws.eu', @command_executor.s3_options[:endpoint]
end
end

context "when region is EU GovCloud" do
setup do
InstanceAgent::Config.config[:s3_endpoint_override] = nil
InstanceAgent::Config.config[:use_fips_mode] = false
ENV['AWS_REGION'] = 'eusc-de-east-1'
end
should "use S3 EU GovCloud specific endpoint" do
assert_equal 'eusc-de-east-1', @command_executor.s3_options[:region]
assert_equal 'https://s3.eusc-de-east-1.amazonaws.eu', @command_executor.s3_options[:endpoint]
end
end
end

context "downloading bundle from S3" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class DeployControlEndpoint < Seahorse::Client::Plugin
if is_on_prem?
partitions_region_pattern = File.read(File.join(File.dirname(__FILE__), 'partition-region-pattern.json'))
partitions_region_pattern_hash = JSON.parse(partitions_region_pattern)

unless partitions_region_pattern_hash.include?(domain)
raise "Unknown domain: #{domain}"
end

known_region_pattern = partitions_region_pattern_hash[domain]["regionRegex"]

unless region.match(known_region_pattern)
raise "Invalid region: #{region}"
end
Expand All @@ -40,8 +40,13 @@ class DeployControlEndpoint < Seahorse::Client::Plugin
ProcessManager::Log.info("Creating client url from IMDS region and domain")
else
region = cfg.region
domain = 'amazonaws.com'
domain += '.cn' if region.split("-")[0] == 'cn'
suffix = case
when region == 'eusc-de-east-1' then 'eu' # Special region has special domain
when region.split("-")[0] == 'cn' then 'com.cn'
else 'com'
end

domain = "amazonaws.#{suffix}"

ProcessManager::Log.info("Creating client url from configurations")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"regionRegex" : "^[0-9a-z-]{1,20}$"
},

"amazonaws.com.cn": {
"amazonaws.eu": {
"regionRegex" : "^[0-9a-z-]{1,20}$"
},

"amazonaws.com.cn": {
"regionRegex" : "^cn\\-\\w+\\-\\d+$"
}
}