class Github::Authentication::Provider
Constants
- Error
- TokenGeneratorError
Public Class Methods
new(generator:, cache:)
click to toggle source
Calls superclass method
# File lib/github/authentication/provider.rb, line 15 def initialize(generator:, cache:) super() @token = nil @generator = generator @cache = cache end
Public Instance Methods
inspect()
click to toggle source
prevent credential leak
# File lib/github/authentication/provider.rb, line 51 def inspect "#<#{self.class.name}>" end
reset_token()
click to toggle source
# File lib/github/authentication/provider.rb, line 45 def reset_token @token = nil @cache.clear end
token(seconds_ttl: 5 * 60)
click to toggle source
# File lib/github/authentication/provider.rb, line 22 def token(seconds_ttl: 5 * 60) return @token if @token&.valid_for?(seconds_ttl) with_retries(TokenGeneratorError) do mu_synchronize do return @token if @token&.valid_for?(seconds_ttl) if (@token = @cache.read) return @token if @token.valid_for?(seconds_ttl) end if (@token = @generator.generate) if @token.valid_for?(seconds_ttl) @cache.write(@token) return @token end end raise TokenGeneratorError, "Couldn't create a token with a TTL of #{seconds_ttl}" end end end