Class: Oneaws::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/oneaws/cli.rb

Instance Method Summary collapse

Instance Method Details

#getkeyObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/oneaws/cli.rb', line 14

def getkey
  client = Client.new

  params = {
    username: ENV['ONELOGIN_USERNAME'],
    password: ENV['ONELOGIN_PASSWORD'],
    app_id: ENV['ONELOGIN_APP_ID'],
    subdomain: ENV['ONELOGIN_SUBDOMAIN'],
  }
  credential = client.issue_credential(params, options[:otp])

  if options["update_aws_credentials"]
    credential_file = File.expand_path(find_credentials)
    unless inifile = IniFile.load(credential_file)
      FileUtils.mkdir_p(File.dirname(credential_file))
      inifile = IniFile.new
    end

    profile = options["profile"]

    inifile[profile]["aws_access_key_id"] = credential.access_key_id
    inifile[profile]["aws_secret_access_key"] = credential.secret_access_key
    inifile[profile]["aws_session_token"] = credential.session_token
    inifile.write(filename: credential_file)
  end

  case options["eval"]
  when "bash"
    puts <<~EOS
    export AWS_ACCESS_KEY_ID='#{credential.access_key_id}'
    export AWS_SECRET_ACCESS_KEY='#{credential.secret_access_key}'
    export AWS_SESSION_TOKEN='#{credential.session_token}'
    EOS
  when 'fish'
    puts <<~EOS
    set -x AWS_ACCESS_KEY_ID '#{credential.access_key_id}'
    set -x AWS_SECRET_ACCESS_KEY '#{credential.secret_access_key}'
    set -x AWS_SESSION_TOKEN '#{credential.session_token}'
    EOS
  end
end

#versionObject



57
58
59
# File 'lib/oneaws/cli.rb', line 57

def version
  puts Oneaws::VERSION
end