class Role
Attributes
role_arn[RW]
Public Class Methods
blurb()
click to toggle source
# File lib/aws/sts/role.rb, line 31 def self.blurb puts "aws-sts <role>" end
new(role_arn,region, profile)
click to toggle source
# 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
test_role_arn(role_arn)
click to toggle source
# File lib/aws/sts/role.rb, line 27 def self.test_role_arn(role_arn) role_arn =~ /^arn:aws:iam::(\d+):role\/([^\/]+)(\/.+)?$/ end
Public Instance Methods
print_keys()
click to toggle source
# 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
Private Instance Methods
get_keys()
click to toggle source
# File lib/aws/sts/role.rb, line 47 def get_keys resp = @client.assume_role({ role_arn: @role_arn, role_session_name: @profile, }) resp.credentials end