Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoNewTokenResolved = errors.New("no new token resolved")
var ErrNoValidTokenResolved = errors.New("no valid token returned")
Functions ¶
This section is empty.
Types ¶
type BasicTokenStore ¶
type BasicTokenStore struct {
// contains filtered or unexported fields
}
BasicTokenStore provides feature to refresh token and return cached token. BasicTokenStore memory the expired tokens and it calls resolvers in order to get new token after MarkTokenExpired called.
func NewBasicTokenStore ¶
func NewBasicTokenStore(tokenType string, resolver TokenResolver) *BasicTokenStore
func (*BasicTokenStore) Digest ¶
func (b *BasicTokenStore) Digest() string
Digest implements TokenStore.
func (*BasicTokenStore) GetToken ¶
func (b *BasicTokenStore) GetToken(ctx context.Context) (*Token, error)
GetToken implements TokenStore.
func (*BasicTokenStore) GetType ¶
func (b *BasicTokenStore) GetType() string
func (*BasicTokenStore) IsTokenValidityAssured ¶
func (b *BasicTokenStore) IsTokenValidityAssured(ctx context.Context) bool
func (*BasicTokenStore) RefreshToken ¶
func (b *BasicTokenStore) RefreshToken(ctx context.Context) error
RefreshToken implements TokenStore. A token store can be referenced from multiple http client and these can call RefreshToken multiple times in parallel just after token expiration. RefreshToken() will ignore the refresh request when it can't acquire the write lock and wait until the lock to be acquired.
type MockErrorTokenResolver ¶
type MockErrorTokenResolver struct{}
func NewMockErrorTokenResolver ¶
func NewMockErrorTokenResolver() *MockErrorTokenResolver
type MultiTokenResolver ¶
type MultiTokenResolver struct {
// contains filtered or unexported fields
}
func NewMultiTokenResolver ¶
func NewMultiTokenResolver(resolvers ...TokenResolver) *MultiTokenResolver
type MultiTokenStoreRefresher ¶
type MultiTokenStoreRefresher struct {
// contains filtered or unexported fields
}
MultiTokenStoreRefresher implements the TokenRefresher to refresh tokens in multiple stores. This rotate the next token store to be refreshed but it will ignore if the token is assured to be alive from the expiry time.
func NewMultiTokenStoreRefresher ¶
func NewMultiTokenStoreRefresher(tokenStores ...TokenStore) *MultiTokenStoreRefresher
type NopTokenRefresher ¶
type NopTokenRefresher struct { }
type OnceTokenResolver ¶
type OnceTokenResolver struct {
// contains filtered or unexported fields
}
OnceTokenResolver resolves the token from somewhere only onetime. This is mainly used for resolving token from CLI arguments or environment variables.
func NewOnceTokenResolver ¶
func NewOnceTokenResolver(resolver func() string) *OnceTokenResolver
type SpyTokenResolver ¶
type SpyTokenResolver struct {
// contains filtered or unexported fields
}
func NewSpyTokenResolver ¶
func NewSpyTokenResolver(tokenResponse ...*Token) *SpyTokenResolver
func NewSpyTokenResolverWithDelay ¶
func NewSpyTokenResolverWithDelay(delayInMillisecond int, tokenResponse ...*Token) *SpyTokenResolver
type Token ¶
type Token struct { // RawToken is the actual token in string representation. RawToken string // ValidAtLeastUntil holds the expiration time when the information is available. // The token refreshers won't refresh token if this value exists and later than now. // The default value will be `January 1, year 1, 00:00:00.000000000 UTC` and it is earlier than the possible time.Now(). // The default value naturally means the token is expired. ValidAtLeastUntil time.Time }
Token contains the token string like access token.
type TokenRefresher ¶
type TokenResolver ¶
type TokenResolver interface { // Resolve returns the token newly resolved. Resolve(ctx context.Context) (*Token, error) }
TokenResolver resolve the new token
type TokenStore ¶
type TokenStore interface { task.CachableDependency GetType() string // GetToken returns the current token. It can come from cache or newly resolved from TokenResolver. GetToken(ctx context.Context) (*Token, error) // IsTokenValidityAssured returns true if this token is assured to be valid now. // When a permission error happens, refresher may attempt to refresh tokens. The refresh is only needed when the token can be expired(when we don't know the expiration time) or the token is actually expired. IsTokenValidityAssured(ctx context.Context) bool // RefreshToken refreshes the token returned from GetToken() RefreshToken(ctx context.Context) error }