Skip to content

Commit

Permalink
Don't have synapse require the aws variables - credentials should be
Browse files Browse the repository at this point in the history
able to be nil to allow using iam instance profile. Updates tests to
reflect
  • Loading branch information
dcosson committed Sep 11, 2015
1 parent c59116e commit d5d580a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
13 changes: 8 additions & 5 deletions lib/synapse/service_watcher/ec2tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ def validate_discovery_opts
raise ArgumentError, "Invalid server_port_override value"
end

# Required, but can use well-known environment variables.
%w[aws_access_key_id aws_secret_access_key aws_region].each do |attr|
unless (@discovery[attr] || ENV[attr.upcase])
raise ArgumentError, "Missing #{attr} option or #{attr.upcase} environment variable"
end
# aws region is optional in the SDK, aws will use a default value if not provided
unless @discovery['aws_region'] || ENV['AWS_REGION']
log.info "aws region is missing, will use default"
end
# access key id & secret are optional, might be using IAM instance profile for credentials
unless ((@discovery['aws_access_key_id'] || ENV['aws_access_key_id']) \
&& (@discovery['aws_secret_access_key'] || ENV['aws_secret_access_key'] ))
log.info "aws access key id & secret not set in config or env variables for service #{name}, will attempt to use IAM instance profile"
end
end

Expand Down
18 changes: 9 additions & 9 deletions spec/lib/synapse/service_watcher_ec2tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ def munge_haproxy_arg(name, new_value)
end

context 'when missing arguments' do
it 'complains if aws_region is missing' do
it 'does not break if aws_region is missing' do
expect {
Synapse::ServiceWatcher::Ec2tagWatcher.new(remove_discovery_arg('aws_region'), mock_synapse)
}.to raise_error(ArgumentError, /Missing aws_region/)
Synapse::ServiceWatcher::EC2Watcher.new(remove_discovery_arg('aws_region'), mock_synapse)
}.not_to raise_error
end
it 'complains if aws_access_key_id is missing' do
it 'does not break if aws_access_key_id is missing' do
expect {
Synapse::ServiceWatcher::Ec2tagWatcher.new(remove_discovery_arg('aws_access_key_id'), mock_synapse)
}.to raise_error(ArgumentError, /Missing aws_access_key_id/)
Synapse::ServiceWatcher::EC2Watcher.new(remove_discovery_arg('aws_access_key_id'), mock_synapse)
}.not_to raise_error
end
it 'complains if aws_secret_access_key is missing' do
it 'does not break if aws_secret_access_key is missing' do
expect {
Synapse::ServiceWatcher::Ec2tagWatcher.new(remove_discovery_arg('aws_secret_access_key'), mock_synapse)
}.to raise_error(ArgumentError, /Missing aws_secret_access_key/)
Synapse::ServiceWatcher::EC2Watcher.new(remove_discovery_arg('aws_secret_access_key'), mock_synapse)
}.not_to raise_error
end
it 'complains if server_port_override is missing' do
expect {
Expand Down

0 comments on commit d5d580a

Please sign in to comment.