postgres

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: 38 Imported by: 0

Documentation

Overview

The full licenses repository: rows with their policy and owner context, the filtered index, the relationship rows and the actions' writes (internal/app/licenses).

Package postgres is the service's PostgreSQL: the SDK's postgres provider with the service's schema (lic) and migrations, plus the typed queries sqld generated and the repositories that adapt them to the app's ports.

Index

Constants

View Source
const Schema = "lic"

Schema every table lives in.

Variables

This section is empty.

Functions

func New

func New(cfg postgres.Config) sdkpg.Provider[*Store]

New is the provider: the postgres driver with the schema and the migrations.

Types

type AccountsRepo

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

AccountsRepo adapts the generated account queries to the accounts scenario's storage port.

func (AccountsRepo) Account

func (r AccountsRepo) Account(ctx context.Context, id uuid.UUID) (domain.Account, error)

Account loads the account by id.

func (AccountsRepo) InsertAccount

func (r AccountsRepo) InsertAccount(ctx context.Context, account domain.Account) error

InsertAccount writes a new account row.

type EntitlementsRepo

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

EntitlementsRepo adapts the entitlement and policy_entitlements queries to the entitlements and policies scenarios' storage ports.

func (EntitlementsRepo) CountEntitlements

func (r EntitlementsRepo) CountEntitlements(ctx context.Context, accountID uuid.UUID, ids []uuid.UUID) (int, error)

CountEntitlements counts the account's entitlements.

func (EntitlementsRepo) CountEntitlementsByIDs

func (r EntitlementsRepo) CountEntitlementsByIDs(
	ctx context.Context, accountID uuid.UUID, ids []uuid.UUID,
) (int, error)

CountEntitlementsByIDs counts only the authorized entitlement IDs.

func (EntitlementsRepo) DeleteEntitlement

func (r EntitlementsRepo) DeleteEntitlement(ctx context.Context, accountID, id uuid.UUID) (bool, error)

DeleteEntitlement destroys the entitlement; false when gone.

func (EntitlementsRepo) DeletePolicyEntitlements

func (r EntitlementsRepo) DeletePolicyEntitlements(
	ctx context.Context, accountID, policyID uuid.UUID, entitlementIDs []uuid.UUID,
) ([]uuid.UUID, error)

DeletePolicyEntitlements removes the join rows of one detach call; the answer is the entitlement ids that were actually attached.

func (EntitlementsRepo) Do

func (r EntitlementsRepo) Do(ctx context.Context, fn func(ctx context.Context) error) error

Do runs fn in one transaction (nested calls join the open one); actions deferred with commit.After run once it commits.

func (EntitlementsRepo) EntitlementByCode

func (r EntitlementsRepo) EntitlementByCode(ctx context.Context, accountID uuid.UUID, code string) (domain.Entitlement, error)

EntitlementByCode loads an entitlement by its (case-insensitive) code.

func (EntitlementsRepo) EntitlementByID

func (r EntitlementsRepo) EntitlementByID(ctx context.Context, accountID, id uuid.UUID) (domain.Entitlement, error)

EntitlementByID loads an entitlement by id.

func (EntitlementsRepo) InsertEntitlement

func (r EntitlementsRepo) InsertEntitlement(ctx context.Context, e domain.Entitlement) error

InsertEntitlement writes a new entitlement row.

func (EntitlementsRepo) InsertPolicyEntitlements

func (r EntitlementsRepo) InsertPolicyEntitlements(
	ctx context.Context, accountID, policyID, joinID uuid.UUID, entitlementIDs []uuid.UUID,
) error

InsertPolicyEntitlements writes the join rows of one attach call.

func (EntitlementsRepo) LicenseEntitlementIDs

func (r EntitlementsRepo) LicenseEntitlementIDs(ctx context.Context, accountID, licenseID uuid.UUID) ([]uuid.UUID, error)

LicenseEntitlementIDs answers the entitlements of one license.

func (EntitlementsRepo) ListEntitlements

func (r EntitlementsRepo) ListEntitlements(ctx context.Context, accountID uuid.UUID, ids []uuid.UUID, page Page) ([]domain.Entitlement, error)

ListEntitlements pages the account-wide entitlement scope. ids narrows the scope to a search's matches; nil keeps the whole account.

func (EntitlementsRepo) ListEntitlementsByIDs

func (r EntitlementsRepo) ListEntitlementsByIDs(
	ctx context.Context, accountID uuid.UUID, ids []uuid.UUID, page Page,
) ([]domain.Entitlement, error)

ListEntitlementsByIDs pages only the authorized entitlement IDs; a nil scope is empty, never the whole account.

func (EntitlementsRepo) ListPolicyEntitlements

func (r EntitlementsRepo) ListPolicyEntitlements(
	ctx context.Context, accountID, policyID uuid.UUID,
) ([]domain.PolicyEntitlement, error)

ListPolicyEntitlements answers a policy's join rows (attach order).

func (EntitlementsRepo) PolicyEntitlement

func (r EntitlementsRepo) PolicyEntitlement(
	ctx context.Context, accountID, policyID, entitlementID uuid.UUID,
) (domain.PolicyEntitlement, error)

PolicyEntitlement loads one join row.

func (EntitlementsRepo) UpdateEntitlement

func (r EntitlementsRepo) UpdateEntitlement(ctx context.Context, e domain.Entitlement) error

UpdateEntitlement overwrites the mutable columns.

func (EntitlementsRepo) UserEntitlementIDs

func (r EntitlementsRepo) UserEntitlementIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

UserEntitlementIDs answers the entitlements of the user's licenses.

type GroupsRepo

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

GroupsRepo adapts the generated group queries to the groups scenario's storage port.

func (GroupsRepo) CountGroups

func (r GroupsRepo) CountGroups(ctx context.Context, accountID uuid.UUID, memberUser uuid.NullUUID, ids []uuid.UUID) (int, error)

CountGroups answers the member-scoped total.

func (GroupsRepo) DeleteGroup

func (r GroupsRepo) DeleteGroup(ctx context.Context, accountID, id uuid.UUID) error

DeleteGroup removes the group.

func (GroupsRepo) DeleteGroupOwnersByUsers

func (r GroupsRepo) DeleteGroupOwnersByUsers(
	ctx context.Context, accountID, groupID uuid.UUID, userIDs []uuid.UUID,
) (int64, error)

DeleteGroupOwnersByUsers detaches the given users.

func (GroupsRepo) GetGroupOwner

func (r GroupsRepo) GetGroupOwner(
	ctx context.Context, accountID, groupID, ownerID uuid.UUID,
) (domain.GroupOwner, error)

GetGroupOwner loads a group-owner row.

func (GroupsRepo) GetGroupOwnerByUser

func (r GroupsRepo) GetGroupOwnerByUser(
	ctx context.Context, accountID, groupID, userID uuid.UUID,
) (domain.GroupOwner, error)

GetGroupOwnerByUser loads the group-owner row of a user.

func (GroupsRepo) GroupByID

func (r GroupsRepo) GroupByID(ctx context.Context, accountID, id uuid.UUID) (domain.Group, error)

GroupByID loads a group.

func (GroupsRepo) InsertGroup

func (r GroupsRepo) InsertGroup(ctx context.Context, group domain.Group) error

InsertGroup writes a new group row.

func (GroupsRepo) InsertGroupOwner

func (r GroupsRepo) InsertGroupOwner(ctx context.Context, owner domain.GroupOwner) error

InsertGroupOwner attaches a user as owner.

func (GroupsRepo) ListGroupLicenseIDs

func (r GroupsRepo) ListGroupLicenseIDs(
	ctx context.Context, accountID, groupID uuid.UUID, limit int,
) ([]uuid.UUID, error)

ListGroupLicenseIDs answers the group's license ids.

func (GroupsRepo) ListGroupMachineIDs

func (r GroupsRepo) ListGroupMachineIDs(
	ctx context.Context, accountID, groupID uuid.UUID, limit int,
) ([]uuid.UUID, error)

ListGroupMachineIDs answers the group's machine ids.

func (GroupsRepo) ListGroupOwners

func (r GroupsRepo) ListGroupOwners(
	ctx context.Context, accountID, groupID uuid.UUID, limit int,
) ([]domain.GroupOwner, error)

ListGroupOwners answers the group's owners.

func (GroupsRepo) ListGroupUsers

func (r GroupsRepo) ListGroupUsers(
	ctx context.Context, accountID, groupID uuid.UUID, limit int,
) ([]domain.User, error)

ListGroupUsers answers the group's member users.

func (GroupsRepo) ListGroups

func (r GroupsRepo) ListGroups(
	ctx context.Context, accountID uuid.UUID, memberUser uuid.NullUUID, ids []uuid.UUID, p paging.Params,
) ([]domain.Group, error)

ListGroups answers the member-scoped page.

func (GroupsRepo) OwnedGroupIDsOfUser

