auth

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package auth contains authentication flows and token storage adapters.

Index

Constants

View Source
const (
	// EnvToken provides an explicit token override.
	EnvToken = "MOCKLET_TOKEN"
)

Variables

View Source
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) ReadToken

func (b FileBackend) ReadToken(_ context.Context, profile string) (string, error)

ReadToken reads token from file storage.

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) ReadToken

func (b KeyringBackend) ReadToken(_ context.Context, profile string) (string, error)

ReadToken reads 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

func (s Store) DeleteToken(ctx context.Context, profile string) error

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

func (Store) WriteToken

func (s Store) WriteToken(ctx context.Context, profile, token string) error

WriteToken persists token. It prefers keyring and falls back to 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL