auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package auth loads OSF credentials from caller-provided sources and redacts secrets from user-visible errors and logs.

Index

Constants

View Source
const PasswordEnv = "OSF_PASSWORD"

PasswordEnv is the environment variable that stores the OSF password.

View Source
const TokenEnv = "OSF_TOKEN"

TokenEnv is the environment variable that stores the OSF personal access token.

View Source
const UsernameEnv = "OSF_USERNAME"

UsernameEnv is the environment variable that stores the OSF username/email.

Variables

This section is empty.

Functions

func LoadToken

func LoadToken(source Source) (string, error)

LoadToken returns the trimmed OSF personal access token from the supplied source.

func Redact

func Redact(text string, secrets ...string) string

Redact removes token-like values from loggable text.

func RedactError

func RedactError(err error, secrets ...string) error

RedactError returns an error whose message has sensitive values removed.

Types

type Credentials

type Credentials struct {
	Mode     Mode
	Token    string
	Username string
	Password string
}

Credentials contains the selected OSF credential material.

func LoadCredentials

func LoadCredentials(source Source) (Credentials, error)

LoadCredentials selects credentials from the supplied source.

OSF_TOKEN has precedence. OSF_USERNAME and OSF_PASSWORD are used only when no token is present.

func (Credentials) Authenticated

func (c Credentials) Authenticated() bool

Authenticated reports whether the credentials can authenticate OSF requests.

func (Credentials) Secrets

func (c Credentials) Secrets() []string

Secrets returns concrete secret values that should be redacted from output.

type EnvSource

type EnvSource struct{}

EnvSource reads values from the process environment.

func (EnvSource) Lookup

func (EnvSource) Lookup(name string) (string, bool)

Lookup implements Source.

type FuncSource

type FuncSource func(name string) (string, bool)

FuncSource adapts a lookup function into a Source.

func (FuncSource) Lookup

func (f FuncSource) Lookup(name string) (string, bool)

Lookup implements Source.

type MissingCredentialsError

type MissingCredentialsError struct {
	UsernamePresent bool
	PasswordPresent bool
}

MissingCredentialsError reports that no complete supported credential set was found.

func (MissingCredentialsError) Error

func (e MissingCredentialsError) Error() string

Error implements error.

type MissingTokenError

type MissingTokenError struct {
	Env string
}

MissingTokenError reports that no usable token was found.

func (MissingTokenError) Error

func (e MissingTokenError) Error() string

Error implements error.

type Mode

type Mode string

Mode identifies the credential mechanism used for OSF requests.

const (
	// ModeAnonymous means no credentials were supplied.
	ModeAnonymous Mode = "anonymous"
	// ModeBearerToken means requests should use Authorization: Bearer.
	ModeBearerToken Mode = "bearer-token"
	// ModeUsernamePassword means requests should use username/password signing.
	ModeUsernamePassword Mode = "username-password"
)

type Source

type Source interface {
	Lookup(name string) (string, bool)
}

Source supplies named values without forcing callers to read the process env.

Jump to

Keyboard shortcuts

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