Skip to content

Commit

Permalink
Merge pull request forward3d#72 from masarakki/support-dotfile
Browse files Browse the repository at this point in the history
support-dotfile
  • Loading branch information
dlahn authored Aug 18, 2017
2 parents 3ec18d0 + 203d70d commit 918a802
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set :ec2_project_tag, 'Project'
set :ec2_roles_tag, 'Roles'
set :ec2_stages_tag, 'Stages'

set :ec2_profile, 'myservice' # use ~/.aws/credentials with profile_name
set :ec2_access_key_id, nil
set :ec2_secret_access_key, nil
set :ec2_region, %w{} # REQUIRED
Expand All @@ -59,7 +60,7 @@ set :ec2_filter_by_status_ok?, nil
#### Order of inheritance

`cap-ec2` supports multiple methods of configuration. The order of inheritance is:
YAML File > User Capistrano Config > Default Capistrano Config > ENV variables.
YAML File > ~/.aws/credentials > User Capistrano Config > Default Capistrano Config > ENV variables.

#### Regions

Expand Down
10 changes: 10 additions & 0 deletions lib/cap-ec2/utils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'aws-sdk'

module CapEC2
module Utils

Expand Down Expand Up @@ -40,6 +42,14 @@ def self.contact_point(instance)
end

def load_config
if fetch(:ec2_profile)
credentials = Aws::SharedCredentials.new(profile_name: fetch(:ec2_profile)).credentials
if credentials
set :ec2_access_key_id, credentials.access_key_id
set :ec2_secret_access_key, credentials.secret_access_key
end
end

config_location = File.expand_path(fetch(:ec2_config), Dir.pwd) if fetch(:ec2_config)
if config_location && File.exists?(config_location)
config = YAML.load_file fetch(:ec2_config)
Expand Down

0 comments on commit 918a802

Please sign in to comment.