Sha256: 3cccbf0ec11cbc344565a02ca2fea4a6fcdf4588781351afd5a5832db486449c

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

require_relative "includes"
require_relative "../../credentials/factories/default_chain_provider"

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

    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: [: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

    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.account, 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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aws_assume_role-0.2.0 lib/aws_assume_role/cli/actions/test.rb
aws_assume_role-0.1.2 lib/aws_assume_role/cli/actions/test.rb