credential

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

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 GormService added in v0.4.0

type GormService struct {
	// contains filtered or unexported fields
}

GormService manages credentials on the SQLite handles with explicit converters between wire types and credential rows. Credential rows live in the durable database; cooldown parks and health verdicts live in the cache file and reference credentials softly. Traditional GORM use: none; every statement runs through gorm.G with typed clauses.

func NewGorm added in v0.4.0

func NewGorm(database *db.Database, providerService *provider.GormService) *GormService

NewGorm constructs a GORM-backed credential service on the SQLite handle. providerService serves backend validation through provider.Resolve; it must read non-nil. Construction performs no I/O.

func (*GormService) Add added in v0.4.0

func (s *GormService) Add(ctx context.Context, options AddOptions) (*models.Credential, error)

Add validates and persists a new credential for the given provider. Validation runs outside the transaction; the insert runs in one transaction on the transaction handle only. The provider row must exist: a dangling provider fails through the foreign key as invalid input.

func (*GormService) All added in v0.4.0

func (s *GormService) All(ctx context.Context, 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 (*GormService) Delete added in v0.4.0

func (s *GormService) Delete(ctx context.Context, identifier string) error

Delete removes a credential by identifier in one conditioned delete. Cached park and health rows reference the credential softly across files, so the delete clears them explicitly after the durable delete succeeds. A zero-row delete reports the not-found sentinel through the WithResult tracker.

func (*GormService) DeleteByProvider added in v0.4.0

func (s *GormService) DeleteByProvider(ctx context.Context, providerID string) (int, error)

DeleteByProvider removes every credential of one provider in one conditioned delete. Cached park and health rows clear explicitly after the durable delete succeeds. Returns the removed count.

func (*GormService) DisableByPlugin added in v0.4.0

func (s *GormService) DisableByPlugin(ctx context.Context, identifier, reason string) error

DisableByPlugin disables a credential on a plugin dead-key verdict. First wins: an already-disabled credential keeps its original cause, so plugin writes never override admin or healthcheck disables. One transaction holds the read-modify-write on the transaction handle only.

func (*GormService) DisableUnhealthy added in v0.4.0

func (s *GormService) DisableUnhealthy(ctx context.Context, identifier, reason string) error

DisableUnhealthy disables a credential on an explicit unhealthy health-check verdict. First wins: an already-disabled credential keeps its original cause. One transaction holds the read-modify-write on the transaction handle only.

func (*GormService) EnableByPlugin added in v0.4.0

func (s *GormService) EnableByPlugin(ctx context.Context, identifier string) error

EnableByPlugin clears a plugin-caused disable when the key proves healthy again. Disables owned by admin or healthcheck verdicts stay untouched. One transaction holds the read-modify-write on the transaction handle only.

func (*GormService) Get added in v0.4.0

func (s *GormService) Get(ctx context.Context, identifier string) (*models.Credential, error)

Get returns a single credential by identifier. A miss reports the not-found sentinel with credential context.

func (*GormService) ListAll added in v0.4.0

func (s *GormService) ListAll(ctx context.Context) ([]*models.Credential, error)

ListAll returns every credential across all providers ordered by identifier.

func (*GormService) ListByProvider added in v0.4.0

func (s *GormService) ListByProvider(ctx context.Context, providerID string) ([]*models.Credential, error)

ListByProvider returns all credentials for a provider ordered by identifier.

func (*GormService) ListUsable added in v0.4.0

func (s *GormService) ListUsable(ctx context.Context, providerID string) ([]*models.Credential, error)

ListUsable returns routable credentials for a provider: non-expired and not disabled, ordered by identifier. Empty pools yield an empty slice, never an error. Selection among them belongs to the plugin.

func (*GormService) Park added in v0.4.0

func (s *GormService) Park(ctx context.Context, identifier string, ttl time.Duration, reason string) error

Park benches a credential in the shared cooldown store until the ttl lapses. Unknown identifiers fail loudly; ttl must read positive and bounded. The existence check reads the durable database; the park upsert runs in one transaction on the cache handle. The two files share no transaction, so the upsert targets the cache handle only.

func (*GormService) Parked added in v0.4.0

func (s *GormService) Parked(ctx context.Context, identifier string) (*models.ParkEntry, error)

Parked returns the live park entry for a credential, or nil when absent or lapsed. Lapsed rows delete on read through the credential_id key. One transaction holds the read and the conditional delete on the cache handle only.

func (*GormService) PurgeExpiredParks added in v0.4.0

func (s *GormService) PurgeExpiredParks(ctx context.Context) (int64, error)

PurgeExpiredParks removes every lapsed cooldown park through the Until index in one conditioned delete on the cache handle. Returns the removed count.

func (*GormService) SetLogger added in v0.4.0

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

SetLogger wires structured logging.

func (*GormService) Unpark added in v0.4.0

func (s *GormService) Unpark(ctx context.Context, identifier string) error

Unpark clears a cooldown park so the credential serves immediately. Missing parks succeed: unparking is idempotent. One transaction holds the conditioned delete on the cache handle only.

func (*GormService) Update added in v0.4.0

func (s *GormService) Update(ctx context.Context, identifier string, data map[string]any, expiresAt *time.Time) error

Update replaces a credential mutable fields (data, expiry). One transaction holds the read-modify-write on the transaction handle only.

func (*GormService) UpdateDetails added in v0.4.0

func (s *GormService) UpdateDetails(ctx context.Context, identifier 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). Validation runs outside the transaction; one transaction holds the read-modify-write on the transaction handle only.

Jump to

Keyboard shortcuts

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