Sha256: af6f464a1ed6ddbceffd0c32799c44d37b6b627777b5c4f953b680e95ec3f35b

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

require_relative "includes"

class AwsAssumeRole::Cli::Actions::ResetEnvironment < AwsAssumeRole::Cli::Actions::AbstractAction
    include AwsAssumeRole::Ui

    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

    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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aws_assume_role-0.2.0 lib/aws_assume_role/cli/actions/reset_environment.rb
aws_assume_role-0.1.2 lib/aws_assume_role/cli/actions/reset_environment.rb
aws_assume_role-0.1.1 lib/aws_assume_role/cli/actions/reset_environment.rb
aws_assume_role-0.1.0 lib/aws_assume_role/cli/actions/reset_environment.rb