Class: StatelyDB::Common::Auth::AuthTokenProvider

Inherits:
TokenProvider
  • Object
show all
Defined in:
lib/common/auth/auth_token_provider.rb

Overview

AuthTokenProvider is an implementation of the TokenProvider abstract base class which vends tokens from the StatelyDB auth API. It will default to using the value of STATELY_ACCESS_KEY if no credentials are explicitly passed and will throw an error if no credentials are found.

Defined Under Namespace

Classes: Actor, TokenState

Instance Method Summary collapse

Constructor Details

#initialize(endpoint: "https://api.stately.cloud", access_key: ENV.fetch("STATELY_ACCESS_KEY", nil), base_retry_backoff_secs: 1) ⇒ AuthTokenProvider

Returns a new instance of AuthTokenProvider.

Parameters:

  • endpoint (String) (defaults to: "https://api.stately.cloud")

    The endpoint of the auth server

  • access_key (String) (defaults to: ENV.fetch("STATELY_ACCESS_KEY", nil))

    The StatelyDB access key credential

  • base_retry_backoff_secs (Float) (defaults to: 1)

    The base retry backoff in seconds



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/common/auth/auth_token_provider.rb', line 30

def initialize(
  endpoint: "https://api.stately.cloud",
  access_key: ENV.fetch("STATELY_ACCESS_KEY", nil),
  base_retry_backoff_secs: 1
)
  super()
  @actor = Async::Actor.new(Actor.new(endpoint:, access_key:, base_retry_backoff_secs:))
  # this initialization cannot happen in the constructor because it is async and must run on the event loop
  # which is not available in the constructor
  @actor.init
end

Instance Method Details

#closevoid

This method returns an undefined value.

Close the token provider and kill any background operations This just invokes the close method on the actor which should do the cleanup



45
46
47
# File 'lib/common/auth/auth_token_provider.rb', line 45

def close
  @actor.close
end

#get_token(force: false) ⇒ String

Get the current access token

Returns:

  • (String)

    The current access token



51
52
53
# File 'lib/common/auth/auth_token_provider.rb', line 51

def get_token(force: false)
  @actor.get_token(force: force)
end