Skip to content

Commit 29d4ff4

Browse files
committed
Changes to get the host-agent working in BJS
1 parent e0f552a commit 29d4ff4

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

bin/install

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ EOF
230230
def get_s3_uri(region, bucket, key)
231231
if (region == 'us-east-1')
232232
URI.parse("https://#{bucket}.s3.amazonaws.com/#{key}")
233+
elsif (region.split("-")[0] == 'cn')
234+
URI.parse("https://#{bucket}.s3.#{region}.amazonaws.com.cn/#{key}")
233235
else
234236
URI.parse("https://#{bucket}.s3-#{region}.amazonaws.com/#{key}")
235237
end

lib/instance_agent/plugins/codedeploy/codedeploy_control.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ def verify_cert
9292
# Do minimal cert pinning
9393
def verify_subject
9494
InstanceAgent::Log.debug("#{self.class.to_s}: Actual certificate subject is '#{@cert.subject.to_s}'")
95-
@cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-commands."+@region+".amazonaws.com"
95+
if "cn" == @region.split("-")[0]
96+
@cert.subject.to_s == "/C=CN/ST=Beijing/L=Beijing/O=Amazon Connect Technology Services (Beijing) Co., Ltd./CN=codedeploy-commands."+@region+".amazonaws.com.cn"
97+
else
98+
@cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-commands."+@region+".amazonaws.com"
99+
end
96100
end
97101

98102
end

lib/instance_agent/plugins/codedeploy/deployment_specification.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ def self.verify_pkcs7_signer_cert(cert)
135135
when 'beta', 'gamma'
136136
cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-signer-integ.amazonaws.com"
137137
when 'prod'
138-
cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-signer-"+@@region+".amazonaws.com"
138+
if (@@region.split("-")[0] == "cn")
139+
cert.subject.to_s == "/C=CN/ST=Beijing/L=Beijing/O=Amazon Connect Technology Services (Beijing) Co., Ltd./CN=codedeploy-signer-"+@@region+".amazonaws.com.cn"
140+
else
141+
cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-signer-"+@@region+".amazonaws.com"
142+
end
139143
else
140144
raise "Unknown profile '#{Config.config()[:codedeploy_test_profile]}'"
141145
end

lib/instance_metadata.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ class InstanceMetadata
88
PORT = 80
99

1010
def self.host_identifier
11+
country = region.split('-')[0]
1112
doc = JSON.parse(http_get('/latest/dynamic/instance-identity/document').strip)
12-
"arn:aws:ec2:#{doc['region']}:#{doc['accountId']}:instance/#{doc['instanceId']}"
13+
if "cn" == country
14+
"arn:aws-cn:ec2:#{doc['region']}:#{doc['accountId']}:instance/#{doc['instanceId']}"
15+
else
16+
"arn:aws:ec2:#{doc['region']}:#{doc['accountId']}:instance/#{doc['instanceId']}"
17+
end
1318
end
1419

1520
def self.region

test/instance_metadata_test.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ def self.should_check_status_code(&blk)
1919
@instance_document = JSON.dump({"accountId" => account_id, "region" => region, "instanceId" => instance_id})
2020
@http = mock()
2121
@response = mock()
22+
@instance_doc_response = mock()
2223
@response.stubs(:code).returns("200")
23-
@http.stubs(:get).returns(@response)
24+
@instance_doc_response.stubs(:code).returns("200")
25+
@http.stubs(:get).returns(@response, @instance_doc_response)
2426
Net::HTTP.stubs(:start).yields(@http)
2527
end
2628

2729
context 'getting the host identifier' do
2830

2931
setup do
30-
@response.stubs(:body).returns(@instance_document)
32+
@response.stubs(:body).returns("us-east-1a")
33+
@instance_doc_response.stubs(:body).returns(@instance_document)
3134
end
3235

3336
should 'connect to the right host' do
@@ -38,7 +41,7 @@ def self.should_check_status_code(&blk)
3841
should 'call the correct URL' do
3942
@http.expects(:get).
4043
with("/latest/dynamic/instance-identity/document").
41-
returns(@response)
44+
returns(@instance_doc_response)
4245
InstanceMetadata.host_identifier
4346
end
4447

@@ -47,7 +50,7 @@ def self.should_check_status_code(&blk)
4750
end
4851

4952
should 'strip whitesace in the body' do
50-
@response.stubs(:body).returns(" \t#{@instance_document} ")
53+
@instance_doc_response.stubs(:body).returns(" \t#{@instance_document} ")
5154
assert_equal(@host_identifier, InstanceMetadata.host_identifier)
5255
end
5356

vendor/gems/codedeploy-commands-1.0.0/lib/aws/plugins/deploy_control_endpoint.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class DeployControlEndpoint < Seahorse::Client::Plugin
77
url = ENV['AWS_DEPLOY_CONTROL_ENDPOINT']
88
if url.nil?
99
url = "https://codedeploy-commands.#{cfg.region}.amazonaws.com"
10+
if "cn" == cfg.region.split("-")[0]
11+
url.concat(".cn")
12+
end
1013
end
1114
url
1215
end

0 commit comments

Comments
 (0)