keys

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package keys is the key scenario: the members of pooled policies' key pools (create requires a pooled policy; the pool itself lives under /policies/{id}/pool).

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = domain.ErrNotFound // one sentinel across the scenario ports

ErrNotFound is the storage port's not-found sentinel.

View Source
var ErrPoolEmpty = errors.New("keys: pool empty")

ErrPoolEmpty: the pool pop found nothing to take.

View Source
var ErrTaken = errors.New("keys: key taken")

ErrTaken is the unique-index violation of (account, key).

Functions

This section is empty.

Types

type Input

type Input struct {
	Key      string
	KeySet   bool
	PolicyID uuid.UUID
}

Input is the request body of create and update (decoded and shape-validated by the handler).

type List

type List struct {
	Items []domain.Key
	Count int
	Next  uuid.NullUUID
}

List is one index page.

type PolicyStore

type PolicyStore interface {
	// PolicyByID loads a policy (the create target and the policy
	// relationship); policies.ErrNotFound.
	PolicyByID(ctx context.Context, accountID, id uuid.UUID) (domain.Policy, error)
}

PolicyStore is the policy seam (the policies repository).

type ProductStore

type ProductStore interface {
	// ProductByID loads a product (the key relationship); products.ErrNotFound.
	ProductByID(ctx context.Context, accountID, id uuid.UUID) (domain.Product, error)
}

ProductStore is the product seam (the products repository).

type Scenario

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

Scenario runs the key reads and writes.

func New

func New(
	store Store, policyStore PolicyStore, productStore ProductStore,
	publisher events.Publisher, clock func() time.Time,
) Scenario

New builds the scenario over the keys, policies and products repositories.

func (Scenario) Create

func (s Scenario) Create(ctx context.Context, account domain.Account, in Input) (domain.Key, error)

Create writes a new pooled key.

func (Scenario) Destroy

func (s Scenario) Destroy(ctx context.Context, account domain.Account, id uuid.UUID) error

Destroy removes the key from the pool.

func (Scenario) Index

func (s Scenario) Index(
	ctx context.Context, account domain.Account, filterPolicyID, filterProductID *uuid.UUID, params paging.Params,
) (List, error)

Index answers the keys page (the product bearer's post-check narrows it to its own).

func (Scenario) Policy

func (s Scenario) Policy(
	ctx context.Context, account domain.Account, id uuid.UUID,
) (domain.Key, domain.Policy, error)

Policy answers the key's policy.

func (Scenario) Product

func (s Scenario) Product(
	ctx context.Context, account domain.Account, id uuid.UUID,
) (domain.Key, domain.Product, error)

Product answers the key's product (through its policy).

func (Scenario) Resolve

func (s Scenario) Resolve(ctx context.Context, account domain.Account, id uuid.UUID) (domain.Key, error)

Show answers one key by id. Resolve loads the key within scope (the before_action's scoped find; a miss is the 404 that precedes the typed-params decode and the authorization).

func (Scenario) Show

func (s Scenario) Show(ctx context.Context, account domain.Account, id uuid.UUID) (domain.Key, error)

func (Scenario) Update

func (s Scenario) Update(ctx context.Context, account domain.Account, id uuid.UUID, in Input) (domain.Key, error)

Update changes the key value (the policy is immutable).

type Store

type Store interface {
	// Do runs fn in one transaction; the writes and the webhook
	// events of one action commit together.
	Do(ctx context.Context, fn func(ctx context.Context) error) error
	// KeyByID loads a key (with its policy's product); ErrNotFound.
	KeyByID(ctx context.Context, accountID, id uuid.UUID) (domain.Key, error)
	// InsertKey writes a new row; ErrTaken on a collision.
	InsertKey(ctx context.Context, key domain.Key) error
	// UpdateKey changes the key value.
	UpdateKey(ctx context.Context, accountID, id uuid.UUID, key string) error
	// DeleteKey destroys the row; false when gone.
	DeleteKey(ctx context.Context, accountID, id uuid.UUID) (bool, error)
	// ListKeys pages the account's keys with the policy/product filters.
	ListKeys(
		ctx context.Context, accountID uuid.UUID,
		filterPolicyID, filterProductID *uuid.UUID, page paging.Page,
	) ([]domain.Key, error)
	// CountKeys counts the same scope.
	CountKeys(
		ctx context.Context, accountID uuid.UUID, filterPolicyID, filterProductID *uuid.UUID,
	) (int, error)
	// KeyIsLicenseID answers a collision with a license's identifier.
	KeyIsLicenseID(ctx context.Context, accountID uuid.UUID, key string) (bool, error)
	// KeyIsLicenseKey answers a collision with a license's key.
	KeyIsLicenseKey(ctx context.Context, accountID uuid.UUID, key string) (bool, error)
}

Store is the scenario's consumer-side storage port.

Jump to

Keyboard shortcuts

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