auth

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package auth manages authentication token storage for axi-forge. Tokens are stored in a single JSON file at $XDG_CACHE_HOME/axi-forge/credentials.json, keyed by host. The file is the single source of truth — no environment variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollapseHome

func CollapseHome(path string) string

CollapseHome replaces the user's home directory prefix in path with "~". Returns the original path if the home directory cannot be determined.

func DefaultStorePath

func DefaultStorePath() string

DefaultStorePath returns the default path to the credentials file. Uses $XDG_CACHE_HOME if set, otherwise ~/.cache.

func InferForgeType

func InferForgeType(host string) string

InferForgeType returns a forge type identifier (e.g., "github", "gitlab", "forgejo") inferred from the host string.

func ResolveToken

func ResolveToken(host string) (string, error)

ResolveToken returns the token for the given host from the default store, or a TokenError if not found.

Types

type Entry

type Entry struct {
	Host  string
	Token string
}

Entry represents a single stored credential.

type Store

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

Store provides concurrent-safe read/write access to the credentials file. The zero value is not usable; use NewStore to create one.

func NewStore

func NewStore(path string) *Store

NewStore creates a Store backed by the file at the given path. The parent directory must exist; the file is created on first write.

func (*Store) Get

func (s *Store) Get(host string) (string, bool)

Get returns the token for the given host and true if it exists.

func (*Store) List

func (s *Store) List() []Entry

List returns all stored credential entries.

func (*Store) Set

func (s *Store) Set(host, token string) error

Set stores a token for the given host. Creates the file and parent directories if they don't exist. File is created with 0600 permissions.

func (*Store) Unset

func (s *Store) Unset(host string) error

Unset removes the token for the given host. It is a no-op if the host does not exist. Returns an error only if writing the file fails.

type TokenError

type TokenError struct {
	Host string
}

TokenError is a structured error returned when a token is not found for a host. It satisfies forge.StructuredError so main.go can format output uniformly.

func (*TokenError) Error

func (e *TokenError) Error() string

func (*TokenError) Help

func (e *TokenError) Help() string

Help returns the suggested corrective command.

func (*TokenError) Message

func (e *TokenError) Message() string

Message returns the user-facing error message.

Jump to

Keyboard shortcuts

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