module AwsRunAs::Cli

Public Instance Methods

load_opts(args: ARGV) click to toggle source

loads the command-line options.

# File lib/aws_runas/cli.rb, line 25
    def load_opts(args: ARGV)
      Trollop.options(args) do
        banner <<-EOS.gsub(/^ {10}/, '')
          aws-runas: Run commands under AWS IAM roles

          Usage:
            aws-runas [options] COMMAND ARGS

          If COMMAND is omitted, the default shell ($SHELL, /bin/sh, or cmd.exe,
          depending on your system) will launch.

          [options] are:
        EOS

        opt :no_role, 'Get a session token only, do not assume a role', type: TrueClass, default: nil
        opt :skip_prompt, 'Do not launch interactive sessions with the fancy prompt', type: TrueClass, default: nil
        opt :path, 'Path to the AWS config file', type: String
        opt :profile, 'The AWS profile to load', type: String, default: 'default'
        stop_on_unknown
      end
    end
read_mfa_if_needed(path: nil, profile: 'default') click to toggle source

Reads the MFA code from standard input.

# File lib/aws_runas/cli.rb, line 59
def read_mfa_if_needed(path: nil, profile: 'default')
  @cfg = AwsRunAs::Config.new(path: path, profile: profile)
  return nil unless @cfg.mfa_required?
  STDOUT.print 'Enter MFA code: '
  STDOUT.flush
  STDIN.gets.chomp
end
start() click to toggle source

Start the CLI. Load options (profile, specific config path), and run main.

# File lib/aws_runas/cli.rb, line 49
def start
  opts = load_opts
  mfa_code = read_mfa_if_needed(path: opts[:path], profile: opts[:profile])
  @main = AwsRunAs::Main.new(path: opts[:path], profile: opts[:profile], mfa_code: mfa_code, no_role: opts[:no_role])
  @main.assume_role
  command = ARGV.shift
  @main.handoff(command: command, argv: ARGV, skip_prompt: opts[:skip_prompt])
end