auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package auth models OpenObserve credentials, resolves them from configuration or secure storage, and applies them to outgoing HTTP requests.

Index

Constants

View Source
const (
	// SchemeBasic is HTTP Basic auth: email (username) + password.
	SchemeBasic = "basic"
	// SchemeToken is a pre-generated credential sent verbatim in the
	// Authorization header (the base64 portion of a Basic token, or a full
	// "Basic …" / "Bearer …" value).
	SchemeToken = "token"
)

Scheme identifies an authentication scheme.

View Source
const (
	BackendKeychain = "keychain"
	BackendFile     = "file"
)

Backend names reported by Save.

Variables

View Source
var ErrSecretNotFound = errors.New("secret not found")

ErrSecretNotFound is returned by a Store when no secret exists for an account.

Functions

func AccountKey

func AccountKey(baseURL, scheme string) string

AccountKey derives the keychain account identifier for a base URL and scheme. It is stable across runs so credentials can be located later.

func Forget

func Forget(baseURL, scheme string, store *Store) error

Forget removes any stored secret for the base URL and scheme.

func Save

func Save(baseURL string, cred Credential, store *Store) (string, error)

Save stores a credential's secret for later resolution and returns the backend ("keychain" or "file") that accepted it.

Types

type Credential

type Credential struct {
	Scheme   string
	Username string // basic only (the account email)
	Secret   string // password (basic) or token value (token)
}

Credential is a fully resolved credential ready to authenticate requests.

func Resolve

func Resolve(cfg config.Config, secrets config.Secrets, store *Store) (Credential, error)

Resolve produces a Credential from configuration. A secret supplied via flags/env/.env (carried in secrets) takes precedence; otherwise the secret is loaded from the Store. The returned credential is validated.

func (Credential) Decorator

func (c Credential) Decorator() transport.Decorator

Decorator returns a transport.Decorator that authenticates every request.

func (Credential) Header

func (c Credential) Header() string

Header returns the Authorization header value for the credential.

OpenObserve authenticates API requests with HTTP Basic auth. For the basic scheme we encode email:password; for the token scheme the user supplies a pre-generated credential — either the already-base64-encoded basic token, or a full "Basic …" / "Bearer …" header value, which we pass through verbatim.

func (Credential) Redacted

func (c Credential) Redacted() Credential

Redacted returns a copy safe for logging: the secret is masked.

func (Credential) Validate

func (c Credential) Validate() error

Validate reports whether the credential is internally consistent.

type Store

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

Store persists secrets. It prefers the OS keychain and transparently falls back to a 0600 file under the config directory when the keychain is unavailable (headless Linux, CI, locked keychain).

func NewStore

func NewStore(dir string) *Store

NewStore returns a Store whose file fallback lives in dir.

func (*Store) Delete

func (s *Store) Delete(account string) error

Delete removes the secret for account from both backends. Missing entries are not an error.

func (*Store) Load

func (s *Store) Load(account string) (string, error)

Load retrieves the secret for account, trying the keychain then the file. It returns ErrSecretNotFound when neither holds a value.

func (*Store) Save

func (s *Store) Save(account, secret string) (string, error)

Save stores secret for account and returns the backend that accepted it.

Jump to

Keyboard shortcuts

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