Documentation
¶
Overview ¶
Package credential implements the Credential Pool Service.
Responsibilities:
- Storage and retrieval of provider-specific credentials
- Admin mutation (label, enable/disable, data, delete)
- Persisting job-refreshed credential data
Selection, rotation, ordering and usage accounting belong to plugins: the service keeps no pool order, no LRU state and no usage counters.
Index ¶
- type AddOptions
- type Service
- func (s *Service) Add(opts AddOptions) (*models.Credential, error)
- func (s *Service) All(providerID string) ([]*models.Credential, error)
- func (s *Service) Delete(id string) error
- func (s *Service) DeleteByProvider(providerID string) (int, error)
- func (s *Service) DisableByPlugin(id, reason string) error
- func (s *Service) DisableUnhealthy(id, reason string) error
- func (s *Service) EnableByPlugin(id string) error
- func (s *Service) Get(id string) (*models.Credential, error)
- func (s *Service) ListAll() ([]*models.Credential, error)
- func (s *Service) ListByProvider(providerID string) ([]*models.Credential, error)
- func (s *Service) ListUsable(providerID string) ([]*models.Credential, error)
- func (s *Service) Park(id string, ttl time.Duration, reason string) error
- func (s *Service) Parked(id string) (*models.ParkEntry, error)
- func (s *Service) SetLogger(l *slog.Logger)
- func (s *Service) SetOnChanged(fn func(providerID string))
- func (s *Service) Unpark(id string) error
- func (s *Service) Update(id string, data map[string]any, expiresAt *time.Time) error
- func (s *Service) UpdateDetails(id string, label *string, disabled *bool, data map[string]any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddOptions ¶
AddOptions holds parameters for adding a new credential to a provider's pool.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages Credential records.
func (*Service) Add ¶
func (s *Service) Add(opts AddOptions) (*models.Credential, error)
Add validates and persists a new Credential for the given provider. Validation dispatches to the Go adapter or the Lua validate_credentials handler for the provider's type key.
func (*Service) All ¶
func (s *Service) All(providerID string) ([]*models.Credential, error)
All returns routable credentials for a provider, denying empty pools: the router gate maps absence to NoCredential before plugins run.
func (*Service) DeleteByProvider ¶
DeleteByProvider removes every Credential of one provider. Returns the removed count.
func (*Service) DisableByPlugin ¶ added in v0.3.8
DisableByPlugin disables a credential on a plugin's dead-key verdict. First wins: an already-disabled credential keeps its original cause, so plugin writes never override admin or healthcheck disables. Manual admin re-enable clears the flag.
func (*Service) DisableUnhealthy ¶ added in v0.3.8
DisableUnhealthy disables a credential on an explicit unhealthy health-check verdict. First wins: an already-disabled credential keeps its original cause. Manual admin re-enable clears the flag.
func (*Service) EnableByPlugin ¶ added in v0.3.8
EnableByPlugin clears a plugin-caused disable when the key proves healthy again. Disables owned by admin or healthcheck verdicts are left untouched: only the actor that benched the key lifts it, besides the manual admin toggle which clears every cause.
func (*Service) Get ¶
func (s *Service) Get(id string) (*models.Credential, error)
Get returns a single Credential by ID.
func (*Service) ListAll ¶
func (s *Service) ListAll() ([]*models.Credential, error)
ListAll returns every Credential across all providers.
func (*Service) ListByProvider ¶
func (s *Service) ListByProvider(providerID string) ([]*models.Credential, error)
ListByProvider returns all Credentials for a given provider.
func (*Service) ListUsable ¶ added in v0.3.8
func (s *Service) ListUsable(providerID string) ([]*models.Credential, error)
ListUsable returns routable credentials for a provider: non-expired and not disabled, in stored order. Empty pools yield an empty slice, never an error: plugin discovery and dashboard reads handle absence themselves. Selection among them belongs to the plugin.
func (*Service) Park ¶ added in v0.3.8
Park benches a credential in the shared cooldown store until ttl lapses: plugin rotation skips it, the dashboard keeps showing it enabled with an unpark action. Unknown IDs fail loudly; TTL must be positive and bounded.
func (*Service) Parked ¶ added in v0.3.8
Parked returns the live park entry for a credential, or nil when absent or lapsed. Lapsed rows delete on read.
func (*Service) SetOnChanged ¶
SetOnChanged registers a callback fired after credential add/delete for a provider.
func (*Service) Unpark ¶ added in v0.3.8
Unpark clears a cooldown park so the credential serves immediately. Missing parks succeed: unparking is idempotent.