Class: Aliyun::STS::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun/sts/client.rb

Overview

STS服务的客户端,用于向STS申请临时token。

Examples:

创建Client

client = Client.new(
  :access_key_id => 'access_key_id',
  :access_key_secret => 'access_key_secret')
token = client.assume_role('role:arn', 'app')

policy = Policy.new
policy.allow(['oss:Get*'], ['acs:oss:*:*:my-bucket/*'])
token = client.assume_role('role:arn', 'app', policy, 60)
puts token.to_s

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Client

Returns a new instance of Client.



19
20
21
22
# File 'lib/aliyun/sts/client.rb', line 19

def initialize(opts)
  @config = Config.new(opts)
  @protocol = Protocol.new(@config)
end

Instance Method Details

#assume_role(role, session, policy = nil, duration = 3600) ⇒ STS::Token

Assume a role

Parameters:

  • role (String)

    the role arn

  • session (String)

    the session name

  • policy (STS::Policy) (defaults to: nil)

    the policy

  • duration (Integer) (defaults to: 3600)

    the duration seconds for the requested token

Returns:



31
32
33
# File 'lib/aliyun/sts/client.rb', line 31

def assume_role(role, session, policy = nil, duration = 3600)
  @protocol.assume_role(role, session, policy, duration)
end