class LittleGhost::Providers::VertexAI::CredentialResolver
Resolves Vertex access tokens from explicit values, service-account ADC, or the Google metadata server.
Public Class Methods
# File lib/little_ghost/providers/vertex_ai/credential_resolver.rb, line 18 def initialize(environment: ENV, access_token: nil, clock: -> { Time.now.to_i }) @environment = environment @access_token = access_token @clock = clock @mutex = Mutex.new end
Uses an explicit token or Google application credentials in environment.
Public Instance Methods
# File lib/little_ghost/providers/vertex_ai/credential_resolver.rb, line 26 def call(cancellation_token: nil, deadline: nil) return @access_token unless @access_token.to_s.empty? @mutex.synchronize do return @cached_token if @cached_token && @expires_at && @expires_at > @clock.call + 60 file = @environment["GOOGLE_APPLICATION_CREDENTIALS"] token, expires_in = if file service_account_token(file, cancellation_token:, deadline:) else metadata_token(cancellation_token:, deadline:) end @cached_token = token @expires_at = @clock.call + Integer(expires_in || 3600) token end end
Returns a current access token, refreshing cached credentials as needed.