credential

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddOptions

type AddOptions struct {
	ProviderID string
	Label      string
	Data       map[string]any
}

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 New

func New(database *db.DB, providerSvc *provider.Service) *Service

New constructs a new credential Service.

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) Delete

func (s *Service) Delete(id string) error

Delete removes a Credential by ID.

func (*Service) DeleteByProvider

func (s *Service) DeleteByProvider(providerID string) (int, error)

DeleteByProvider removes every Credential of one provider. Returns the removed count.

func (*Service) DisableByPlugin added in v0.3.8

func (s *Service) DisableByPlugin(id, reason string) error

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

func (s *Service) DisableUnhealthy(id, reason string) error

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

func (s *Service) EnableByPlugin(id string) error

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

func (s *Service) Park(id string, ttl time.Duration, reason string) error

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

func (s *Service) Parked(id string) (*models.ParkEntry, error)

Parked returns the live park entry for a credential, or nil when absent or lapsed. Lapsed rows delete on read.

func (*Service) SetLogger added in v0.2.0

func (s *Service) SetLogger(l *slog.Logger)

SetLogger wires structured logging.

func (*Service) SetOnChanged

func (s *Service) SetOnChanged(fn func(providerID string))

SetOnChanged registers a callback fired after credential add/delete for a provider.

func (*Service) Unpark added in v0.3.8

func (s *Service) Unpark(id string) error

Unpark clears a cooldown park so the credential serves immediately. Missing parks succeed: unparking is idempotent.

func (*Service) Update

func (s *Service) Update(id string, data map[string]any, expiresAt *time.Time) error

Update replaces a Credential's mutable fields (data, expiry).

func (*Service) UpdateDetails

func (s *Service) UpdateDetails(id string, label *string, disabled *bool, data map[string]any) error

UpdateDetails edits the admin-facing fields: label, enable/disable, and optionally the credential data (revalidated against the provider backend when replaced).

Jump to

Keyboard shortcuts

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