auth

package
v0.2.0-rc.3 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: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCredentialsPath = "~/.mcpsmithy/credentials"

DefaultCredentialsPath is the credentials file location used when no explicit path is given. It deliberately lives outside any project directory: file_read is sandboxed to the project root, so a credentials file inside a project could be handed to the agent or picked up by a local source glob.

Variables

This section is empty.

Functions

func NetrcExists

func NetrcExists() bool

NetrcExists reports whether a netrc file is present in the user's home directory. Callers use it to warn that the deprecated credential source is being relied on.

Types

type Credential

type Credential struct {
	// Auth scheme prefixing the token, e.g. "Token". Defaults to "Bearer"
	// when the credential targets the Authorization header, and to no scheme
	// when it targets a custom header.
	Scheme string `yaml:"scheme,omitempty"`
	// Header to carry the credential. Defaults to "Authorization".
	// Set it for APIs that use their own header, e.g. "PRIVATE-TOKEN".
	Header string `yaml:"header,omitempty"`
	// Static API token. Mutually exclusive with username/password.
	Token string `yaml:"token,omitempty"`
	// Username for Basic auth. Mutually exclusive with token.
	Username string `yaml:"username,omitempty"`
	// Password for Basic auth.
	Password string `yaml:"password,omitempty"`
}

Credential is the auth material for a single host.

The fields present determine the header that gets sent:

token                     → Authorization: Bearer <token>
token + scheme            → Authorization: <scheme> <token>
token + header            → <header>: <token>
token + header + scheme   → <header>: <scheme> <token>
username + password       → Authorization: Basic base64(username:password)

type Store

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

Store resolves credentials by hostname. Hosts absent from the store fall back to ~/.netrc, which is deprecated but still honoured.

A nil *Store applies no credentials at all, which keeps callers that have no credential source (tests, or code paths that must not authenticate) simple.

func Load

func Load(path string) (*Store, error)

Load reads a credentials file and returns a Store.

A missing file is not an error: the returned Store is empty and every lookup falls back to ~/.netrc, matching the silent-miss behaviour netrc has always had. A file that exists but cannot be read, parsed, or validated is an error, because silently ignoring a malformed credentials file would look like an authentication bug at request time.

func (*Store) Apply

func (s *Store) Apply(req *http.Request)

Apply sets the auth header on req for the request's hostname. Hosts without an entry fall back to ~/.netrc. A nil Store is a no-op.

func (*Store) HasCredentials

func (s *Store) HasCredentials() bool

HasCredentials reports whether the store holds any entries. Callers use it to decide whether to warn that netrc is being relied on.

Jump to

Keyboard shortcuts

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