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 ¶
- Variables
- type Input
- type List
- type PolicyStore
- type ProductStore
- type Scenario
- func (s Scenario) Create(ctx context.Context, account domain.Account, in Input) (domain.Key, error)
- func (s Scenario) Destroy(ctx context.Context, account domain.Account, id uuid.UUID) error
- func (s Scenario) Index(ctx context.Context, account domain.Account, ...) (List, error)
- func (s Scenario) Policy(ctx context.Context, account domain.Account, id uuid.UUID) (domain.Key, domain.Policy, error)
- func (s Scenario) Product(ctx context.Context, account domain.Account, id uuid.UUID) (domain.Key, domain.Product, error)
- func (s Scenario) Resolve(ctx context.Context, account domain.Account, id uuid.UUID) (domain.Key, error)
- func (s Scenario) Show(ctx context.Context, account domain.Account, id uuid.UUID) (domain.Key, error)
- func (s Scenario) Update(ctx context.Context, account domain.Account, id uuid.UUID, in Input) (domain.Key, error)
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = domain.ErrNotFound // one sentinel across the scenario ports
ErrNotFound is the storage port's not-found sentinel.
var ErrPoolEmpty = errors.New("keys: pool empty")
ErrPoolEmpty: the pool pop found nothing to take.
var ErrTaken = errors.New("keys: key taken")
ErrTaken is the unique-index violation of (account, key).
Functions ¶
This section is empty.
Types ¶
type Input ¶
Input is the request body of create and update (decoded and shape-validated by the handler).
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) 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).
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.