Skip to content

Commit

Permalink
Add the ability to specify profile name and region in driver url
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeiser committed Jan 27, 2015
1 parent 8cb1640 commit 713f86e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/chef/provisioning/aws_driver/driver.rb
Expand Up @@ -29,7 +29,7 @@ class Driver < Chef::Provisioning::Driver
attr_reader :region

# URL scheme:
# aws:account_id:region
# aws:profilename:region
# TODO: migration path from fog:AWS - parse that URL
# canonical URL calls realpath on <path>
def self.from_url(driver_url, config)
Expand All @@ -38,17 +38,22 @@ def self.from_url(driver_url, config)

def initialize(driver_url, config)
super
credentials = aws_credentials.default
@region = credentials[:region]

scheme, profile_name, region = driver_url.split(':')
puts "driver_url #{driver_url}. #{driver_url.split(':').inspect}"
profile_name = nil if profile_name && profile_name.empty?
region = nil if region && region.empty?

credentials = profile_name ? aws_credentials[profile_name] : aws_credentials.default
@region = region || credentials[:region]
# TODO: fix credentials here
AWS.config(:access_key_id => credentials[:aws_access_key_id],
:secret_access_key => credentials[:aws_secret_access_key],
:region => credentials[:region])
end

def self.canonicalize_url(driver_url, config)
url = driver_url.split(":")[0]
[ "aws:#{url}", config ]
[ driver_url, config ]
end


Expand Down Expand Up @@ -650,7 +655,7 @@ def default_aws_keypair(action_handler, machine_spec)
end

# Only warn the first time
default_warning = 'Using default key, which is not shared between machines! It is recommended to create an AWS key pair with the fog_key_pair resource, and set :bootstrap_options => { :key_name => <key name> }'
default_warning = 'Using default key, which is not shared between machines! It is recommended to create an AWS key pair with the aws_key_pair resource, and set :bootstrap_options => { :key_name => <key name> }'
Chef::Log.warn(default_warning) if updated

default_key_name
Expand Down

0 comments on commit 713f86e

Please sign in to comment.