Class: AwsAssumeRole::Cli::Actions::ResetEnvironment

Inherits:
AbstractAction show all
Includes:
Ui
Defined in:
lib/aws_assume_role/cli/actions/reset_environment.rb

Constant Summary collapse

SHELL_STRINGS =
{
    sh: {
        env_command: "unset %<key>s; ",
    },
    csh: {
        env_command: "unset %<key>s; ",
    },
    fish: {
        env_command: "set -ex %<key>s; ",
        footer: "commands.reset_environment.shells.fish",
    },
    powershell: {
        env_command: "remove-item ENV:%<key>s; ",
        footer: "commands.reset_environment.shells.powershell",
    },
}.freeze
CommandSchema =
proc do
    required(:shell_type).value(included_in?: SHELL_STRINGS.stringify_keys.keys)
end

Constants included from AwsAssumeRole

AwsAssumeRole::Config, DefaultProvider, VERSION

Constants included from Types

Types::ACCESS_KEY_REGEX, Types::ACCESS_KEY_VALIDATOR, Types::ARN_REGEX, Types::Credentials, Types::Dry, Types::EXTERNAL_ID_REGEX, Types::MFA_REGEX, Types::MfaSerial, Types::REGION_REGEX, Types::REGION_VALIDATOR, Types::ROLE_REGEX, Types::ROLE_SESSION_NAME_REGEX, Types::Region, Types::SECRET_ACCESS_KEY_REGEX, Types::SECRET_ACCESS_KEY_VALIDATOR

Instance Method Summary collapse

Methods included from Ui

ask_with_validation, error, input, out, pastel, show_validation_errors, t, validation_errors_to_s

Methods included from AwsAssumeRole

shared_config

Methods inherited from AbstractAction

#initialize

Methods included from Logging

included

Constructor Details

This class inherits a constructor from AwsAssumeRole::Cli::Actions::AbstractAction

Instance Method Details

#act_on(config) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/aws_assume_role/cli/actions/reset_environment.rb', line 27

def act_on(config)
    shell_strings = SHELL_STRINGS[config.shell_type.to_sym]
    str = ""
    %w[AWS_ACCESS_KEY_ID
       AWS_SECRET_ACCESS_KEY
       AWS_SESSION_TOKEN
       AWS_PROFILE
       AWS_ASSUME_ROLE_LOG_LEVEL
       GLI_DEBUG
       AWS_ASSUME_ROLE_KEYRING_BACKEND].each do |key|
        str << format(shell_strings[:env_command], key: key) if ENV.fetch(key, false)
    end
    str << "# #{pastel.yellow t(shell_strings.fetch(:footer, 'commands.set_environment.shells.others'))}"
    puts str
rescue KeyError, Aws::Errors::NoSuchProfileError
    error format(t("errors.NoSuchProfileError"), config.profile)
    raise
rescue Aws::Errors::MissingCredentialsError
    error t("errors.MissingCredentialsError")
    raise
end