credential

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 10 Imported by: 0

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

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

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: non-expired and not disabled, sorted by manual order, then computed priority, then LRU.

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

func (s *Service) ManualRefresh(credentialID string) error

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

func (s *Service) Reorder(providerID string, ids []string) error

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) 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) SystemDisable added in v0.2.0

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

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.

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

func (*Service) UpdateUsage

func (s *Service) UpdateUsage(id string, success bool) error

UpdateUsage updates credential usage statistics after a request.

Jump to

Keyboard shortcuts

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