Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
Ensure default region is used when none specified
Browse files Browse the repository at this point in the history
The prior behavior caused region to be set to `""` when no region was
configured. This ended up causing a AWS `ops_works_region` to be set to `""`.
And, this ended up causing the `ops_works_endpoint` to be set to
`opsworks..amazonaws.com` instead of something like `opsworks.us-
east-1.amazonaws.com`. So, we work around this by ensuring `nil` is passed in
when no region is specified.
  • Loading branch information
ptoomey3 committed Jun 8, 2017
1 parent 1786eb4 commit 78f0181
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/services/aws_ops_works.rb
Expand Up @@ -141,9 +141,13 @@ def create_deployment
end

def ops_works_client
region = config_value('endpoint_region')
# The AWS library requires you pass `nil`, and not an empty string, if you
# want to connect to a legitimate default AWS host name.
region = nil if region.empty?
AWS::OpsWorks::Client.new access_key_id: required_config_value('aws_access_key_id'),
secret_access_key: required_config_value('aws_secret_access_key'),
region: config_value('endpoint_region')
region: region
end

def github_api_url
Expand Down
12 changes: 12 additions & 0 deletions test/aws_ops_works_test.rb
Expand Up @@ -52,6 +52,11 @@ def test_aws_access_key_id_configured
assert_equal sample_data['aws_access_key_id'], config.access_key_id
end

def test_region_configured
config = service.ops_works_client.config
assert_equal sample_data['region'], config.ops_works_region
end

def test_aws_access_key_id_missing
svc = service(sample_data.except('aws_access_key_id'))
assert_raises Service::ConfigurationError do
Expand All @@ -71,6 +76,12 @@ def test_aws_secret_access_key_missing
end
end

def test_region_blank
svc = service(sample_data.merge('region' => ""))
config = service.ops_works_client.config
assert_equal sample_data['region'], config.ops_works_region
end

def service(data = sample_data, payload = sample_payload)
Service::AwsOpsWorks.new(:push, data, payload)
end
Expand All @@ -81,6 +92,7 @@ def sample_data
'aws_secret_access_key' => '0123456789+0123456789+0123456789+0123456',
'stack_id' => '12345678-1234-1234-1234-123456789012',
'app_id' => '01234567-0123-0123-0123-012345678901',
'region' => "us-east-1",
'branch_name' => 'default-branch'
}
end
Expand Down

0 comments on commit 78f0181

Please sign in to comment.