Class: Role

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/sts/role.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role_arn, region, profile) ⇒ Role

Returns a new instance of Role.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/aws/sts/role.rb', line 11

def initialize(role_arn,region, profile)
  if self.class.test_role_arn(role_arn)
    @role_arn = role_arn
  else
    raise ArgumentError.new("Role Arn is not valid")
  end

  @region   = region
  @profile  = profile
  @client   = Aws::STS::Client.new(
    region: @region,
    profile: @profile,
  )
end

Instance Attribute Details

#role_arnObject

Returns the value of attribute role_arn.



9
10
11
# File 'lib/aws/sts/role.rb', line 9

def role_arn
  @role_arn
end

Class Method Details

.blurbObject



31
32
33
# File 'lib/aws/sts/role.rb', line 31

def self.blurb
  puts "aws-sts <role>"
end

.test_role_arn(role_arn) ⇒ Object



27
28
29
# File 'lib/aws/sts/role.rb', line 27

def self.test_role_arn(role_arn)
  role_arn =~ /^arn:aws:iam::(\d+):role\/([^\/]+)(\/.+)?$/
end

Instance Method Details



35
36
37
38
39
40
41
42
43
# File 'lib/aws/sts/role.rb', line 35

def print_keys

  credentials = get_keys
  puts "export AWS_ACCESS_KEY_ID=#{credentials.access_key_id}"
  puts "export AWS_SECRET_ACCESS_KEY=#{credentials.secret_access_key}"
  puts "export AWS_SESSION_TOKEN=#{credentials.session_token}"
  puts "export ASSUMED_ROLE=#{@profile}"
  puts "# run eval $(ruby Role.rb <profile>)"
end