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



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

#closeObject

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



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

def close
  @actor.close
end

#get_token(force: false) ⇒ String

Get the current access token



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

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