func (r GroupsRepo) OwnedGroupIDsOfUser(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

OwnedGroupIDsOfUser answers ownership without membership-only groups.

func (GroupsRepo) UpdateGroup

func (r GroupsRepo) UpdateGroup(ctx context.Context, group domain.Group) error

UpdateGroup writes every mutable column.

type JobsRepo

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

JobsRepo adapts the periodic-job queries.

func (JobsRepo) PruneExpiredTokens

func (r JobsRepo) PruneExpiredTokens(ctx context.Context, cutoff time.Time) (int64, error)

PruneExpiredTokens deletes tokens whose expiry passed the cutoff.

func (JobsRepo) PruneWebhookEvents

func (r JobsRepo) PruneWebhookEvents(ctx context.Context, cutoff time.Time) (int64, error)

PruneWebhookEvents deletes events older than the cutoff; 0 disables.

func (JobsRepo) TryAdvisoryLock

func (r JobsRepo) TryAdvisoryLock(ctx context.Context) (bool, error)

TryAdvisoryLock answers whether this transaction won the jobs lock (one replica runs a tick).

type KeysRepo

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

KeysRepo adapts the key queries to the keys and policies scenarios' storage ports.

func (KeysRepo) CountKeys

func (r KeysRepo) CountKeys(
	ctx context.Context, accountID uuid.UUID, filterPolicyID, filterProductID *uuid.UUID,
) (int, error)

CountKeys counts the account's keys.

func (KeysRepo) CountPolicyPool

func (r KeysRepo) CountPolicyPool(ctx context.Context, accountID, policyID uuid.UUID) (int, error)

CountPolicyPool counts one policy's pool.

func (KeysRepo) DeleteKey

func (r KeysRepo) DeleteKey(ctx context.Context, accountID, id uuid.UUID) (bool, error)

DeleteKey destroys the key; false when gone.

func (KeysRepo) Do

func (r KeysRepo) Do(ctx context.Context, fn func(ctx context.Context) error) error

Do runs fn in one transaction (nested calls join the open one); actions deferred with commit.After run once it commits.

func (KeysRepo) InsertKey

func (r KeysRepo) InsertKey(ctx context.Context, k domain.Key) error

InsertKey writes a new key row.

func (KeysRepo) KeyByID

func (r KeysRepo) KeyByID(ctx context.Context, accountID, id uuid.UUID) (domain.Key, error)

KeyByID loads a key (with its policy's product) by id.

func (KeysRepo) KeyIsLicenseID

func (r KeysRepo) KeyIsLicenseID(ctx context.Context, accountID uuid.UUID, key string) (bool, error)

KeyIsLicenseID answers a collision with a license's identifier.

func (KeysRepo) KeyIsLicenseKey

func (r KeysRepo) KeyIsLicenseKey(ctx context.Context, accountID uuid.UUID, key string) (bool, error)

KeyIsLicenseKey answers a collision with a license's key.

func (KeysRepo) ListKeys

func (r KeysRepo) ListKeys(
	ctx context.Context, accountID uuid.UUID, filterPolicyID, filterProductID *uuid.UUID, page Page,
) ([]domain.Key, error)

ListKeys pages the account's keys (the product bearer's post-check rejects pages holding anyone else's keys).

func (KeysRepo) ListPolicyPool

func (r KeysRepo) ListPolicyPool(
	ctx context.Context, accountID, policyID uuid.UUID, page Page,
) ([]domain.Key, error)

ListPolicyPool pages one policy's pool.

func (KeysRepo) PopPolicyKey

func (r KeysRepo) PopPolicyKey(ctx context.Context, accountID, policyID uuid.UUID) (domain.Key, error)

PopPolicyKey destroys the newest pooled key and answers it.

func (KeysRepo) UpdateKey

func (r KeysRepo) UpdateKey(ctx context.Context, accountID, id uuid.UUID, key string) error

UpdateKey changes the key value.

type LicensesRepo

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

LicensesRepo adapts the license-auth lookups to the authn scenario's storage port.

func (LicensesRepo) AuthByID

func (r LicensesRepo) AuthByID(ctx context.Context, accountID, id uuid.UUID) (domain.LicenseAuth, error)

AuthByID loads the license-auth slice by id.

func (LicensesRepo) AuthByKey

func (r LicensesRepo) AuthByKey(ctx context.Context, accountID uuid.UUID, key string) (domain.LicenseAuth, error)

AuthByKey loads the license-auth slice by key.

func (LicensesRepo) CountLicenseEntitlementCodes

func (r LicensesRepo) CountLicenseEntitlementCodes(
	ctx context.Context, accountID, policyID, licenseID uuid.UUID, codes []string,
) (int, error)

CountLicenseEntitlementCodes answers how many of the codes the license is entitled to.

func (LicensesRepo) CountLicenseEntitlementsOf

func (r LicensesRepo) CountLicenseEntitlementsOf(
	ctx context.Context, accountID, licenseID uuid.UUID, entitlementIDs []uuid.UUID,
) (int, error)

CountLicenseEntitlementsOf answers how many of the entitlements are attached to the license.

func (LicensesRepo) CountLicenseEntitlementsOfUnion

func (r LicensesRepo) CountLicenseEntitlementsOfUnion(
	ctx context.Context, accountID, policyID, licenseID uuid.UUID,
) (int, error)

CountLicenseEntitlementsOfUnion counts the union.

func (LicensesRepo) CountLicenseProcesses

func (r LicensesRepo) CountLicenseProcesses(
	ctx context.Context, accountID, licenseID uuid.UUID, owner *uuid.UUID,
) (int, error)

CountLicenseProcesses answers the license's process count (the owner-scoped per-user lease when owner is set).

func (LicensesRepo) CountLicenseUsersOf

func (r LicensesRepo) CountLicenseUsersOf(
	ctx context.Context, accountID, licenseID uuid.UUID, userIDs []uuid.UUID,
) (int, error)

CountLicenseUsersOf answers how many of the users are attached.

func (LicensesRepo) CountLicenses

func (r LicensesRepo) CountLicenses(
	ctx context.Context, accountID uuid.UUID, f licenses.Filter, scopeKind string,
	scopeID uuid.UUID, now time.Time,
) (int, error)

CountLicenses counts the filtered scope.

func (LicensesRepo) CountLicensesOfGroup

func (r LicensesRepo) CountLicensesOfGroup(ctx context.Context, accountID, groupID uuid.UUID) (int, error)

CountLicensesOfGroup answers the group's license count.

func (LicensesRepo) CountMachineComponentsOf

func (r LicensesRepo) CountMachineComponentsOf(
	ctx context.Context, machineID uuid.UUID, fingerprints []string,
) (int, error)

CountMachineComponentsOf answers how many of the component fingerprints the machine holds.

func (LicensesRepo) CountMachineProcesses

func (r LicensesRepo) CountMachineProcesses(ctx context.Context, accountID, machineID uuid.UUID) (int, error)

CountMachineProcesses answers the machine's process count.

func (LicensesRepo) CountPolicyEntitlementsOf

func (r LicensesRepo) CountPolicyEntitlementsOf(
	ctx context.Context, accountID, policyID uuid.UUID, entitlementIDs []uuid.UUID,
) (int, error)

CountPolicyEntitlementsOf answers how many of the entitlements the policy already attaches.

func (LicensesRepo) DeleteLicense

func (r LicensesRepo) DeleteLicense(ctx context.Context, accountID, id uuid.UUID) error

DeleteLicense destroys the license and its tokens.

func (LicensesRepo) DeleteLicenseEntitlements

func (r LicensesRepo) DeleteLicenseEntitlements(
	ctx context.Context, accountID, licenseID uuid.UUID, entitlementIDs []uuid.UUID,
) (int, error)

DeleteLicenseEntitlements detaches entitlements, answering how many.

func (LicensesRepo) DeleteLicenseUsers

func (r LicensesRepo) DeleteLicenseUsers(
	ctx context.Context, accountID, licenseID uuid.UUID, userIDs []uuid.UUID,
) (int, error)

DeleteLicenseUsers detaches licensees, answering how many went.

func (LicensesRepo) InsertLicense

func (r LicensesRepo) InsertLicense(ctx context.Context, l domain.License) error

InsertLicense writes the new row.

func (LicensesRepo) InsertLicenseEntitlements

func (r LicensesRepo) InsertLicenseEntitlements(
	ctx context.Context, joinID, accountID, licenseID uuid.UUID, entitlementIDs []uuid.UUID,
) error

InsertLicenseEntitlements attaches entitlements.

func (LicensesRepo) InsertLicenseUsers

func (r LicensesRepo) InsertLicenseUsers(
	ctx context.Context, joinID, accountID, licenseID uuid.UUID, userIDs []uuid.UUID,
) error

InsertLicenseUsers attaches licensees.

func (LicensesRepo) LicenseByID

func (r LicensesRepo) LicenseByID(ctx context.Context, accountID, id uuid.UUID) (domain.License, error)

LicenseByID loads the license (with policy and owner context) by id.

func (LicensesRepo) LicenseByKey

func (r LicensesRepo) LicenseByKey(ctx context.Context, accountID uuid.UUID, key string) (domain.License, error)

LicenseByKey loads the license by raw key.

func (LicensesRepo) LicenseEntitlementOf

func (r LicensesRepo) LicenseEntitlementOf(
	ctx context.Context, accountID, policyID, licenseID, id uuid.UUID,
) (domain.Entitlement, error)

LicenseEntitlementOf loads one of the license's entitlements.

func (LicensesRepo) LicenseIDExists

func (r LicensesRepo) LicenseIDExists(ctx context.Context, accountID, id uuid.UUID) (bool, error)

LicenseIDExists answers whether a license with the id exists.

func (LicensesRepo) LicenseKeyTaken

func (r LicensesRepo) LicenseKeyTaken(ctx context.Context, accountID uuid.UUID, key string) (bool, error)

LicenseKeyTaken answers whether some license already holds the key.

func (LicensesRepo) LicenseMachineByFingerprint

func (r LicensesRepo) LicenseMachineByFingerprint(
	ctx context.Context, accountID, licenseID uuid.UUID, fingerprint string, now time.Time,
) (domain.Machine, error)

LicenseMachineByFingerprint loads one of the license's machines by fingerprint.

func (LicensesRepo) LicenseMachineByID

func (r LicensesRepo) LicenseMachineByID(
	ctx context.Context, accountID, licenseID, id uuid.UUID, now time.Time,
) (domain.Machine, error)

LicenseMachineByID loads one of the license's machines by id.

func (LicensesRepo) LicenseMachines

func (r LicensesRepo) LicenseMachines(
	ctx context.Context, accountID, licenseID uuid.UUID, f licenses.MachineFilter, now time.Time,
) ([]domain.Machine, error)

LicenseMachines answers every machine of the license with its heartbeat status (the index and the validation share the rows).

func (LicensesRepo) LicenseNotificationCandidates

func (r LicensesRepo) LicenseNotificationCandidates(
	ctx context.Context, accountID uuid.UUID, now time.Time,
) ([]port.LicenseNotificationCandidate, error)

LicenseNotificationCandidates narrows the scan to the reference's windows.

func (LicensesRepo) LicenseUserMatches

func (r LicensesRepo) LicenseUserMatches(
	ctx context.Context, accountID, licenseID, userID uuid.UUID, email *string,
) (bool, error)

LicenseUserMatches answers whether the user (by id or email) is the owner or a licensee of the license.

func (LicensesRepo) LicenseUsesForUpdate

func (r LicensesRepo) LicenseUsesForUpdate(ctx context.Context, accountID, id uuid.UUID) (int32, error)

LicenseUsesForUpdate locks the counter without waiting, like Keygen's usage actions. The caller owns the pgtx boundary.

func (LicensesRepo) LicenseeIsUser

func (r LicensesRepo) LicenseeIsUser(ctx context.Context, accountID, licenseID, userID uuid.UUID) (bool, error)

LicenseeIsUser answers whether the user is a licensee.

func (LicensesRepo) ListLicenseEntitlementCodes

func (r LicensesRepo) ListLicenseEntitlementCodes(
	ctx context.Context, accountID, policyID, licenseID uuid.UUID,
) ([]string, error)

ListLicenseEntitlementCodes answers the union of the policy- and license-attached entitlement codes.

func (LicensesRepo) ListLicenseEntitlementRows

func (r LicensesRepo) ListLicenseEntitlementRows(
	ctx context.Context, accountID, licenseID uuid.UUID, entitlementIDs []uuid.UUID,
) ([]domain.LicenseEntitlement, error)

ListLicenseEntitlementRows answers the join rows of the attached entitlements.

func (LicensesRepo) ListLicenseEntitlementsOf

func (r LicensesRepo) ListLicenseEntitlementsOf(
	ctx context.Context, accountID, policyID, licenseID uuid.UUID, page Page,
) ([]domain.Entitlement, error)

ListLicenseEntitlementsOf pages the union of the policy- and license-attached entitlements.

func (LicensesRepo) ListLicenseUserRows

func (r LicensesRepo) ListLicenseUserRows(
	ctx context.Context, accountID, licenseID uuid.UUID, userIDs []uuid.UUID,
) ([]domain.LicenseUser, error)

ListLicenseUserRows answers the join rows of the attached users.

func (LicensesRepo) ListLicenses

func (r LicensesRepo) ListLicenses(
	ctx context.Context, accountID uuid.UUID, f licenses.Filter, scopeKind string,
	scopeID uuid.UUID, page Page, now time.Time,
) ([]domain.License, error)

ListLicenses pages the filtered scope.

func (LicensesRepo) SetLicenseExpiry

func (r LicensesRepo) SetLicenseExpiry(
	ctx context.Context, accountID, id uuid.UUID, expiry *time.Time, now time.Time,
) error

SetLicenseExpiry writes the expiry.

func (LicensesRepo) SetLicenseGroup

func (r LicensesRepo) SetLicenseGroup(
	ctx context.Context, accountID, id uuid.UUID, group uuid.NullUUID, now time.Time,
) error

SetLicenseGroup writes the group.

func (LicensesRepo) SetLicenseLastCheckIn

func (r LicensesRepo) SetLicenseLastCheckIn(
	ctx context.Context, accountID, id uuid.UUID, at, now time.Time,
) error

SetLicenseLastCheckIn writes the check-in timestamp.

func (LicensesRepo) SetLicenseLastCheckOut

func (r LicensesRepo) SetLicenseLastCheckOut(
	ctx context.Context, accountID, id uuid.UUID, at, now time.Time,
) error

SetLicenseLastCheckOut writes the check-out timestamp.

func (LicensesRepo) SetLicenseOwner

func (r LicensesRepo) SetLicenseOwner(
	ctx context.Context, accountID, id uuid.UUID, owner uuid.NullUUID, group uuid.NullUUID, now time.Time,
) error

SetLicenseOwner writes the owner (and the inherited group).

func (LicensesRepo) SetLicenseSuspended

func (r LicensesRepo) SetLicenseSuspended(
	ctx context.Context, accountID, id uuid.UUID, suspended bool, now time.Time,
) error

SetLicenseSuspended writes the suspension flag.

func (LicensesRepo) SetLicenseUsersCount

func (r LicensesRepo) SetLicenseUsersCount(ctx context.Context, accountID, licenseID uuid.UUID, count int32) error

SetLicenseUsersCount writes the denormalized licensee count.

func (LicensesRepo) SetLicenseUses

func (r LicensesRepo) SetLicenseUses(ctx context.Context, accountID, id uuid.UUID, uses int32, now time.Time) error

SetLicenseUses writes the usage counter.

func (LicensesRepo) StampLicenseNotification

func (r LicensesRepo) StampLicenseNotification(
	ctx context.Context, accountID, id uuid.UUID, event string, now time.Time,
) error

StampLicenseNotification persists the throttle in the caller's transaction.

func (LicensesRepo) SumLicenseMachinesForOwner

func (r LicensesRepo) SumLicenseMachinesForOwner(
	ctx context.Context, accountID, licenseID uuid.UUID, owner *uuid.UUID,
) (licenses.MachineSums, error)

SumLicenseMachinesForOwner answers the owner-scoped machine count and resource sums (the per-user lease math).

func (LicensesRepo) TouchLicenseValidated

func (r LicensesRepo) TouchLicenseValidated(
	ctx context.Context, accountID, id uuid.UUID, at time.Time, checksum, version *string,
) error

TouchLicenseValidated writes the validation touches.

func (LicensesRepo) TransferLicense

func (r LicensesRepo) TransferLicense(
	ctx context.Context, accountID, id, policyID, productID uuid.UUID, expiry *time.Time, now time.Time,
) error

TransferLicense moves the license to another policy.

func (LicensesRepo) TryLicenseNotificationLock

func (r LicensesRepo) TryLicenseNotificationLock(ctx context.Context) (bool, error)

TryLicenseNotificationLock shares the periodic jobs' transaction lock.

func (LicensesRepo) UpdateLicense

func (r LicensesRepo) UpdateLicense(ctx context.Context, l domain.License) error

UpdateLicense writes every mutable column.

type MachinesRepo added in v0.0.5

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

MachinesRepo adapts the machine rows to the machines scenario's ports (machines, the license lock, activation-token counters).

func (MachinesRepo) AppendUsage added in v0.0.5

func (r MachinesRepo) AppendUsage(
	ctx context.Context, accountID, machineID uuid.UUID, report usage.Report, events []usage.Event, ack usage.Acked,
) error

AppendUsage records an accepted report: its events, its ack and the new head.

func (MachinesRepo) ComponentFingerprintTaken added in v0.0.5

func (r MachinesRepo) ComponentFingerprintTaken(
	ctx context.Context, accountID uuid.UUID, in machines.Uniqueness, fingerprint string,
) (bool, error)

ComponentFingerprintTaken answers whether the fingerprint exists in the space.

func (MachinesRepo) CountMachines added in v0.0.5

func (r MachinesRepo) CountMachines(
	ctx context.Context, accountID uuid.UUID, f machines.Filter, scope machines.Scope, now time.Time,
) (int, error)

CountMachines counts the scoped, filtered index.

func (MachinesRepo) DeadMachines added in v0.0.5

func (r MachinesRepo) DeadMachines(ctx context.Context, now time.Time, limit int) ([]machines.Ref, error)

DeadMachines is a batch of dead machines for the cull.

func (MachinesRepo) DeadProcesses added in v0.0.5

func (r MachinesRepo) DeadProcesses(ctx context.Context, now time.Time, limit int) ([]machines.Ref, error)

DeadProcesses is a batch of dead processes for the cull.

func (MachinesRepo) DeleteComponent added in v0.0.5

func (r MachinesRepo) DeleteComponent(ctx context.Context, accountID, id uuid.UUID) error

DeleteComponent removes the component.

func (MachinesRepo) DeleteMachine added in v0.0.5

func (r MachinesRepo) DeleteMachine(ctx context.Context, accountID, id uuid.UUID) error

DeleteMachine removes the machine (its components and processes cascade).

func (MachinesRepo) DeleteProcess added in v0.0.5

func (r MachinesRepo) DeleteProcess(ctx context.Context, accountID, id uuid.UUID) error

DeleteProcess removes the process.

func (MachinesRepo) FindComponent added in v0.0.5

func (r MachinesRepo) FindComponent(
	ctx context.Context, accountID uuid.UUID, scope machines.Scope, id uuid.UUID,
) (domain.MachineComponent, error)

FindComponent loads a component within the scope.

func (MachinesRepo) FindMachine added in v0.0.5

func (r MachinesRepo) FindMachine(
	ctx context.Context, accountID uuid.UUID, scope machines.Scope, idOrFingerprint string, now time.Time,
) (domain.Machine, error)

FindMachine resolves an id or a fingerprint within the scope, the oldest machine first (FindByAliasService).

func (MachinesRepo) FindProcess added in v0.0.5

func (r MachinesRepo) FindProcess(
	ctx context.Context, accountID uuid.UUID, scope machines.Scope, id uuid.UUID, now time.Time,
) (domain.MachineProcess, error)

FindProcess loads a process within the scope.

func (MachinesRepo) FingerprintTaken added in v0.0.5

func (r MachinesRepo) FingerprintTaken(
	ctx context.Context, accountID uuid.UUID, in machines.Uniqueness, fingerprint string,
) (bool, error)

FingerprintTaken answers whether the fingerprint exists in the space.

func (MachinesRepo) GroupMachineCount added in v0.0.5

func (r MachinesRepo) GroupMachineCount(ctx context.Context, groupID uuid.UUID) (int, error)

GroupMachineCount counts the group's machines.

func (MachinesRepo) InsertComponent added in v0.0.5

func (r MachinesRepo) InsertComponent(ctx context.Context, c domain.MachineComponent) error

InsertComponent writes a component.

func (MachinesRepo) InsertMachine added in v0.0.5

func (r MachinesRepo) InsertMachine(ctx context.Context, m domain.Machine) error

InsertMachine writes a new machine.

func (MachinesRepo) InsertProcess added in v0.0.5

func (r MachinesRepo) InsertProcess(ctx context.Context, p domain.MachineProcess) error

InsertProcess writes a new process.

func (MachinesRepo) LicenseByID added in v0.0.5

func (r MachinesRepo) LicenseByID(ctx context.Context, accountID, id uuid.UUID) (domain.License, error)

LicenseByID loads the license with its policy.

func (MachinesRepo) LicenseHasUser added in v0.0.5

func (r MachinesRepo) LicenseHasUser(ctx context.Context, licenseID, userID uuid.UUID) (bool, error)

LicenseHasUser answers whether the user owns or uses the license.

func (MachinesRepo) ListComponents added in v0.0.5

func (r MachinesRepo) ListComponents(
	ctx context.Context, accountID uuid.UUID, f machines.SubFilter, scope machines.Scope, page Page,
) ([]domain.MachineComponent, int, error)

ListComponents reads a page of the scoped components and the total.

func (MachinesRepo) ListMachines added in v0.0.5

func (r MachinesRepo) ListMachines(
	ctx context.Context, accountID uuid.UUID, f machines.Filter, scope machines.Scope, page Page, now time.Time,
) ([]domain.Machine, error)

ListMachines reads one page of the scoped, filtered index.

func (MachinesRepo) ListProcesses added in v0.0.5

func (r MachinesRepo) ListProcesses(
	ctx context.Context, accountID uuid.UUID, f machines.SubFilter, scope machines.Scope, page Page, now time.Time,
) ([]domain.MachineProcess, int, error)

ListProcesses reads a page of the scoped processes and the total.

func (MachinesRepo) LockLicense added in v0.0.5

func (r MachinesRepo) LockLicense(ctx context.Context, accountID, id uuid.UUID) error

LockLicense takes the license row lock for the transaction.

func (MachinesRepo) LockToken added in v0.0.5

func (r MachinesRepo) LockToken(ctx context.Context, accountID, id uuid.UUID, nowait bool) (domain.Token, bool, error)

LockToken locks the token row NOWAIT or SKIP LOCKED; locked is false when another transaction holds it.

func (MachinesRepo) MachineExists added in v0.0.5

func (r MachinesRepo) MachineExists(ctx context.Context, accountID, id uuid.UUID) (bool, error)

MachineExists answers whether a machine has the id.

func (MachinesRepo) MachineTotals added in v0.0.5

func (r MachinesRepo) MachineTotals(
	ctx context.Context, licenseID uuid.UUID, perUser bool, owner machines.Owner, except uuid.UUID,
) (machines.Totals, error)

MachineTotals sums the license's machines other than except.

func (MachinesRepo) ProcessCount added in v0.0.5

func (r MachinesRepo) ProcessCount(
	ctx context.Context, kind string, scopeID uuid.UUID, owner machines.Owner,
) (int64, error)

ProcessCount counts the processes the limits compare against.

func (MachinesRepo) ProcessExists added in v0.0.5

func (r MachinesRepo) ProcessExists(ctx context.Context, id uuid.UUID) (bool, error)

ProcessExists answers whether a process has the id.

func (MachinesRepo) ProcessPidTaken added in v0.0.5

func (r MachinesRepo) ProcessPidTaken(ctx context.Context, machineID uuid.UUID, pid string) (bool, error)

ProcessPidTaken answers whether the machine runs a process with the pid.

func (MachinesRepo) RefreshLicenseCounters added in v0.0.5

func (r MachinesRepo) RefreshLicenseCounters(ctx context.Context, accountID, licenseID uuid.UUID, now time.Time) error

RefreshLicenseCounters rewrites the license's machine counter cache.

func (MachinesRepo) SetTokenCounters added in v0.0.5

func (r MachinesRepo) SetTokenCounters(
	ctx context.Context, accountID, id uuid.UUID, activations, deactivations int, now time.Time,
) error

SetTokenCounters writes the token's activation counters.

func (MachinesRepo) TokenByID added in v0.0.5

func (r MachinesRepo) TokenByID(ctx context.Context, accountID, id uuid.UUID) (domain.Token, error)

TokenByID loads the token.

func (MachinesRepo) UpdateComponent added in v0.0.5

func (r MachinesRepo) UpdateComponent(ctx context.Context, c domain.MachineComponent) error

UpdateComponent writes the mutable columns.

func (MachinesRepo) UpdateMachine added in v0.0.5

func (r MachinesRepo) UpdateMachine(ctx context.Context, m domain.Machine) error

UpdateMachine writes every mutable column.

func (MachinesRepo) UpdateProcess added in v0.0.5

func (r MachinesRepo) UpdateProcess(ctx context.Context, p domain.MachineProcess) error

UpdateProcess writes the mutable columns.

func (MachinesRepo) UsageAcks added in v0.0.5

func (r MachinesRepo) UsageAcks(
	ctx context.Context, machineID uuid.UUID, epoch, after uint64, limit int,
) ([]usage.Acked, error)

UsageAcks reads the epoch's acks after a sequence number.

func (MachinesRepo) UsageEvents added in v0.0.5

func (r MachinesRepo) UsageEvents(
	ctx context.Context, machineID uuid.UUID, epoch, after uint64, limit int,
) ([]usage.ResponseEvent, error)

UsageEvents reads the epoch's events after a sequence number.

func (MachinesRepo) UsageHead added in v0.0.5

func (r MachinesRepo) UsageHead(ctx context.Context, machineID uuid.UUID, forUpdate bool) (usage.Acked, error)

UsageHead loads the machine's accepted usage state (zero before the first report), locking it for the transaction when asked.

type Page

type Page = paging.Page

Page is the storage-layer list window (paging.Page).

type PoliciesRepo

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

PoliciesRepo adapts the policy queries to the policies scenario's storage port.

func (PoliciesRepo) CountPolicies

func (r PoliciesRepo) CountPolicies(ctx context.Context, accountID uuid.UUID, filterProductID *uuid.UUID, ids []uuid.UUID) (int, error)

CountPolicies counts the admin-side scope.

func (PoliciesRepo) CountProductPolicies

func (r PoliciesRepo) CountProductPolicies(ctx context.Context, accountID, productID uuid.UUID) (int, error)

CountProductPolicies counts the product-bearer scope.

func (PoliciesRepo) DeletePolicy

func (r PoliciesRepo) DeletePolicy(ctx context.Context, accountID, id uuid.UUID) (bool, error)

DeletePolicy destroys the policy; false when it was gone already.

func (PoliciesRepo) Do

func (r PoliciesRepo) Do(ctx context.Context, fn func(ctx context.Context) error) error

Do runs fn in one transaction (nested calls join the open one); actions deferred with commit.After run once it commits.

func (PoliciesRepo) InsertPolicy

func (r PoliciesRepo) InsertPolicy(ctx context.Context, p domain.Policy) error

InsertPolicy writes a new policy row.

func (PoliciesRepo) ListPolicies

func (r PoliciesRepo) ListPolicies(
	ctx context.Context, accountID uuid.UUID, filterProductID *uuid.UUID, ids []uuid.UUID, page Page,
) ([]domain.Policy, error)

ListPolicies pages the admin-side scope (user and license bearers load the same page and fail the post-check); filterProductID narrows by product when set.

func (PoliciesRepo) ListProductPolicies

func (r PoliciesRepo) ListProductPolicies(
	ctx context.Context, accountID, productID uuid.UUID, page Page,
) ([]domain.Policy, error)

ListProductPolicies pages the product-bearer scope.

func (PoliciesRepo) PolicyByID

func (r PoliciesRepo) PolicyByID(ctx context.Context, accountID, id uuid.UUID) (domain.Policy, error)

PolicyByID loads a policy by id.

func (PoliciesRepo) PolicyByLicense

func (r PoliciesRepo) PolicyByLicense(ctx context.Context, accountID, licenseID uuid.UUID) (domain.Policy, error)

PolicyByLicense loads the license bearer's own policy.

func (PoliciesRepo) UpdatePolicy

func (r PoliciesRepo) UpdatePolicy(ctx context.Context, p domain.Policy) error

UpdatePolicy overwrites the mutable columns.

func (PoliciesRepo) UserPolicyIDs

func (r PoliciesRepo) UserPolicyIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

UserPolicyIDs answers the policies of the user's licenses.

type ProductsRepo

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

ProductsRepo adapts the product queries to the products scenario's storage port.

func (ProductsRepo) CountAllProducts

func (r ProductsRepo) CountAllProducts(ctx context.Context, accountID uuid.UUID, ids []uuid.UUID) (int, error)

CountAllProducts counts the admin-side scope.

func (ProductsRepo) CountLicenseProducts

func (r ProductsRepo) CountLicenseProducts(ctx context.Context, accountID, productID uuid.UUID) (int, error)

CountLicenseProducts counts the license scope.

func (ProductsRepo) CountOwnProducts

func (r ProductsRepo) CountOwnProducts(ctx context.Context, accountID, bearerID uuid.UUID) (int, error)

CountOwnProducts counts the product-bearer scope.

func (ProductsRepo) CountProductTokens

func (r ProductsRepo) CountProductTokens(ctx context.Context, accountID, productID uuid.UUID) (int, error)

CountProductTokens counts the product's tokens.

func (ProductsRepo) CountProductUsers

func (r ProductsRepo) CountProductUsers(
	ctx context.Context, accountID, productID uuid.UUID, roles []string,
) (int, error)

CountProductUsers counts the product's users.

func (ProductsRepo) CountUserProducts

func (r ProductsRepo) CountUserProducts(ctx context.Context, accountID, userID uuid.UUID) (int, error)

CountUserProducts counts the user scope.

func (ProductsRepo) DeleteProduct

func (r ProductsRepo) DeleteProduct(ctx context.Context, accountID, id uuid.UUID) (bool, error)

DeleteProduct destroys the product; false when it was gone already.

func (ProductsRepo) Do

func (r ProductsRepo) Do(ctx context.Context, fn func(ctx context.Context) error) error

Do runs fn in one transaction (nested calls join the open one); actions deferred with commit.After run once it commits.

func (ProductsRepo) GetLicenseProductID

func (r ProductsRepo) GetLicenseProductID(
	ctx context.Context, accountID, licenseID uuid.UUID,
) (uuid.UUID, error)

GetLicenseProductID answers the license bearer's product id.

func (ProductsRepo) GetProductToken

func (r ProductsRepo) GetProductToken(
	ctx context.Context, accountID, productID, tokenID uuid.UUID,
) (domain.Token, error)

GetProductToken loads one of the product's tokens.

func (ProductsRepo) GetProductUserByEmail

func (r ProductsRepo) GetProductUserByEmail(
	ctx context.Context, accountID, productID uuid.UUID, roles []string, email string,
) (domain.User, error)

GetProductUserByEmail loads one of the product's users by email.

func (ProductsRepo) GetProductUserByID

func (r ProductsRepo) GetProductUserByID(
	ctx context.Context, accountID, productID uuid.UUID, roles []string, id uuid.UUID,
) (domain.User, error)

GetProductUserByID loads one of the product's users by id.

func (ProductsRepo) InsertProduct

func (r ProductsRepo) InsertProduct(ctx context.Context, p domain.Product) error

InsertProduct writes a new product row.

func (ProductsRepo) ListAllProducts

func (r ProductsRepo) ListAllProducts(ctx context.Context, accountID uuid.UUID, ids []uuid.UUID, page Page) ([]domain.Product, error)

ListAllProducts pages the account's products (the admin-side scope). ids narrows the scope to a search's matches; nil keeps the whole account.

func (ProductsRepo) ListLicenseProducts

func (r ProductsRepo) ListLicenseProducts(
	ctx context.Context, accountID, productID uuid.UUID, page Page,
) ([]domain.Product, error)

ListLicenseProducts pages the license scope: open products UNION the license's own product.

func (ProductsRepo) ListOwnProducts

func (r ProductsRepo) ListOwnProducts(
	ctx context.Context, accountID, bearerID uuid.UUID, page Page,
) ([]domain.Product, error)

ListOwnProducts pages the product-bearer scope: the bearer itself.

func (ProductsRepo) ListProductTokens

func (r ProductsRepo) ListProductTokens(
	ctx context.Context, accountID, productID uuid.UUID, page Page,
) ([]domain.Token, error)

ListProductTokens pages the product's tokens.

func (ProductsRepo) ListProductUsers

func (r ProductsRepo) ListProductUsers(
	ctx context.Context, accountID, productID uuid.UUID, roles []string, page Page,
) ([]domain.User, error)

ListProductUsers pages the product's users (via its licenses).

func (ProductsRepo) ListUserProducts

func (r ProductsRepo) ListUserProducts(
	ctx context.Context, accountID, userID uuid.UUID, page Page,
) ([]domain.Product, error)

ListUserProducts pages the user scope: open products UNION the products of the user's licenses.

func (ProductsRepo) ProductByCode

func (r ProductsRepo) ProductByCode(ctx context.Context, accountID uuid.UUID, code string) (domain.Product, error)

ProductByCode loads a product by its (case-insensitive) code alias.

func (ProductsRepo) ProductByID

func (r ProductsRepo) ProductByID(ctx context.Context, accountID, id uuid.UUID) (domain.Product, error)

ProductByID loads a product by id.

func (ProductsRepo) UpdateProduct

func (r ProductsRepo) UpdateProduct(ctx context.Context, p domain.Product) error

UpdateProduct overwrites the mutable columns.

func (ProductsRepo) UserProductIDs

func (r ProductsRepo) UserProductIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

UserProductIDs answers the user's licensed products.

type SecondFactorsRepo

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

SecondFactorsRepo adapts the generated second-factor queries to the secondfactors scenario's storage port.

func (SecondFactorsRepo) AnySecondFactor

func (r SecondFactorsRepo) AnySecondFactor(ctx context.Context, userID uuid.UUID) (domain.SecondFactor, error)

AnySecondFactor loads the user's (only) factor.

func (SecondFactorsRepo) DeleteSecondFactor

func (r SecondFactorsRepo) DeleteSecondFactor(
	ctx context.Context, accountID, userID, id uuid.UUID,
) error

DeleteSecondFactor removes the factor.

func (SecondFactorsRepo) Do

func (r SecondFactorsRepo) Do(ctx context.Context, fn func(ctx context.Context) error) error

Do runs fn in one transaction (nested calls join the open one); actions deferred with commit.After run once it commits.

func (SecondFactorsRepo) InsertSecondFactor

func (r SecondFactorsRepo) InsertSecondFactor(ctx context.Context, factor domain.SecondFactor) error

InsertSecondFactor writes the factor.

func (SecondFactorsRepo) ListSecondFactors

func (r SecondFactorsRepo) ListSecondFactors(
	ctx context.Context, accountID, userID uuid.UUID, limit int,
) ([]domain.SecondFactor, error)

ListSecondFactors answers the user's factors.

func (SecondFactorsRepo) SecondFactorByID

func (r SecondFactorsRepo) SecondFactorByID(
	ctx context.Context, accountID, userID, id uuid.UUID,
) (domain.SecondFactor, error)

SecondFactorByID loads the user's factor.

func (SecondFactorsRepo) UpdateSecondFactor

func (r SecondFactorsRepo) UpdateSecondFactor(ctx context.Context, factor domain.SecondFactor) error

UpdateSecondFactor writes enabled and the replay guard.

func (SecondFactorsRepo) VerifySecondFactor

func (r SecondFactorsRepo) VerifySecondFactor(
	ctx context.Context, userID uuid.UUID, otp string, now time.Time,
) (bool, error)

VerifySecondFactor locks the factor while checking and consuming the OTP.

type Store

type Store struct {
	*postgres.DB

	// Q runs on DB: inside the context's transaction, else the pool.
	Q *db.Queries

	// Accounts is the account repository.
	Accounts AccountsRepo
	// Users is the users repository.
	Users UsersRepo
	// Tokens is the tokens repository.
	Tokens TokensRepo
	// Licenses is the license-auth repository.
	Licenses LicensesRepo
	// Products is the products repository.
	Products ProductsRepo
	// Policies is the policies repository.
	Policies PoliciesRepo
	// Entitlements is the entitlements and policy_entitlements repository.
	Entitlements EntitlementsRepo
	// Keys is the keys repository.
	Keys KeysRepo
	// Groups is the groups repository.
	Groups GroupsRepo
	// SecondFactors is the second-factors repository.
	SecondFactors SecondFactorsRepo
	// Webhooks is the webhook endpoints and events repository.
	Webhooks WebhooksRepo
	// Jobs is the periodic-jobs repository.
	Jobs     JobsRepo
	Machines MachinesRepo
}

Store is the connection with the typed queries and repositories.

func Open

func Open(ctx context.Context, log *xlog.Logger, cfg postgres.Config) (*Store, error)

Open connects outside the dependency tree (tests, one-off tools): the same schema and embedded migrations as the provider.

func (*Store) Account

func (s *Store) Account(ctx context.Context, id uuid.UUID) (domain.Account, error)

Account loads the account by id.

func (*Store) AnySecondFactor

func (s *Store) AnySecondFactor(ctx context.Context, userID uuid.UUID) (domain.SecondFactor, error)

AnySecondFactor loads the user's (only) factor.

func (*Store) AutomationActivityResult

func (s *Store) AutomationActivityResult(ctx context.Context, accountID uuid.UUID, key string,
) (port.ActivityReceipt, error)

func (*Store) BearerUser

func (s *Store) BearerUser(ctx context.Context, accountID, id uuid.UUID) (domain.User, error)

BearerUser loads the override bearer (a user).

func (*Store) ConsoleCounts

func (s *Store) ConsoleCounts(ctx context.Context, accountID uuid.UUID) (map[string]int64, error)

ConsoleCounts returns the operator's account-scoped resource overview.

func (*Store) CountAdmins

func (s *Store) CountAdmins(ctx context.Context, accountID uuid.UUID) (int, error)

CountAdmins answers the account's admin count.

func (*Store) CountGroupUsers

func (s *Store) CountGroupUsers(ctx context.Context, accountID, groupID uuid.UUID) (int, error)

CountGroupUsers answers the group's member count.

func (*Store) CountGroups

func (s *Store) CountGroups(ctx context.Context, accountID uuid.UUID, memberUser uuid.NullUUID, ids []uuid.UUID) (int, error)

CountGroups answers the member-scoped total.

func (*Store) CountTokens

func (s *Store) CountTokens(
	ctx context.Context, accountID uuid.UUID, f tokens.Filter, scopeKind string, scopeID uuid.UUID,
) (int, error)

CountTokens answers the filtered, scoped total.

func (*Store) CountUsers

func (s *Store) CountUsers(
	ctx context.Context, accountID uuid.UUID, f users.Filter, scopeKind string, scopeID uuid.UUID,
) (int, error)

CountUsers answers the filter's total.

func (*Store) CountWebhookEndpoints

func (s *Store) CountWebhookEndpoints(
	ctx context.Context, accountID uuid.UUID, product uuid.NullUUID,
) (int, error)

CountWebhookEndpoints answers the scoped total.

func (*Store) CountWebhookEvents

func (s *Store) CountWebhookEvents(
	ctx context.Context, accountID uuid.UUID, filter webhooks.EventFilter, product uuid.NullUUID,
) (int, error)

CountWebhookEvents answers the filtered total.

func (*Store) DeleteGroup

func (s *Store) DeleteGroup(ctx context.Context, accountID, id uuid.UUID) error

DeleteGroup removes the group.

func (*Store) DeleteGroupOwnersByUsers

func (s *Store) DeleteGroupOwnersByUsers(
	ctx context.Context, accountID, groupID uuid.UUID, userIDs []uuid.UUID,
) (int64, error)

DeleteGroupOwnersByUsers detaches the given users.

func (*Store) DeleteSecondFactor

func (s *Store) DeleteSecondFactor(ctx context.Context, accountID, userID, id uuid.UUID) error

DeleteSecondFactor removes the factor.

func (*Store) DeleteToken

func (s *Store) DeleteToken(ctx context.Context, accountID, id uuid.UUID) error

DeleteToken removes the row.

func (*Store) DeleteUser

func (s *Store) DeleteUser(ctx context.Context, accountID, id uuid.UUID) error

DeleteUser removes the row.

func (*Store) DeleteUserTokens

func (s *Store) DeleteUserTokens(ctx context.Context, accountID, userID uuid.UUID) error

DeleteUserTokens revokes every token of the user.

func (*Store) DeleteUserTokensExcept

func (s *Store) DeleteUserTokensExcept(ctx context.Context, accountID, userID, exceptID uuid.UUID) error

DeleteUserTokensExcept revokes every token of the user but the acting one.

func (*Store) DeleteWebhookEndpoint

func (s *Store) DeleteWebhookEndpoint(ctx context.Context, accountID, id uuid.UUID) error

DeleteWebhookEndpoint removes the endpoint.

func (*Store) DeleteWebhookEvent

func (s *Store) DeleteWebhookEvent(ctx context.Context, accountID, id uuid.UUID) error

DeleteWebhookEvent removes the event.

func (*Store) DisableWebhookEndpoint

func (s *Store) DisableWebhookEndpoint(ctx context.Context, accountID, id uuid.UUID) error

DisableWebhookEndpoint empties the subscriptions.

func (*Store) Do

func (s *Store) Do(ctx context.Context, fn func(ctx context.Context) error) error

Do runs fn in one read-committed transaction; every store query that carries the transaction's context joins it (pgtx). Nested calls join the open transaction. Actions deferred with commit.After inside fn run once it commits.

func (*Store) EnabledSecondFactorSecret

func (s *Store) EnabledSecondFactorSecret(ctx context.Context, userID uuid.UUID) (string, bool, error)

EnabledSecondFactorSecret loads the user's enabled TOTP secret.

func (*Store) GetGroupOwner

func (s *Store) GetGroupOwner(ctx context.Context, accountID, groupID, ownerID uuid.UUID) (domain.GroupOwner, error)

GetGroupOwner loads a group-owner row.

func (*Store) GetGroupOwnerByUser

func (s *Store) GetGroupOwnerByUser(
	ctx context.Context, accountID, groupID, userID uuid.UUID,
) (domain.GroupOwner, error)

GetGroupOwnerByUser loads the group-owner row of a user.

func (*Store) GroupByID

func (s *Store) GroupByID(ctx context.Context, accountID, id uuid.UUID) (domain.Group, error)

GroupByID loads a group; ErrNotFound.

func (*Store) GroupIDsOfUser

func (s *Store) GroupIDsOfUser(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

GroupIDsOfUser answers the group ids the user belongs to or owns.

func (*Store) InsertAccount

func (s *Store) InsertAccount(ctx context.Context, account domain.Account) error

InsertAccount writes a new account row.

func (*Store) InsertGroup

func (s *Store) InsertGroup(ctx context.Context, group domain.Group) error

InsertGroup writes a new group row.

func (*Store) InsertGroupOwner

func (s *Store) InsertGroupOwner(ctx context.Context, owner domain.GroupOwner) error

InsertGroupOwner attaches a user as owner.

func (*Store) InsertSecondFactor

func (s *Store) InsertSecondFactor(ctx context.Context, factor domain.SecondFactor) error

InsertSecondFactor writes the factor.

func (*Store) InsertToken

func (s *Store) InsertToken(ctx context.Context, token domain.Token) error

InsertToken writes a new token row.

func (*Store) InsertUser

func (s *Store) InsertUser(ctx context.Context, user domain.User) error

InsertUser writes a new user row.

func (*Store) InsertWebhookEndpoint

func (s *Store) InsertWebhookEndpoint(ctx context.Context, endpoint domain.WebhookEndpoint) error

InsertWebhookEndpoint writes a new endpoint row.

func (*Store) InsertWebhookEvent

func (s *Store) InsertWebhookEvent(ctx context.Context, event domain.WebhookEvent) error

InsertWebhookEvent writes an outbox row.

func (*Store) LicenseByID

func (s *Store) LicenseByID(ctx context.Context, accountID, id uuid.UUID) (domain.LicenseAuth, error)

LicenseByID loads the license-auth slice by id.

func (*Store) LicenseByKey

func (s *Store) LicenseByKey(ctx context.Context, accountID uuid.UUID, key string) (domain.LicenseAuth, error)

LicenseByKey loads the license-auth slice by key.

func (*Store) LicenseOfProduct

func (s *Store) LicenseOfProduct(
	ctx context.Context, accountID, licenseID, productID uuid.UUID,
) (bool, error)

LicenseOfProduct answers whether the license belongs to the product.

func (*Store) ListGroupLicenseIDs

func (s *Store) ListGroupLicenseIDs(ctx context.Context, accountID, groupID uuid.UUID, limit int) ([]uuid.UUID, error)

ListGroupLicenseIDs answers the group's license ids.

func (*Store) ListGroupMachineIDs

func (s *Store) ListGroupMachineIDs(ctx context.Context, accountID, groupID uuid.UUID, limit int) ([]uuid.UUID, error)

ListGroupMachineIDs answers the group's machine ids.

func (*Store) ListGroupOwners

func (s *Store) ListGroupOwners(
	ctx context.Context, accountID, groupID uuid.UUID, limit int,
) ([]domain.GroupOwner, error)

ListGroupOwners answers the group's owners.

func (*Store) ListGroupUsers

func (s *Store) ListGroupUsers(
	ctx context.Context, accountID, groupID uuid.UUID, limit int,
) ([]domain.User, error)

ListGroupUsers answers the group's member users.

func (*Store) ListGroups

func (s *Store) ListGroups(
	ctx context.Context, accountID uuid.UUID, memberUser uuid.NullUUID, ids []uuid.UUID, p paging.Params,
) ([]domain.Group, error)

ListGroups answers the member-scoped page.

func (*Store) ListSecondFactors

func (s *Store) ListSecondFactors(
	ctx context.Context, accountID, userID uuid.UUID, limit int,
) ([]domain.SecondFactor, error)

ListSecondFactors answers the user's factors.

func (*Store) ListTokens

func (s *Store) ListTokens(
	ctx context.Context, accountID uuid.UUID, f tokens.Filter, scopeKind string, scopeID uuid.UUID, p paging.Params,
) ([]domain.Token, error)

ListTokens answers the filtered, scoped page.

func (*Store) ListUsers

func (s *Store) ListUsers(
	ctx context.Context, accountID uuid.UUID, f users.Filter, scopeKind string,
	scopeID uuid.UUID, p paging.Params,
) ([]users.Listed, error)

ListUsers answers the filtered page with computed statuses.

func (*Store) ListWebhookEndpoints

func (s *Store) ListWebhookEndpoints(
	ctx context.Context, accountID uuid.UUID, product uuid.NullUUID, page paging.Params,
) ([]domain.WebhookEndpoint, error)

ListWebhookEndpoints answers the scoped page.

func (*Store) ListWebhookEvents

func (s *Store) ListWebhookEvents(
	ctx context.Context, accountID uuid.UUID, filter webhooks.EventFilter,
	product uuid.NullUUID, page paging.Params,
) ([]domain.WebhookEvent, error)

ListWebhookEvents answers the filtered page.

func (*Store) LockAutomationActivity

func (s *Store) LockAutomationActivity(ctx context.Context, accountID uuid.UUID, key string) error

func (*Store) LockCatalog added in v0.0.18

func (s *Store) LockCatalog(ctx context.Context, accountID uuid.UUID) error

LockCatalog takes the account's catalog lock until the transaction ends.

func (*Store) OwnedGroupIDsOfUser

func (s *Store) OwnedGroupIDsOfUser(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

OwnedGroupIDsOfUser answers the user's ownership-only group scope.

func (*Store) PolicyByID

func (s *Store) PolicyByID(ctx context.Context, accountID, id uuid.UUID) (domain.Policy, error)

PolicyByID loads a policy; ErrNotFound.

func (*Store) PolicyIDs added in v0.0.18

func (s *Store) PolicyIDs(ctx context.Context, accountID uuid.UUID) ([]uuid.UUID, error)

PolicyIDs lists the account's policy ids.

func (*Store) ProductByID

func (s *Store) ProductByID(ctx context.Context, accountID, id uuid.UUID) (domain.Product, error)

func (*Store) ProductIDs added in v0.0.18

func (s *Store) ProductIDs(ctx context.Context, accountID uuid.UUID) ([]uuid.UUID, error)

ProductIDs lists the account's product ids.

func (*Store) ProductTokens added in v0.0.18

func (s *Store) ProductTokens(ctx context.Context, accountID uuid.UUID) ([]domain.Token, error)

ProductTokens lists the account's product tokens, oldest first.

func (*Store) PruneExpiredTokens

func (s *Store) PruneExpiredTokens(ctx context.Context, cutoff time.Time) (int64, error)

PruneExpiredTokens deletes tokens past their grace window.

func (*Store) PruneWebhookEvents

func (s *Store) PruneWebhookEvents(ctx context.Context, cutoff time.Time) (int64, error)

PruneWebhookEvents deletes events older than the cutoff.

func (*Store) RegenerateToken

func (s *Store) RegenerateToken(
	ctx context.Context, accountID, id uuid.UUID, digest string, expiry *time.Time,
) error

RegenerateToken writes the new digest (and reset expiry).

func (*Store) SaveAutomationActivityResult

func (s *Store) SaveAutomationActivityResult(ctx context.Context, accountID uuid.UUID, key string,
	receipt port.ActivityReceipt,
) error

func (*Store) SearchIDs

func (s *Store) SearchIDs(
	ctx context.Context, accountID uuid.UUID, resource, attribute string, t search.Term,
) ([]uuid.UUID, error)

SearchIDs answers the ids the term matches in one attribute of a resource.

func (*Store) SecondFactorByID

func (s *Store) SecondFactorByID(
	ctx context.Context, accountID, userID, id uuid.UUID,
) (domain.SecondFactor, error)

SecondFactorByID loads the user's factor.

func (*Store) SetDeclaredToken added in v0.0.18

func (s *Store) SetDeclaredToken(
	ctx context.Context, accountID, id uuid.UUID, digest string, permissions []string,
) error

SetDeclaredToken writes the token's digest and permissions.

func (*Store) SetUserBannedAt

func (s *Store) SetUserBannedAt(ctx context.Context, accountID, id uuid.UUID, bannedAt *time.Time) error

SetUserBannedAt writes (or clears) the ban timestamp.

func (*Store) SetUserPasswordReset

func (s *Store) SetUserPasswordReset(
	ctx context.Context, accountID, id uuid.UUID, token string, sentAt time.Time,
) error

SetUserPasswordReset stores the reset token digest and timestamp.

func (*Store) SetWebhookEventDelivered

func (s *Store) SetWebhookEventDelivered(
	ctx context.Context, accountID, id uuid.UUID, code int, body string,
) error

SetWebhookEventDelivered records a 2xx outcome.

func (*Store) SetWebhookEventExhausted

func (s *Store) SetWebhookEventExhausted(ctx context.Context, accountID, id uuid.UUID) error

SetWebhookEventExhausted records exhaustion without an HTTP outcome.

func (*Store) SetWebhookEventFailure

func (s *Store) SetWebhookEventFailure(
	ctx context.Context, accountID, id uuid.UUID, status domain.WebhookEventStatus,
	code *int, body string,
) error

SetWebhookEventFailure records a failure outcome.

func (*Store) SubscribedWebhookEndpoints

func (s *Store) SubscribedWebhookEndpoints(
	ctx context.Context, accountID uuid.UUID, event string,
) ([]domain.WebhookEndpoint, error)

SubscribedWebhookEndpoints answers an event's fan-out candidates.

func (*Store) TokenByDigest

func (s *Store) TokenByDigest(ctx context.Context, accountID uuid.UUID, digest string) (domain.Token, error)

TokenByDigest loads a token by its digest.

func (*Store) TokenByID

func (s *Store) TokenByID(ctx context.Context, accountID, id uuid.UUID) (domain.Token, error)

TokenByID loads a token by its id.

func (*Store) TryAdvisoryLock

func (s *Store) TryAdvisoryLock(ctx context.Context) (bool, error)

TryAdvisoryLock answers whether the caller's transaction won the jobs lock.

func (*Store) UpdateGroup

func (s *Store) UpdateGroup(ctx context.Context, group domain.Group) error

UpdateGroup writes every mutable column.

func (*Store) UpdateSecondFactor

func (s *Store) UpdateSecondFactor(ctx context.Context, factor domain.SecondFactor) error

UpdateSecondFactor writes enabled and the replay guard.

func (*Store) UpdateUser

func (s *Store) UpdateUser(ctx context.Context, user domain.User, attrs users.Attrs) error

UpdateUser writes every mutable column of the row.

func (*Store) UpdateUserPassword

func (s *Store) UpdateUserPassword(ctx context.Context, accountID, id uuid.UUID, digest string) error

UpdateUserPassword writes a new password digest and clears the reset fields.

func (*Store) UpdateWebhookEndpoint

func (s *Store) UpdateWebhookEndpoint(ctx context.Context, endpoint domain.WebhookEndpoint) error

UpdateWebhookEndpoint writes every mutable column.

func (*Store) UserByEmail

func (s *Store) UserByEmail(ctx context.Context, accountID uuid.UUID, email string) (domain.User, error)

UserByEmail loads a user by downcased email; ErrNotFound when none.

func (*Store) UserByID

func (s *Store) UserByID(ctx context.Context, accountID, id uuid.UUID) (domain.User, error)

UserByID loads a user; ErrNotFound when none.

func (*Store) UserHasActiveLicense

func (s *Store) UserHasActiveLicense(ctx context.Context, accountID, id uuid.UUID) (bool, error)

UserHasActiveLicense answers the user's status input.

func (*Store) UserIsTeammate

func (s *Store) UserIsTeammate(ctx context.Context, accountID, userID, otherID uuid.UUID) (bool, error)

UserIsTeammate answers whether other shares a license with user.

func (*Store) UserLicenseIDs

func (s *Store) UserLicenseIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

UserLicenseIDs answers the user's license ids.

func (*Store) UserLicensedToProduct

func (s *Store) UserLicensedToProduct(
	ctx context.Context, accountID, userID, productID uuid.UUID,
) (bool, error)

UserLicensedToProduct answers the product-scope membership check.

func (*Store) UserMachineIDs

func (s *Store) UserMachineIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

UserMachineIDs answers the user's machine ids.

func (*Store) UserOfLicense

func (s *Store) UserOfLicense(ctx context.Context, accountID, licenseID, userID uuid.UUID) (bool, error)

UserOfLicense answers whether the user owns or is attached to the license.

func (*Store) UserProductIDs

func (s *Store) UserProductIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

UserProductIDs answers the product ids behind the user's licenses.

func (*Store) VerifySecondFactor

func (s *Store) VerifySecondFactor(ctx context.Context, userID uuid.UUID, otp string, now time.Time) (bool, error)

VerifySecondFactor atomically checks and consumes an enabled factor's code.

func (*Store) WebhookEndpointByID

func (s *Store) WebhookEndpointByID(
	ctx context.Context, accountID, id uuid.UUID,
) (domain.WebhookEndpoint, error)

WebhookEndpointByID loads an endpoint; ErrNotFound.

func (*Store) WebhookEndpointByURL

func (s *Store) WebhookEndpointByURL(
	ctx context.Context, accountID uuid.UUID, url string,
) (domain.WebhookEndpoint, error)

WebhookEndpointByURL loads the first endpoint with the URL.

func (*Store) WebhookEndpointProduct

func (s *Store) WebhookEndpointProduct(
	ctx context.Context, accountID, id uuid.UUID,
) (uuid.NullUUID, error)

WebhookEndpointProduct answers an endpoint's product.

func (*Store) WebhookEventByID

func (s *Store) WebhookEventByID(
	ctx context.Context, accountID, id uuid.UUID,
) (domain.WebhookEvent, error)

WebhookEventByID loads an event; ErrNotFound.

type TokensRepo

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

TokensRepo adapts the generated token queries to the authn and tokens scenarios' storage ports.

func (TokensRepo) CountTokens

func (r TokensRepo) CountTokens(
	ctx context.Context, accountID uuid.UUID, f tokens.Filter, scopeKind string, scopeID uuid.UUID,
) (int, error)

CountTokens answers the filtered, scoped total.

func (TokensRepo) DeleteToken

func (r TokensRepo) DeleteToken(ctx context.Context, accountID, id uuid.UUID) error

DeleteToken removes the row.

func (TokensRepo) InsertToken

func (r TokensRepo) InsertToken(ctx context.Context, token domain.Token) error

InsertToken writes a new token row.

func (TokensRepo) LicenseOfProduct

func (r TokensRepo) LicenseOfProduct(
	ctx context.Context, accountID, licenseID, productID uuid.UUID,
) (bool, error)

LicenseOfProduct answers whether the license belongs to the product.

func (TokensRepo) ListTokens

func (r TokensRepo) ListTokens(
	ctx context.Context, accountID uuid.UUID, f tokens.Filter, scopeKind string, scopeID uuid.UUID, p paging.Params,
) ([]domain.Token, error)

ListTokens answers the filtered, scoped page.

func (TokensRepo) RegenerateToken

func (r TokensRepo) RegenerateToken(
	ctx context.Context, accountID, id uuid.UUID, digest string, expiry *time.Time,
) error

RegenerateToken writes the new digest (and the reset expiry).

func (TokensRepo) TokenByDigest

func (r TokensRepo) TokenByDigest(ctx context.Context, accountID uuid.UUID, digest string) (domain.Token, error)

TokenByDigest loads a token by its digest.

func (TokensRepo) TokenByID

func (r TokensRepo) TokenByID(ctx context.Context, accountID, id uuid.UUID) (domain.Token, error)

TokenByID loads a token by its id.

func (TokensRepo) UserLicensedToProduct

func (r TokensRepo) UserLicensedToProduct(
	ctx context.Context, accountID, userID, productID uuid.UUID,
) (bool, error)

UserLicensedToProduct answers the product-scope membership check.

type UsersRepo

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

UsersRepo adapts the generated user queries to the users, authn and secondfactors scenarios' storage ports.

func (UsersRepo) CountAdmins

func (r UsersRepo) CountAdmins(ctx context.Context, accountID uuid.UUID) (int, error)

CountAdmins answers the account's admin count (the last-admin guard).

func (UsersRepo) CountGroupUsers

func (r UsersRepo) CountGroupUsers(ctx context.Context, accountID, groupID uuid.UUID) (int, error)

CountGroupUsers answers the group's member count (limit checks).

func (UsersRepo) CountUsers

func (r UsersRepo) CountUsers(
	ctx context.Context, accountID uuid.UUID, f users.Filter, scopeKind string, scopeID uuid.UUID,
) (int, error)

CountUsers answers the filter's total (offset pagination meta).

func (UsersRepo) DeleteUser

func (r UsersRepo) DeleteUser(ctx context.Context, accountID, id uuid.UUID) error

DeleteUser removes the row (licenses survive, owner nulled).

func (UsersRepo) DeleteUserTokens

func (r UsersRepo) DeleteUserTokens(ctx context.Context, accountID, userID uuid.UUID) error

DeleteUserTokens revokes every token of the user.

func (UsersRepo) DeleteUserTokensExcept

func (r UsersRepo) DeleteUserTokensExcept(
	ctx context.Context, accountID, userID, exceptID uuid.UUID,
) error

DeleteUserTokensExcept revokes every token of the user but the acting one.

func (UsersRepo) EnabledSecondFactorSecret

func (r UsersRepo) EnabledSecondFactorSecret(ctx context.Context, userID uuid.UUID) (string, bool, error)

EnabledSecondFactorSecret loads the user's enabled TOTP secret.

func (UsersRepo) GroupIDsOfUser

func (r UsersRepo) GroupIDsOfUser(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

GroupIDsOfUser answers the ids of the groups the user belongs to (membership via group_id plus owned groups).

func (UsersRepo) InsertUser

func (r UsersRepo) InsertUser(ctx context.Context, user domain.User) error

InsertUser writes a new user row.

func (UsersRepo) ListUsers

func (r UsersRepo) ListUsers(
	ctx context.Context, accountID uuid.UUID, f users.Filter, scopeKind string,
	scopeID uuid.UUID, p paging.Params,
) ([]users.Listed, error)

ListUsers answers the filtered, paginated page with each row's computed status.

func (UsersRepo) SetUserBannedAt

func (r UsersRepo) SetUserBannedAt(
	ctx context.Context, accountID, id uuid.UUID, bannedAt *time.Time,
) error

SetUserBannedAt writes (or clears) the ban timestamp.

func (UsersRepo) SetUserPasswordReset

func (r UsersRepo) SetUserPasswordReset(
	ctx context.Context, accountID, id uuid.UUID, token string, sentAt time.Time,
) error

SetUserPasswordReset stores the reset token digest and timestamp.

func (UsersRepo) UpdateUser

func (r UsersRepo) UpdateUser(ctx context.Context, user domain.User, attrs users.Attrs) error

UpdateUser writes only addressed fields, never stale reset or ban state.

func (UsersRepo) UpdateUserPassword

func (r UsersRepo) UpdateUserPassword(
	ctx context.Context, accountID, id uuid.UUID, digest string,
) error

UpdateUserPassword writes the new digest and clears the reset fields.

func (UsersRepo) UserByEmail

func (r UsersRepo) UserByEmail(ctx context.Context, accountID uuid.UUID, email string) (domain.User, error)

UserByEmail loads a user by (downcased) email.

func (UsersRepo) UserByID

func (r UsersRepo) UserByID(ctx context.Context, accountID, id uuid.UUID) (domain.User, error)

UserByID loads a user by id.

func (UsersRepo) UserHasActiveLicense

func (r UsersRepo) UserHasActiveLicense(ctx context.Context, accountID, id uuid.UUID) (bool, error)

UserHasActiveLicense answers whether the user owns or is attached to a license with activity within the last 90 days.

func (UsersRepo) UserIsTeammate

func (r UsersRepo) UserIsTeammate(ctx context.Context, accountID, userID, otherID uuid.UUID) (bool, error)

UserIsTeammate answers whether other shares a license with user.

func (UsersRepo) UserLicenseIDs

func (r UsersRepo) UserLicenseIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

UserLicenseIDs answers the ids of the user's licenses (owned or attached).

func (UsersRepo) UserMachineIDs

func (r UsersRepo) UserMachineIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

UserMachineIDs answers the ids of the user's machines.

func (UsersRepo) UserOfLicense

func (r UsersRepo) UserOfLicense(ctx context.Context, accountID, licenseID, userID uuid.UUID) (bool, error)

UserOfLicense answers whether the user owns or is attached to the license.

func (UsersRepo) UserProductIDs

func (r UsersRepo) UserProductIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)

UserProductIDs answers the ids of the products behind the user's licenses.

type WebhooksRepo

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

WebhooksRepo adapts the webhook endpoint and event queries to the webhooks scenario's storage port (and the publisher's).

func (WebhooksRepo) CountWebhookEndpoints

func (r WebhooksRepo) CountWebhookEndpoints(
	ctx context.Context, accountID uuid.UUID, product uuid.NullUUID,
) (int, error)

CountWebhookEndpoints answers the scoped total.

func (WebhooksRepo) CountWebhookEvents

func (r WebhooksRepo) CountWebhookEvents(
	ctx context.Context, accountID uuid.UUID, f webhooks.EventFilter, product uuid.NullUUID,
) (int, error)

CountWebhookEvents answers the filtered total.

func (WebhooksRepo) DeleteWebhookEndpoint

func (r WebhooksRepo) DeleteWebhookEndpoint(ctx context.Context, accountID, id uuid.UUID) error

DeleteWebhookEndpoint removes the endpoint.

func (WebhooksRepo) DeleteWebhookEvent

func (r WebhooksRepo) DeleteWebhookEvent(ctx context.Context, accountID, id uuid.UUID) error

DeleteWebhookEvent removes the event.

func (WebhooksRepo) DisableWebhookEndpoint

func (r WebhooksRepo) DisableWebhookEndpoint(ctx context.Context, accountID, id uuid.UUID) error

DisableWebhookEndpoint empties the subscriptions (auto-disable).

func (WebhooksRepo) InsertWebhookEndpoint

func (r WebhooksRepo) InsertWebhookEndpoint(ctx context.Context, e domain.WebhookEndpoint) error

InsertWebhookEndpoint writes a new endpoint row.

func (WebhooksRepo) InsertWebhookEvent

func (r WebhooksRepo) InsertWebhookEvent(ctx context.Context, e domain.WebhookEvent) error

InsertWebhookEvent writes an outbox row (inside the caller's transaction when the context carries one).

func (WebhooksRepo) ListWebhookEndpoints

func (r WebhooksRepo) ListWebhookEndpoints(
	ctx context.Context, accountID uuid.UUID, product uuid.NullUUID, p paging.Params,
) ([]domain.WebhookEndpoint, error)

ListWebhookEndpoints answers the (product-scoped) page.

func (WebhooksRepo) ListWebhookEvents

func (r WebhooksRepo) ListWebhookEvents(
	ctx context.Context, accountID uuid.UUID, f webhooks.EventFilter, product uuid.NullUUID,
	p paging.Params,
) ([]domain.WebhookEvent, error)

ListWebhookEvents answers the filtered page.

func (WebhooksRepo) SetWebhookEventDelivered

func (r WebhooksRepo) SetWebhookEventDelivered(
	ctx context.Context, accountID, id uuid.UUID, code int, body string,
) error

SetWebhookEventDelivered records a 2xx outcome.

func (WebhooksRepo) SetWebhookEventExhausted

func (r WebhooksRepo) SetWebhookEventExhausted(ctx context.Context, accountID, id uuid.UUID) error

SetWebhookEventExhausted marks a relay budget exhausted without inventing an HTTP response or an extra delivery attempt.

func (WebhooksRepo) SetWebhookEventFailure

func (r WebhooksRepo) SetWebhookEventFailure(
	ctx context.Context, accountID, id uuid.UUID, status domain.WebhookEventStatus,
	code *int, body string,
) error

SetWebhookEventFailure records a non-2xx or transport outcome.

func (WebhooksRepo) SubscribedWebhookEndpoints

func (r WebhooksRepo) SubscribedWebhookEndpoints(
	ctx context.Context, accountID uuid.UUID, event string,
) ([]domain.WebhookEndpoint, error)

SubscribedWebhookEndpoints answers the endpoints an event goes to (the publisher's fan-out candidates).

func (WebhooksRepo) UpdateWebhookEndpoint

func (r WebhooksRepo) UpdateWebhookEndpoint(ctx context.Context, e domain.WebhookEndpoint) error

UpdateWebhookEndpoint writes every mutable column.

func (WebhooksRepo) WebhookEndpointByID

func (r WebhooksRepo) WebhookEndpointByID(
	ctx context.Context, accountID, id uuid.UUID,
) (domain.WebhookEndpoint, error)

WebhookEndpointByID loads an endpoint by id.

func (WebhooksRepo) WebhookEndpointByURL

func (r WebhooksRepo) WebhookEndpointByURL(
	ctx context.Context, accountID uuid.UUID, url string,
) (domain.WebhookEndpoint, error)

WebhookEndpointByURL loads the first endpoint with the URL (the retry action's fallback when the event's endpoint row is gone).

func (WebhooksRepo) WebhookEndpointProduct

func (r WebhooksRepo) WebhookEndpointProduct(
	ctx context.Context, accountID, id uuid.UUID,
) (uuid.NullUUID, error)

WebhookEndpointProduct answers the endpoint's product (the product bearer's read scope); false when the endpoint row is gone.

func (WebhooksRepo) WebhookEventByID

func (r WebhooksRepo) WebhookEventByID(
	ctx context.Context, accountID, id uuid.UUID,
) (domain.WebhookEvent, error)

WebhookEventByID loads an event by id.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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