Class: AwsMskIamSaslSigner::MSKTokenProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-msk-iam-sasl-signer/msk_token_provider.rb

Defined Under Namespace

Classes: AuthToken, CallerIdentity

Constant Summary collapse

ENDPOINT_URL_TEMPLATE =
"kafka.{}.amazonaws.com"
DEFAULT_TOKEN_EXPIRY_SECONDS =
900
LIB_NAME =
"aws-msk-iam-sasl-signer-msk-iam-sasl-signer-ruby"
USER_AGENT_KEY =
"User-Agent"
SESSION_NAME =
"MSKSASLDefaultSession"

Instance Method Summary collapse

Constructor Details

#initialize(region:) ⇒ MSKTokenProvider

Returns a new instance of MSKTokenProvider.



18
19
20
# File 'lib/aws-msk-iam-sasl-signer/msk_token_provider.rb', line 18

def initialize(region:)
  @region = region
end

Instance Method Details

#generate_auth_token(aws_debug: false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/aws-msk-iam-sasl-signer/msk_token_provider.rb', line 22

def generate_auth_token(aws_debug: false)
  credentials = CredentialsResolver.new.from_credential_provider_chain(@region)
  caller_identity = caller_identity(credentials, @region) if aws_debug
  url = presign(credentials, endpoint_url)
  AuthToken.new(
    urlsafe_encode64(user_agent(url)),
    expiration_time_ms(url),
    caller_identity
  )
end

#generate_auth_token_from_credentials_provider(credentials_provider) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/aws-msk-iam-sasl-signer/msk_token_provider.rb', line 55

def generate_auth_token_from_credentials_provider(credentials_provider)
  raise "Invalid credentials provider" unless credentials_provider.respond_to?(:credentials)

  url = presign(credentials_provider, endpoint_url)
  AuthToken.new(
    urlsafe_encode64(user_agent(url)),
    expiration_time_ms(url)
  )
end

#generate_auth_token_from_profile(profile) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/aws-msk-iam-sasl-signer/msk_token_provider.rb', line 33

def generate_auth_token_from_profile(profile)
  credentials = CredentialsResolver.new.from_profile(profile)
  url = presign(credentials, endpoint_url)
  AuthToken.new(
    urlsafe_encode64(user_agent(url)),
    expiration_time_ms(url)
  )
end

#generate_auth_token_from_role_arn(role_arn, session_name = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aws-msk-iam-sasl-signer/msk_token_provider.rb', line 42

def generate_auth_token_from_role_arn(role_arn, session_name=nil)
  session_name ||= SESSION_NAME
  credentials = CredentialsResolver.new.from_role_arn(
    role_arn: role_arn,
    session_name: session_name
  )
  url = presign(credentials, endpoint_url)
  AuthToken.new(
    urlsafe_encode64(user_agent(url)),
    expiration_time_ms(url)
  )
end