Documentation
¶
Overview ¶
Package auth contains authentication flows and token storage adapters.
Index ¶
Constants ¶
const (
// EnvToken provides an explicit token override.
EnvToken = "MOCKLET_TOKEN"
)
Variables ¶
var ( // ErrTokenNotFound indicates token is not available in a backend. ErrTokenNotFound = errors.New("token not found") )
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
ReadToken(ctx context.Context, profile string) (string, error)
WriteToken(ctx context.Context, profile, token string) error
DeleteToken(ctx context.Context, profile string) error
}
Backend is a token persistence backend.
type FileBackend ¶
type FileBackend struct {
ConfigDir string
}
FileBackend stores profile tokens on disk with strict permissions.
func (FileBackend) DeleteToken ¶
func (b FileBackend) DeleteToken(_ context.Context, profile string) error
DeleteToken deletes token file.
func (FileBackend) WriteToken ¶
func (b FileBackend) WriteToken(_ context.Context, profile, token string) error
WriteToken writes token to file storage.
type KeyringBackend ¶
type KeyringBackend struct {
Service string
}
KeyringBackend stores tokens in the OS keyring.
func (KeyringBackend) DeleteToken ¶
func (b KeyringBackend) DeleteToken(_ context.Context, profile string) error
DeleteToken removes a token from keyring.
func (KeyringBackend) WriteToken ¶
func (b KeyringBackend) WriteToken(_ context.Context, profile, token string) error
WriteToken writes a token to keyring.
type Store ¶
type Store struct {
LookupEnv func(string) (string, bool)
KeyringBackend Backend
FileBackend Backend
}
Store resolves and persists auth tokens using precedence rules.
func (Store) DeleteToken ¶
DeleteToken removes a token from available backends.
func (Store) ResolveToken ¶
func (s Store) ResolveToken(ctx context.Context, profile string, flagToken string) (TokenValue, error)
ResolveToken resolves token by precedence: 1) --token flag 2) MOCKLET_TOKEN env 3) keyring backend 4) file backend
type TokenSource ¶
type TokenSource string
TokenSource identifies where the effective token was loaded from.
const ( SourceFlag TokenSource = "flag" SourceEnv TokenSource = "env" SourceKeyring TokenSource = "keyring" SourceFile TokenSource = "file" )
type TokenValue ¶
type TokenValue struct {
Value string
Source TokenSource
}
TokenValue carries a resolved token and its source.