cliauth

package
v0.0.0-...-232ca89 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("credentials not found")

ErrNotFound is returned by AuthStore.Load when no credentials are stored.

Functions

func Commands

func Commands(cfg *Config) *cli.Command

Commands builds the "auth" parent command with subcommands based on the capabilities of the configured provider.

func DecorateContext

func DecorateContext(ctx context.Context, cfg *Config) context.Context

DecorateContext calls the configured AuthDecorator and appends the resulting key-value pairs to the outgoing gRPC metadata on the context. Returns the original context unchanged if there is no decorator, on error, or when the decorator returns an empty map (lenient — allows unauthenticated commands to proceed).

Types

type AuthDecorator

type AuthDecorator interface {
	Decorate(ctx context.Context, store AuthStore) (map[string]string, error)
}

AuthDecorator decorates outgoing gRPC requests with authentication metadata.

type AuthStore

type AuthStore interface {
	Save(ctx context.Context, token []byte) error
	Load(ctx context.Context) ([]byte, error)
	Delete(ctx context.Context) error
}

AuthStore provides credential persistence for authentication tokens.

type Config

type Config struct {
	Provider  LoginProvider
	Store     AuthStore
	Decorator AuthDecorator
}

Config holds the auth configuration assembled from a LoginProvider and options.

func NewConfig

func NewConfig(appName string, provider LoginProvider, opts ...Option) *Config

NewConfig creates a Config for the given provider with sensible defaults. If no Store is provided via options, a KeychainStore is used.

type InteractiveLoginProvider

type InteractiveLoginProvider interface {
	LoginProvider
	LoginInteractive(ctx context.Context, in io.Reader, out io.Writer, store AuthStore) error
}

InteractiveLoginProvider extends LoginProvider with interactive prompting support.

type KeychainStore

type KeychainStore struct {
	// contains filtered or unexported fields
}

KeychainStore persists credentials using the OS keychain (macOS Keychain, Windows Credential Manager, Linux Secret Service).

func NewKeychainStore

func NewKeychainStore(appName string) *KeychainStore

NewKeychainStore creates a KeychainStore that stores credentials under the given application name as the keychain service name.

func (*KeychainStore) Delete

func (s *KeychainStore) Delete(_ context.Context) error

Delete removes the stored credential from the keychain. Returns ErrNotFound if no credential is stored.

func (*KeychainStore) Load

func (s *KeychainStore) Load(_ context.Context) ([]byte, error)

Load retrieves the stored credential token from the keychain. Returns ErrNotFound if no credential is stored.

func (*KeychainStore) Save

func (s *KeychainStore) Save(_ context.Context, token []byte) error

Save persists a credential token to the keychain.

type LoginProvider

type LoginProvider interface {
	Flags() []cli.Flag
	Login(ctx context.Context, cmd *cli.Command, store AuthStore) error
}

LoginProvider handles flag-based authentication login.

type LogoutProvider

type LogoutProvider interface {
	Logout(ctx context.Context, store AuthStore) error
}

LogoutProvider adds logout capability to the auth command suite.

type Option

type Option func(*Config)

Option configures an auth Config.

func WithDecorator

func WithDecorator(decorator AuthDecorator) Option

WithDecorator sets an AuthDecorator for decorating outgoing gRPC requests.

func WithStore

func WithStore(store AuthStore) Option

WithStore sets a custom AuthStore instead of the default KeychainStore.

type StatusProvider

type StatusProvider interface {
	Status(ctx context.Context, store AuthStore) (string, error)
}

StatusProvider adds status reporting to the auth command suite.

Jump to

Keyboard shortcuts

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