Class: Aws::Session::Credentials::SessionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/session/credentials/session_manager.rb

Overview

Manages sessions

Instance Method Summary collapse

Instance Method Details

#assume_role(options) ⇒ Object

Assumes a role from provided options

Parameters:

  • options (Hash)

Options Hash (options):

  • :profile (String)
  • :role_arn (String)
  • :duration (String)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/aws/session/credentials/session_manager.rb', line 11

def assume_role(options)
  options[:profile] = options[:profile].to_sym

  session_prof = Cache.new.profile(options[:profile])
  options = session_prof.to_h.deep_merge(options).deep_symbolize_keys

  sb = SessionBuilder.new(
    mfa_device: mfa_device(options),
    role_duration_seconds: options[:duration],
    role_arn: options[:role_arn],
    role_session_name: options[:role_session_name],
    source_profile: session_prof
  )
  role_profile = sb.role_profile

  CredentialFile.new.set_profile(options[:profile], role_profile)
end

#new_session(options) ⇒ Object

Creates a new session from provided options

Parameters:

  • options (Hash)

Options Hash (options):

  • :aws_access_key_id (String)
  • :aws_secret_access_key (String)
  • :aws_session_token (String)
  • :aws_region (String)
  • :source_profile (String)
  • :profile (String)
  • :duration (String)
  • :mfa_device (String)
  • :mfa_code (String)
  • :yubikey_name (String)
  • :oath_credential (String)
  • :config_file (String)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/aws/session/credentials/session_manager.rb', line 43

def new_session(options)
  options[:source_profile] = options[:source_profile].to_sym
  options[:profile] = options[:profile].to_sym

  user_prof = (options[:source_profile], options[:config_file])
  options = user_prof.to_h.deep_merge(options).deep_symbolize_keys

  sb = SessionBuilder.new(
    mfa_device: mfa_device(options),
    session_duration_seconds: options[:duration],
    source_profile: user_prof
  )
  set_user_session_profile(options[:profile], sb.session_profile)
end