Documentation
¶
Overview ¶
Package credential implements the Credential Pool Service.
Responsibilities:
- Storage and retrieval of provider-specific credentials
- LRU-based credential selection with priority ordering
- Usage tracking and quota management
- Updating credentials after refresh by the Maintenance service
Index ¶
- func SortPool(creds []*models.Credential)
- 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) 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) ManualRefresh(credentialID string) error
- func (s *Service) Reorder(providerID string, ids []string) error
- func (s *Service) SetLogger(l *slog.Logger)
- func (s *Service) SetOnChanged(fn func(providerID string))
- func (s *Service) SystemDisable(id, reason 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
- func (s *Service) UpdateUsage(id string, success bool) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SortPool ¶
func SortPool(creds []*models.Credential)
SortPool orders a credential pool: manually ordered first (Order asc), then by computed priority, then least recently used.
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: non-expired and not disabled, sorted by manual order, then computed priority, then LRU.
func (*Service) DeleteByProvider ¶
DeleteByProvider removes every Credential of one provider. Returns the removed count.
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) ManualRefresh ¶ added in v0.2.0
ManualRefresh triggers a credential refresh for the given credential ID, typically from a user action in the dashboard. It resolves the provider type and dispatches to the appropriate refresh handler (Lua or Go adapter). If the provider does not support refresh, it returns an error.
func (*Service) Reorder ¶
Reorder sets the manual pool order for a provider's credentials. ids must cover every credential of the provider; Order becomes 1-based.
func (*Service) SetOnChanged ¶
SetOnChanged registers a callback fired after credential add/delete for a provider.
func (*Service) SystemDisable ¶ added in v0.2.0
SystemDisable disables a credential on auth/payment_required outcomes. First wins: already-disabled credentials keep their original cause, so a late duplicate error cannot rewrite the admin-visible reason. Manual admin re-enable clears the flag; the next failure disables again with a fresh cause.