Class: Dev::Aws::Profile
- Defined in:
- lib/firespring_dev_commands/aws/profile.rb
Overview
Class containing methods to help write/maintain aws profile information
Constant Summary collapse
- CONFIG_FILE =
The filename where we store the local profile information
"#{Dir.home}/.env.profile".freeze
- IDENTIFIER =
The name of the profile identifier we use
'AWS_PROFILE'.freeze
Instance Method Summary collapse
-
#current ⇒ Object
Retrieve the current profile value Returns nil if one has not been configured.
-
#export_info ⇒ Object
Print the export commands for the current credentials.
-
#info ⇒ Object
Print the profile info for the current account.
-
#write!(profile) ⇒ Object
Write the new profile value to the env file.
Instance Method Details
#current ⇒ Object
Retrieve the current profile value Returns nil if one has not been configured
19 20 21 |
# File 'lib/firespring_dev_commands/aws/profile.rb', line 19 def current ENV.fetch(IDENTIFIER, nil) end |
#export_info ⇒ Object
Print the export commands for the current credentials
57 58 59 60 61 62 63 |
# File 'lib/firespring_dev_commands/aws/profile.rb', line 57 def export_info Dev::Aws::Credentials.new.export! puts "export AWS_DEFAULT_REGION=#{ENV.fetch('AWS_DEFAULT_REGION', nil)}" puts "export AWS_ACCESS_KEY_ID=#{ENV.fetch('AWS_ACCESS_KEY_ID', nil)}" puts "export AWS_SECRET_ACCESS_KEY=#{ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)}" puts "export AWS_SESSION_TOKEN=#{ENV.fetch('AWS_SESSION_TOKEN', nil)}" end |
#info ⇒ Object
Print the profile info for the current account
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/firespring_dev_commands/aws/profile.rb', line 34 def info Dev::Aws::Credentials.new.export! current_role = Dev::Aws::Credentials.new.logged_in_role current_account_name = Dev::Aws::Account.new.name_by_account(current) puts puts " Currently logged in as #{current_role} in the #{current_account_name} (#{current}) account".light_yellow puts puts ' To use this profile in your local aws cli, you must either pass the profile as a command line argument ' \ 'or export the corresponding aws variable:'.light_white puts " aws --profile=#{current} s3 ls" puts ' -OR-'.light_white puts " export #{IDENTIFIER}=#{current}" puts ' aws s3 ls' puts puts ' To use temporary credentials in your terminal, run the following:'.light_white puts " export AWS_DEFAULT_REGION=#{ENV.fetch('AWS_DEFAULT_REGION', nil)}" puts " export AWS_ACCESS_KEY_ID=#{ENV.fetch('AWS_ACCESS_KEY_ID', nil)}" puts " export AWS_SECRET_ACCESS_KEY=#{ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)}" puts " export AWS_SESSION_TOKEN=#{ENV.fetch('AWS_SESSION_TOKEN', nil)}" puts end |
#write!(profile) ⇒ Object
Write the new profile value to the env file
24 25 26 27 28 29 30 31 |
# File 'lib/firespring_dev_commands/aws/profile.rb', line 24 def write!(profile) override = Dev::Env.new(CONFIG_FILE) override.set(IDENTIFIER, profile) override.write # Update any existing ENV variables Dotenv.overload(CONFIG_FILE) end |