credential

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 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
  • 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) MarkQuotaExceeded

func (s *Service) MarkQuotaExceeded(id string, resetAt time.Time) error

MarkQuotaExceeded marks a credential as quota-exceeded until resetAt.

func (*Service) Next

func (s *Service) Next(providerID string) (*models.Credential, error)

Next returns the best available (non-expired) Credential for a provider.

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

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

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

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