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.
-
#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 |
#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 |
# File 'lib/firespring_dev_commands/aws/profile.rb', line 34 def info Dev::Aws::Credentials.new.export! puts puts " Currently logged in to the #{Dev::Aws::Account.new.name_by_account(current)} (#{current})".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 |