From d5d580aaf7f31ac0fb288513037ad30617669662 Mon Sep 17 00:00:00 2001 From: Danny Cosson Date: Tue, 23 Jun 2015 17:32:13 -0400 Subject: [PATCH] Don't have synapse require the aws variables - credentials should be able to be nil to allow using iam instance profile. Updates tests to reflect --- lib/synapse/service_watcher/ec2tag.rb | 13 ++++++++----- .../synapse/service_watcher_ec2tags_spec.rb | 18 +++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/synapse/service_watcher/ec2tag.rb b/lib/synapse/service_watcher/ec2tag.rb index 40996aa4..7c5d0d1e 100644 --- a/lib/synapse/service_watcher/ec2tag.rb +++ b/lib/synapse/service_watcher/ec2tag.rb @@ -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 diff --git a/spec/lib/synapse/service_watcher_ec2tags_spec.rb b/spec/lib/synapse/service_watcher_ec2tags_spec.rb index 30aeab37..e04c8fb2 100644 --- a/spec/lib/synapse/service_watcher_ec2tags_spec.rb +++ b/spec/lib/synapse/service_watcher_ec2tags_spec.rb @@ -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 {