Skip to content

Commit ec39004

Browse files
KatyalHelen1987
authored andcommitted
Add s3 endpoint override as a config variable
Let the user override what s3 endpoint the agent is using. This change adds a new optional config variable, which lets us override s3 endpoint override. * Unit Tests : Y * Integration Tests : Y cr https://code.amazon.com/reviews/CR-9234157
1 parent 3e47cac commit ec39004

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

conf/codedeployagent.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
:verbose: false
88
:wait_between_runs: 1
99
:proxy_uri:
10-
:max_revisions: 5
10+
:max_revisions: 5

lib/instance_agent/config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def initialize
4242
:proxy_uri => nil,
4343
:enable_deployments_log => true,
4444
:use_fips_mode => false,
45-
:deploy_control_endpoint => nil
45+
:deploy_control_endpoint => nil,
46+
:s3_endpoint_override => nil
4647
})
4748
end
4849

lib/instance_agent/plugins/codedeploy/command_executor.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,13 @@ def s3_options
266266

267267
region = ENV['AWS_REGION'] || InstanceMetadata.region
268268
options[:region] = region
269-
if InstanceAgent::Config.config[:use_fips_mode]
269+
if !InstanceAgent::Config.config[:s3_endpoint_override].to_s.empty?
270+
options[:endpoint] = URI(InstanceAgent::Config.config[:s3_endpoint_override])
271+
elsif InstanceAgent::Config.config[:use_fips_mode]
270272
#S3 Fips pseudo-regions are not supported by the SDK yet
271273
#source for the URL: https://aws.amazon.com/compliance/fips/
272274
options[:endpoint] = "https://s3-fips.#{region}.amazonaws.com"
273-
end
274-
275+
end
275276
proxy_uri = nil
276277
if InstanceAgent::Config.config[:proxy_uri]
277278
proxy_uri = URI(InstanceAgent::Config.config[:proxy_uri])

test/instance_agent/config_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class InstanceAgentConfigTest < InstanceAgentTestCase
3333
:enable_deployments_log => true,
3434
:kill_agent_max_wait_time_seconds => 7200,
3535
:use_fips_mode => false,
36-
:deploy_control_endpoint => nil
36+
:deploy_control_endpoint => nil,
37+
:s3_endpoint_override => nil
3738
}, InstanceAgent::Config.config)
3839
end
3940

test/instance_agent/plugins/codedeploy/command_executor_test.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,16 @@ def generate_signed_message_for(map)
332332
InstanceAgent::Config.config[:use_fips_mode] = false
333333
end
334334

335-
should "use no endpoint when not using Fips" do
335+
should "use right endpoint when using endpoint override" do
336+
s3_endpoint_override_url = 'htpp://testendpointoverride'
337+
InstanceAgent::Config.config[:s3_endpoint_override] = s3_endpoint_override_url
338+
assert_equal s3_endpoint_override_url, @command_executor.s3_options[:endpoint].to_s
339+
InstanceAgent::Config.config[:s3_endpoint_override] = nil
340+
end
341+
342+
should "use no endpoint when neither using Fips nor Endpoint override" do
343+
InstanceAgent::Config.config[:s3_endpoint_override] = nil
344+
InstanceAgent::Config.config[:use_fips_mode] = false
336345
assert_false @command_executor.s3_options.include? :endpoint
337346
end
338347

0 commit comments

Comments
 (0)