auth

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package auth resolves SCM credentials per repository owner through pluggable backends, allowing separate accounts for each configured project.

Credentials are looked up by host and owner, cached in memory for the lifetime of the process, and never written to viper or to disk. No configuration field holds a credential directly: settings name an environment variable, an external command, or a gh CLI account from which the credential is read.

Index

Constants

View Source
const (
	// BackendAuto tries each available source in turn. This is the default.
	BackendAuto = "auto"
	// BackendEnv reads the credential from the environment variable named by auth.env.
	BackendEnv = "env"
	// BackendGh reads the credential from the gh CLI (GitHub only).
	BackendGh = "gh"
	// BackendCommand reads the credential from the stdout of an external command.
	BackendCommand = "command"
	// BackendNone makes unauthenticated requests.
	BackendNone = "none"
)

Supported credential backends, selected via the auth.provider setting.

Variables

Backends lists every supported auth.provider value.

View Source
var ErrNoCredential = errors.New("no credential found")

ErrNoCredential is returned when no configured backend yields a credential.

Functions

func Owners

func Owners(ctx context.Context) []string

Owners returns the owners which have an explicit auth.owners entry.

func Reset

func Reset()

Reset clears the in-memory credential cache. It exists for tests and for commands which need to re-resolve credentials after changing configuration.

func Sorted

func Sorted(owners ...string) []string

Sorted returns the given owners deduplicated and sorted, dropping empty names.

func Token

func Token(ctx context.Context, host, owner string) (string, error)

Token returns the credential for the given host and owner, resolving it through the configured backend on first use and caching the result in memory. An empty token with a nil error means the owner is configured for unauthenticated access.

func Validate

func Validate(ctx context.Context, host, owner string) error

Validate reports whether a credential can be resolved for the given host and owner, without exposing the credential itself.

Types

type Scope

type Scope struct {
	// Owner is the project or organization these settings apply to.
	Owner string
	// Provider names the backend used to resolve the credential.
	Provider string
	// Env names the environment variable holding the credential. It never holds
	// the credential itself.
	Env string
	// Command is the argv of an external command whose stdout is the credential.
	Command []string
	// Account optionally selects a specific gh CLI account.
	Account string
}

Scope is the set of credential settings which apply to a single owner. Values are merged from the top-level auth settings and any matching auth.owners entry.

func ResolveScope

func ResolveScope(ctx context.Context, owner string) Scope

ResolveScope merges the auth.owners entry for the given owner over the top-level auth settings. An owner entry only overrides the fields it sets.

func (Scope) Source

func (s Scope) Source() string

Source describes where this scope's credential comes from, without resolving it.

type Status

type Status struct {
	// Owner is the project or organization this status describes.
	Owner string
	// Provider is the backend which resolved (or failed to resolve) the credential.
	Provider string
	// Source describes where the credential came from, or would come from.
	Source string
	// Fingerprint is a truncated SHA-256 digest of the credential. It is empty when
	// no credential was resolved or the owner needs none.
	Fingerprint string
	// Unauthenticated reports whether the owner is deliberately configured without
	// a credential via the "none" backend.
	Unauthenticated bool
	// Err records why resolution failed, if it did.
	Err error
}

Status describes the outcome of credential resolution for a single owner. It deliberately carries no credential: the digest is one-way and truncated, so a Status can be rendered without any risk of exposing the underlying secret.

func Describe

func Describe(ctx context.Context, host, owner string) Status

Describe resolves the credential for the given host and owner and reports the outcome without exposing the credential itself.

func DescribeAll

func DescribeAll(ctx context.Context, host string, owners ...string) []Status

DescribeAll reports the credential status for every given owner, preserving the order in which they were supplied.

func (Status) OK

func (s Status) OK() bool

OK reports whether a credential was resolved, or is deliberately not required.

Jump to

Keyboard shortcuts

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