Class: AwsMfaSecure::Session

Inherits:
Base
  • Object
show all
Defined in:
lib/aws_mfa_secure/session.rb

Instance Method Summary collapse

Methods inherited from Base

#aws_cli_installed?, #aws_cli_setup?, #aws_config, #aws_mfa_env_set?, #aws_profile, #credentials, #fetch_creds?, #get_session_token, #good_session_creds?, #iam_mfa?, #mfa_prompt, #mfa_serial, #save_creds, #session_creds_path, #shell_get_session_token, #sts

Constructor Details

#initialize(options = {}, *argv) ⇒ Session

Returns a new instance of Session.



3
4
5
6
7
# File 'lib/aws_mfa_secure/session.rb', line 3

def initialize(options={}, *argv)
  @options = options
  @argv = ["aws"] + argv
  @aws_profile = aws_profile
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/aws_mfa_secure/session.rb', line 9

def run
  unless iam_mfa?
    exec(*@argv) # will never get pass this point if there's no mfa_serial setting
  end

  if fetch_creds?
    resp = get_session_token(shell: true)
    save_creds(resp.credentials.to_h)
  end

  ENV['AWS_ACCESS_KEY_ID']     = credentials["access_key_id"]
  ENV['AWS_SECRET_ACCESS_KEY'] = credentials["secret_access_key"]
  ENV['AWS_SESSION_TOKEN']     = credentials["session_token"]
  exec(*@argv)
end