credpool

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRateLimitFallback = 60 * time.Second

DefaultRateLimitFallback is used when Retry-After is missing or unparseable.

Variables

View Source
var ErrNoUsableCredential = errors.New("credpool: no usable credential")

ErrNoUsableCredential is returned by Pool.Acquire when every credential is excluded, in cooldown, or permanently auth-invalid. Its message never includes API key material.

Functions

func BackendKeySecrets

func BackendKeySecrets(apiKey string, apiKeys []string) ([]string, error)

BackendKeySecrets returns ordered non-empty trimmed secrets for a hosted backend instance: api_key first (when non-empty after trim), then api_keys in order. Duplicate secrets are dropped while preserving first-seen order (api_key then api_keys, aligned with pluginreg.EffectiveAPIKeys for the YAML credential fields).

func CooldownFromRetryAfter

func CooldownFromRetryAfter(value string, now time.Time) (time.Time, bool)

CooldownFromRetryAfter parses a Retry-After header value (RFC 7231): either delta-seconds or an HTTP-date. On success, the returned time is strictly after now. Pure: it does not read or mutate credential pool state.

func CooldownFromRetryAfterOrFallback

func CooldownFromRetryAfterOrFallback(value string, now time.Time, fallback time.Duration) time.Time

CooldownFromRetryAfterOrFallback returns CooldownFromRetryAfter when parsing succeeds; otherwise it returns now+fallback (for provider-local conservative cooldowns).

func Secrets

func Secrets(credentials []Credential) []string

Secrets returns the ordered Secret field of each credential. Callers typically pass the result to inventory providers that only need a flat secret list. Returns nil when the input is empty.

Types

type Credential

type Credential struct {
	ID                string
	Secret            string
	RemoteOrgID       string
	RemoteProjectID   string
	RemoteWorkspaceID string
	RemoteAccountID   string
	RemoteRegion      string
}

Credential is one API key attached to a backend instance. ID is a non-secret operator-facing identifier; when empty, New assigns a pool-local opaque id (c0, c1, ...). IDs are never derived from secret material.

type CredentialStatus

type CredentialStatus struct {
	ID                string
	RemoteOrgID       string
	RemoteProjectID   string
	RemoteWorkspaceID string
	RemoteAccountID   string
	RemoteRegion      string
	State             State
	CooldownUntil     time.Time // zero means not in cooldown / n/a for usable
}

CredentialStatus is a secret-free view for tests and diagnostics.

type Pool

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

Pool holds ordered credentials and per-credential usefulness state.

func New

func New(credentials []Credential) (*Pool, error)

New builds a pool from normalized credentials (non-empty secrets).

func NewPoolFromBackendKeys

func NewPoolFromBackendKeys(apiKey string, apiKeys []string) (*Pool, error)

NewPoolFromBackendKeys builds a pool from install-style API key fields.

func NewPoolFromCredentials

func NewPoolFromCredentials(apiKey string, apiKeys []string, credentials []Credential) (*Pool, error)

NewPoolFromCredentials builds a pool from structured credentials when present, otherwise falls back to legacy api_key/api_keys fields.

func (*Pool) Acquire

func (p *Pool) Acquire(now time.Time, exclude map[string]struct{}) (Credential, error)

Acquire returns the first usable credential in registration order: not in exclude, not auth-invalid, and not in an active cooldown at now.

func (*Pool) AcquireByID

func (p *Pool) AcquireByID(now time.Time, id string) (Credential, error)

AcquireByID returns the credential with the given id when it is usable at now (not auth-invalid and not in an active cooldown).

func (*Pool) MarkAuthInvalid

func (p *Pool) MarkAuthInvalid(id string)

MarkAuthInvalid permanently marks the credential unusable for auth reasons.

func (*Pool) MarkRateLimited

func (p *Pool) MarkRateLimited(id string, until time.Time)

MarkRateLimited puts the credential in cooldown until the given instant. If the credential already has a cooldown that ends later than until, the existing deadline is kept (never shortens an in-flight cooldown).

func (*Pool) Snapshot

func (p *Pool) Snapshot(now time.Time) []CredentialStatus

Snapshot returns secret-free status for every credential in order.

type State

type State string

State is usefulness of a credential for diagnostics only.

const (
	StateUsable      State = "usable"
	StateCooldown    State = "cooldown"
	StateAuthInvalid State = "auth_invalid"
)

Jump to

Keyboard shortcuts

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