Class: AwsAssumeRole::Cli::Actions::Test

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

Constant Summary collapse

CommandSchema =
proc do
    required(:profile).maybe
    optional(:region) { filled? > format?(REGION_REGEX) }
    optional(:serial_number) { filled? > format?(MFA_REGEX) }
    required(:role_arn).maybe
    required(:role_session_name).maybe
    required(:duration_seconds).maybe
    rule(role_specification: %i[profile role_arn role_session_name duration_seconds]) do |p, r, s, d|
        (p.filled? | p.empty? & r.filled?) & (r.filled? > s.filled? & d.filled?)
    end
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


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aws_assume_role/cli/actions/test.rb', line 19

def act_on(config)
    logger.debug "Will try for credentials"
    credentials = try_for_credentials config
    logger.debug "Got credentials #{credentials}"
    client = Aws::STS::Client.new(credentials: credentials, region: resolved_region)
    identity = client.get_caller_identity
    out format(t("commands.test.output"), identity., identity.arn, identity.user_id)
rescue KeyError, Aws::Errors::NoSuchProfileError
    error format(t("errors.NoSuchProfileError"), config.profile)
    raise
rescue Aws::Errors::MissingCredentialsError
    error t("errors.MissingCredentialsError")
    raise
end