Documentation
¶
Overview ¶
Package authfile is the adapter-layer leaf for mecatl's credentials file: a settings.yaml-sibling YAML file (conventionally $XDG_CONFIG_HOME/mecatl/auth.yaml) holding per-provider secrets: an api_key for the existing keyed providers or a manually supplied OAuth access-token snapshot for openai-codex.
LAYERING: adapter-layer LEAF — stdlib + internal/adapter/xdgconfig only (mirrors xdgconfig's own leaf shape: "Adapters MAY import it; no domain package ever may"). internal/cliconfig is its cmd-layer wiring consumer today; a future credential- writing subcommand (e.g. `mecated auth login`) can depend on this package directly without pulling in cliconfig's flag/model-alias machinery.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPath ¶
func DefaultPath(env xdgconfig.ResolveEnv) string
DefaultPath returns the conventional auth.yaml location: $XDG_CONFIG_HOME/mecatl/auth.yaml, falling back to ~/.config/mecatl/auth.yaml. Empty when neither can be resolved (matches xdgconfig.UserConfigDir).
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is the parsed shape of auth.yaml: a settings.yaml companion that holds credentials. Operator-machine-local only — there is no project-tier equivalent (a project has no business supplying credentials).
func Load ¶
func Load(path string, explicit bool, env xdgconfig.ResolveEnv, knownProviders []string) (*File, string)
Load reads and strictly parses the auth.yaml at path, returning the parsed file (nil if there's nothing to merge) and a human-readable warning (empty if there's nothing to report). It is NEVER fatal — a caller always falls back to whatever it already has — but a non-empty warning should be surfaced (cmd/ mains: slog.Warn) so a typo'd or loosely-permissioned auth.yaml doesn't go unnoticed.
The warning is deliberately VALUE-FREE: it names the path, a provider count, or a permission mode, but never echoes file content back — and a mistyped provider NAME is file content (a key typed where the name belongs is a verified leak shape). A caller may log it unconditionally without risking a secret leak — see the decode-error branch below for why this is asserted rather than merely intended.
knownProviders is the closed set of provider names an entry may use (e.g. "anthropic"); a name outside it is reported rather than silently ignored, while entries that DO match still apply — a typo in one entry shouldn't cost you the rest of the file.
explicit reports whether path came from an operator-supplied override (as opposed to a conventional default) and controls only whether a MISSING file is worth reporting: a missing conventional file is the common, unremarkable case (most operators still use an env var, or haven't created one yet); a missing EXPLICIT path is always reported, since the caller named that exact path. A file that DOES exist but fails to read or parse is always reported, regardless of explicit.
func LoadStrict ¶
func LoadStrict(path string, explicit bool, env xdgconfig.ResolveEnv, knownProviders []string) (*File, error)
LoadStrict is the fail-closed credential-file entry point for callers whose provider set is configuration-derived. Unlike Load's legacy best-effort merge, any file warning rejects the entire snapshot without returning file content.
func (*File) APIKey ¶
APIKey returns the api_key for name, or "" if f is nil or has no entry for name (an absent file, or a provider it doesn't mention, degrades to the empty string exactly like an unset environment variable).
func (*File) OAuth ¶
func (f *File) OAuth(name string) OAuthEntry
OAuth returns a copy of name's validated OAuth file entry. The zero value means there is no usable OAuth entry for name. Returning a value keeps callers from mutating the parsed credential snapshot through this accessor.
func (*File) ValidateKnown ¶
ValidateKnown applies the command root's final provider allowlist to an already parsed immutable snapshot. It is intentionally separate from Load so roots can first discover custom provider IDs, then validate auth.yaml without a second filesystem read.
type OAuthEntry ¶
type OAuthEntry struct {
AccessToken string `yaml:"access_token"`
AccountID string `yaml:"account_id"`
ExpiresAt string `yaml:"expires_at"`
}
OAuthEntry is the raw, immutable-at-runtime OAuth shape accepted at the file boundary. Parsing routing metadata and expiry is deliberately left to the provider adjunct; authfile keeps these fields as strings and never refreshes or writes them.