Documentation
¶
Index ¶
- Constants
- Variables
- func BackendKeySecrets(apiKey string, apiKeys []string) ([]string, error)
- func CooldownFromRetryAfter(value string, now time.Time) (time.Time, bool)
- func CooldownFromRetryAfterOrFallback(value string, now time.Time, fallback time.Duration) time.Time
- func Secrets(credentials []Credential) []string
- type Credential
- type CredentialStatus
- type Pool
- func (p *Pool) Acquire(now time.Time, exclude map[string]struct{}) (Credential, error)
- func (p *Pool) AcquireByID(now time.Time, id string) (Credential, error)
- func (p *Pool) MarkAuthInvalid(id string)
- func (p *Pool) MarkRateLimited(id string, until time.Time)
- func (p *Pool) Snapshot(now time.Time) []CredentialStatus
- type State
Constants ¶
const DefaultRateLimitFallback = 60 * time.Second
DefaultRateLimitFallback is used when Retry-After is missing or unparseable.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
MarkAuthInvalid permanently marks the credential unusable for auth reasons.
func (*Pool) MarkRateLimited ¶
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).