Documentation
¶
Overview ¶
Package catalog is the composition layer: it pulls the entity stores together into an atomic in-memory Snapshot the request path can read in O(1). Snapshots are immutable; Reload rebuilds and atomically swaps.
Membership rule (single, simple): every enabled row of every kind enters the snapshot. There is no reachability filter — a Model not bound to any Policy still appears (it's just unreachable through PoolModels until someone wires it up). The "enabled" flag is the entire toggle mechanism.
Reverse joins (pricingByModelHost, bindingsByModel, etc.) are derived indices over the snapshot — they hold pointers to the same rows.
Index ¶
- Constants
- Variables
- func AliasUpstream(ref *AliasRef, raw string) (via, upstream string)
- func Bootstrap(ctx context.Context, opts BootstrapOptions) (*Catalog, *Listener, *Stores, error)
- func BootstrapStores(ctx context.Context, opts BootstrapOptions) (*Catalog, *Stores, error)
- func ModelDeprecated(m *model.Model) bool
- func PruneDetached(ctx context.Context, stores *Stores, opts BootstrapOptions, idle time.Duration, ...) (catalogprune.Report, error)
- func RefsGrant(refs []modelref.Ref, providerSlug, modelSlug, hostSlug string, ...) bool
- func UserSubjects(userID string, localGroups, idpGroups []string) []string
- type AliasRef
- type BindingLister
- type BootstrapOptions
- type Catalog
- func (c *Catalog) ApplyGroupDelete(id string) error
- func (c *Catalog) ApplyGroupUpsert(g *group.Group) error
- func (c *Catalog) ApplyHostDelete(id string) error
- func (c *Catalog) ApplyHostKeyDelete(id string) error
- func (c *Catalog) ApplyHostKeyUpsert(k *hostkey.HostKey) error
- func (c *Catalog) ApplyHostUpsert(h *host.Host) error
- func (c *Catalog) ApplyKeyDelete(id string) error
- func (c *Catalog) ApplyKeyUpsert(k *key.Key) error
- func (c *Catalog) ApplyModelDelete(id string) error
- func (c *Catalog) ApplyModelUpsert(m *model.Model) error
- func (c *Catalog) ApplyOverlayDelete(kind, resourceID string) error
- func (c *Catalog) ApplyOverlayUpsert(o *overlay.Overlay) error
- func (c *Catalog) ApplyPolicyBindingDelete(id string) error
- func (c *Catalog) ApplyPolicyBindingUpsert(b *policybinding.PolicyBinding) error
- func (c *Catalog) ApplyPolicyDelete(id string) error
- func (c *Catalog) ApplyPolicyUpsert(p *policy.Policy) error
- func (c *Catalog) ApplyPricingDelete(id string) error
- func (c *Catalog) ApplyPricingUpsert(p *pricing.Pricing) error
- func (c *Catalog) ApplyProjectDelete(id string) error
- func (c *Catalog) ApplyProjectUpsert(p *project.Project) error
- func (c *Catalog) ApplyProviderDelete(id string) error
- func (c *Catalog) ApplyProviderUpsert(p *provider.Provider) error
- func (c *Catalog) ApplyRateLimitDelete(id string) error
- func (c *Catalog) ApplyRateLimitUpsert(r *ratelimit.RateLimit) error
- func (c *Catalog) ApplyRoleBindingDelete(id string) error
- func (c *Catalog) ApplyRoleBindingUpsert(b *rolebinding.RoleBinding) error
- func (c *Catalog) ApplyRoleDelete(id string) error
- func (c *Catalog) ApplyRoleUpsert(r *role.Role) error
- func (c *Catalog) ApplyServiceAccountDelete(id string) error
- func (c *Catalog) ApplyServiceAccountUpsert(sa *serviceaccount.ServiceAccount) error
- func (c *Catalog) ApplyTeamDelete(id string) error
- func (c *Catalog) ApplyTeamUpsert(t *team.Team) error
- func (c *Catalog) Current() *Snapshot
- func (c *Catalog) ForwardEvents(f EventForwarder)
- func (c *Catalog) Hydrate(ctx context.Context, stores *Stores, opts BootstrapOptions) (*Listener, error)
- func (c *Catalog) IsReady() bool
- func (c *Catalog) OnSettingsChange(section string, fn func())
- func (c *Catalog) Reload(ctx context.Context) error
- func (c *Catalog) ReloadTokenVersions(ctx context.Context) error
- func (c *Catalog) Setting(section string) (any, bool)
- func (c *Catalog) UseClock(now func() time.Time)
- func (c *Catalog) UseOverlays(l OverlayLister)
- func (c *Catalog) UseTenancy(t TeamLister, p ProjectLister, sa ServiceAccountLister, g GroupLister, ...)
- func (c *Catalog) UseTokenVersions(l TokenVersionLister)
- type CheckResult
- type EventForwarder
- type Follower
- type GroupLister
- type HostKeyLister
- type HostLister
- type KeyLister
- type Listener
- type ModelLister
- type OverlayLister
- type PolicyBindingLister
- type PolicyLister
- type PricingLister
- type ProjectLister
- type ProviderLister
- type PruneOptions
- type RateLimitLister
- type ResolvedRef
- type RoleBindingLister
- type RoleLister
- type ServiceAccountLister
- type SettingsLister
- type Snapshot
- func (s *Snapshot) AllBindings() []*binding.Binding
- func (s *Snapshot) AllGroups() []*group.Group
- func (s *Snapshot) AllHostKeys() []*hostkey.HostKey
- func (s *Snapshot) AllKeys() []*key.Key
- func (s *Snapshot) AllModels() []*model.Model
- func (s *Snapshot) AllPolicies() []*policy.Policy
- func (s *Snapshot) AllPolicyBindings() []*policybinding.PolicyBinding
- func (s *Snapshot) AllPricings() []*pricing.Pricing
- func (s *Snapshot) AllProjects() []*project.Project
- func (s *Snapshot) AllProviders() []*provider.Provider
- func (s *Snapshot) AllRateLimits() []*ratelimit.RateLimit
- func (s *Snapshot) AllRoleBindings() []*rolebinding.RoleBinding
- func (s *Snapshot) AllRoles() []*role.Role
- func (s *Snapshot) AllServiceAccounts() []*serviceaccount.ServiceAccount
- func (s *Snapshot) AllTeams() []*team.Team
- func (s *Snapshot) Binding(id string) (*binding.Binding, bool)
- func (s *Snapshot) BindingForModelHost(modelID, hostID string) (*binding.Binding, bool)
- func (s *Snapshot) BindingsForModel(modelID string) []*binding.Binding
- func (s *Snapshot) Dependents(kind refKind, id string) []refKey
- func (s *Snapshot) DisabledPolicy(id string) (*policy.Policy, bool)
- func (s *Snapshot) EnabledHosts() []*host.Host
- func (s *Snapshot) EnabledModels() []*model.Model
- func (s *Snapshot) Generation() uint64
- func (s *Snapshot) Group(id string) (*group.Group, bool)
- func (s *Snapshot) GroupByName(name string) (*group.Group, bool)
- func (s *Snapshot) GroupsForUser(userID string) []string
- func (s *Snapshot) Host(id string) (*host.Host, bool)
- func (s *Snapshot) HostByName(name string) (*host.Host, bool)
- func (s *Snapshot) HostKey(id string) (*hostkey.HostKey, bool)
- func (s *Snapshot) HostKeysForHost(hostID string) []*hostkey.HostKey
- func (s *Snapshot) HostSlug(hostID string) (string, bool)
- func (s *Snapshot) Hosts() []*host.Host
- func (s *Snapshot) Key(id string) (*key.Key, bool)
- func (s *Snapshot) KeyByHash(hash string) (k *key.Key, matchedPrevious bool)
- func (s *Snapshot) KeyHashesForUser(userID string) []string
- func (s *Snapshot) Model(id string) (*model.Model, bool)
- func (s *Snapshot) ModelsByName(name string) []*model.Model
- func (s *Snapshot) ModelsByProvider(providerID string) []*model.Model
- func (s *Snapshot) Policy(id string) (*policy.Policy, bool)
- func (s *Snapshot) PolicyBinding(id string) (*policybinding.PolicyBinding, bool)
- func (s *Snapshot) PolicyBindingsForProject(projectID string) []*policybinding.PolicyBinding
- func (s *Snapshot) PolicyByName(name string) (*policy.Policy, bool)
- func (s *Snapshot) PriceByModelHost(modelID, hostID string) (*pricing.Pricing, bool)
- func (s *Snapshot) Pricing(id string) (*pricing.Pricing, bool)
- func (s *Snapshot) PricingForBinding(b *binding.Binding) (*pricing.Pricing, bool)
- func (s *Snapshot) Project(id string) (*project.Project, bool)
- func (s *Snapshot) ProjectByName(name string) (*project.Project, bool)
- func (s *Snapshot) ProjectsInTeam(teamID string) []*project.Project
- func (s *Snapshot) Provider(id string) (*provider.Provider, bool)
- func (s *Snapshot) ProviderByName(name string) (*provider.Provider, bool)
- func (s *Snapshot) ProviderSlug(providerID string) (string, bool)
- func (s *Snapshot) RateLimit(id string) (*ratelimit.RateLimit, bool)
- func (s *Snapshot) ResolveAlias(key string, patterns bool) (AliasRef, bool)
- func (s *Snapshot) ResolveModelRef(name string) ResolvedRef
- func (s *Snapshot) ResolveSnapshot(key string) (*model.Model, *model.Snapshot, string, bool)
- func (s *Snapshot) Role(id string) (*role.Role, bool)
- func (s *Snapshot) RoleBinding(id string) (*rolebinding.RoleBinding, bool)
- func (s *Snapshot) RoleBindingsForSubject(subject string) []*rolebinding.RoleBinding
- func (s *Snapshot) RoleByName(name string) (*role.Role, bool)
- func (s *Snapshot) ScopeChain(o *meta.Owner) []meta.Owner
- func (s *Snapshot) ScopeChainFor(kind, id string, o *meta.Owner) []meta.Owner
- func (s *Snapshot) ServiceAccount(id string) (*serviceaccount.ServiceAccount, bool)
- func (s *Snapshot) ServiceAccountByName(name string) (*serviceaccount.ServiceAccount, bool)
- func (s *Snapshot) ServiceAccountsForProject(projectID string) []*serviceaccount.ServiceAccount
- func (s *Snapshot) SnapshotByName(name string) (*model.Model, *model.Snapshot, bool)
- func (s *Snapshot) SubjectsForKey(keyID string) []string
- func (s *Snapshot) SubjectsForServiceAccount(id string) []string
- func (s *Snapshot) SystemRateLimitByName(name string) (*ratelimit.RateLimit, bool)
- func (s *Snapshot) Team(id string) (*team.Team, bool)
- func (s *Snapshot) TeamByName(name string) (*team.Team, bool)
- func (s *Snapshot) TokenVersion(userID string) (int, bool)
- func (s *Snapshot) UserDisabled(userID string) bool
- func (s *Snapshot) UserEnabled(userID string) bool
- type Stores
- type TeamLister
- type TokenVersionLister
Constants ¶
const ( SubjectAuthenticated = "group:system:authenticated" SubjectServiceAccounts = "group:system:serviceaccounts" )
System group subjects every data-plane principal carries. They are not Group rows — an operator binds a role to them without maintaining membership.
const DefaultPruneIdle = 30 * 24 * time.Hour
DefaultPruneIdle is how long a detached model or host binding must have served no request before a prune deletes it.
Variables ¶
var ErrSeedBusy = errors.New("catalog: another relay is seeding the catalog")
ErrSeedBusy reports a check skipped because another relay holds the seed lock.
Functions ¶
func AliasUpstream ¶ added in v0.20.0
AliasUpstream returns the usage tag and the wire model name an alias match imposes: an exact alias sends its declared string, a pattern sends the caller's raw string. Both are empty when ref is nil.
func Bootstrap ¶
Bootstrap is the legacy one-shot: stores + Hydrate in a single call. Kept for tests and any caller that doesn't need split-boot semantics. Returns the same triple as before plus the listener primed for Run.
func BootstrapStores ¶
BootstrapStores wires the eight entity stores against the pool and constructs a Catalog. Does NOT touch row data — no seed, no Reload. Use when the control plane needs the stores but data-plane readiness is deferred (see (*Catalog).Hydrate). Cheap and rarely fails.
func ModelDeprecated ¶ added in v0.20.0
ModelDeprecated reports whether m is deprecated or sunset, which hides it from wildcard grants.
func PruneDetached ¶ added in v0.21.0
func PruneDetached(ctx context.Context, stores *Stores, opts BootstrapOptions, idle time.Duration, apply bool) (catalogprune.Report, error)
PruneDetached judges every detached catalog row and, with apply, deletes the ones nothing holds, under the seed lock so no reseed runs meanwhile; it answers ErrSeedBusy when another relay holds that lock. idle 0 uses the configured window.
func RefsGrant ¶ added in v0.20.0
func RefsGrant(refs []modelref.Ref, providerSlug, modelSlug, hostSlug string, hideDeprecated bool) bool
RefsGrant reports whether any ref grants (provider, model, host) under the policy grant rules: with hideDeprecated, a wildcard-model match does not grant, while a ref naming the model still does.
func UserSubjects ¶ added in v0.10.0
UserSubjects renders a user's subjects from their local group names and any groups an identity provider asserted. The union is deduplicated and sorted so two callers with the same membership produce the same list. Tokens build theirs per request (a token's claims are its own source); keys read the precomputed list off the snapshot.
Types ¶
type AliasRef ¶ added in v0.3.0
type AliasRef struct {
Model *model.Model
Snapshot *model.Snapshot
// HostID is non-empty only when the matched form carried an "@host"
// pin (synthesized for exact aliases the same way snapshotAliases
// pins are).
HostID string
// Name is the alias exactly as declared on the model. For exact
// aliases this is the verbatim upstream wire name; for patterns it
// identifies the matcher (usage tagging).
Name string
// Pattern marks a wildcard match — the upstream wire name is the
// caller's raw request string, not Name.
Pattern bool
}
AliasRef is a declared-alias match: the owning Model and the Pointer snapshot the alias resolves to. Declared aliases are resolution-only, last-priority lookup keys (see model.Spec.Aliases) — routing consults them only after ResolveSnapshot misses, so real catalog names always shadow them.
type BindingLister ¶
type BootstrapOptions ¶
type BootstrapOptions struct {
Pool *pgxpool.Pool
MasterKey []byte
// MasterKeyExtra are further KEKs (RELAY_MASTER_KEY_EXTRA), held during a
// KEK change; which KEK wraps new data keys is recorded in the database.
MasterKeyExtra [][]byte
// AutoSeedDir, when non-empty AND the catalog is empty in PG, triggers
// a YAML import from this directory before the initial Reload. The
// expected layout matches wyolet/relay-catalog's data/ tree (providers/
// <provider>/{provider.yaml,models/}, hosts/<host>/{host.yaml,pricing/,
// policies/}). filepath.WalkDir walks the tree; dispatch is by the
// kind field in each YAML doc, so the nested layout is transparent.
// Idempotent: if any catalog row already exists, seeding is skipped.
AutoSeedDir string
// CatalogVersion, when non-empty, pins the seeded catalog to a
// published relay-catalog ref (tag), or — as "latest"/"auto" —
// resolves the newest release for this binary's schema channel via
// the channel index (CatalogIndexURL) at every hydrate. Once
// concrete, the stored "catalog-source" marker is compared against
// it; on mismatch (or an empty catalog) the tree is seeded, unless the
// marker names a newer release (see AllowDowngrade) — from
// AutoSeedDir when its .version stamp matches (no network), else
// fetched from CatalogURL — and the marker updated. The seed is
// layering-safe: operator-edited (dirty) rows are skipped and
// overlays re-merge at snapshot load. A resolve, fetch or seed failure
// against a non-empty catalog logs and continues with the existing
// rows (never blocks boot); against an empty catalog it falls back to
// AutoSeedDir when set, else fails hydrate (retried by the caller).
CatalogVersion string
// CatalogURL overrides the archive URL template used by
// CatalogVersion fetches ("{version}" substituted). Empty uses
// seed.DefaultCatalogURLTemplate. The archive must have its sha256sum
// file at the same URL plus ".sha256". Point it at a mirror for
// airgapped deployments.
CatalogURL string
// CatalogIndexURL overrides where "latest"/"auto" resolves the
// channel index from. Empty uses seed.DefaultCatalogIndexURL.
CatalogIndexURL string
// SeedLock serializes the seed decision and the seed itself across every
// pod sharing the database, so pods booting together against an empty
// catalog seed it once. Nil runs unserialized: safe for one process only.
SeedLock func(ctx context.Context, fn func(context.Context) error) error
// SeedTryLock is SeedLock for a seed that skips when another pod holds the
// lock, reporting whether fn ran. The follower uses it; nil runs fn.
SeedTryLock func(ctx context.Context, fn func(context.Context) error) (bool, error)
// AllowDowngrade lets the boot seed replace a catalog seeded from a newer
// release than CatalogVersion resolves to. The follower never downgrades.
AllowDowngrade bool
// SystemRateLimits are the system-owned rate limits the binary looks up by name. Every hydrate creates the ones with no row and leaves existing rows alone.
SystemRateLimits []*ratelimit.RateLimit
// Prune deletes the detached rows nothing holds: with Prune.Auto after
// every versioned reseed and on a follower's checks, and on demand
// through PruneDetached.
Prune PruneOptions
}
BootstrapOptions configures the one-call Bootstrap helper. Pool is required; MasterKey may be nil if stored-mode HostKeys aren't in use.
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog is the long-lived composition object. Holds the entity stores and the current Snapshot pointer. Construct one per process; call Reload at boot and whenever PG state changes (admin write, NOTIFY watcher).
func New ¶
func New( providers ProviderLister, hosts HostLister, policies PolicyLister, models ModelLister, hostKeys HostKeyLister, rateLimits RateLimitLister, keys KeyLister, pricings PricingLister, bindings BindingLister, ) *Catalog
New constructs a Catalog backed by the supplied stores. Initial Snapshot is empty; call Reload before serving traffic.
func (*Catalog) ApplyGroupDelete ¶ added in v0.10.0
func (*Catalog) ApplyGroupUpsert ¶ added in v0.10.0
func (*Catalog) ApplyHostDelete ¶
func (*Catalog) ApplyHostKeyDelete ¶
func (*Catalog) ApplyKeyDelete ¶ added in v0.10.0
func (*Catalog) ApplyKeyUpsert ¶ added in v0.10.0
func (*Catalog) ApplyModelDelete ¶
func (*Catalog) ApplyOverlayDelete ¶ added in v0.3.0
ApplyOverlayDelete removes an overlay and restores the target's pristine template (factory reset).
func (*Catalog) ApplyOverlayUpsert ¶ added in v0.3.0
ApplyOverlayUpsert installs (or replaces) an overlay and re-derives the target's effective row. An overlay whose target isn't in the snapshot is registered inert — it merges when the target appears.
func (*Catalog) ApplyPolicyBindingDelete ¶ added in v0.10.0
func (*Catalog) ApplyPolicyBindingUpsert ¶ added in v0.10.0
func (c *Catalog) ApplyPolicyBindingUpsert(b *policybinding.PolicyBinding) error
A policy binding names a project, subjects and a policy — none of which the allowed-combo sets are a function of — so these two publish directly instead of rebuilding every policy's grants.
func (*Catalog) ApplyPolicyDelete ¶
func (*Catalog) ApplyPricingDelete ¶
func (*Catalog) ApplyProjectDelete ¶ added in v0.10.0
func (*Catalog) ApplyProjectUpsert ¶ added in v0.10.0
func (*Catalog) ApplyProviderDelete ¶
func (*Catalog) ApplyProviderUpsert ¶
func (*Catalog) ApplyRateLimitDelete ¶
func (*Catalog) ApplyRateLimitUpsert ¶
func (*Catalog) ApplyRoleBindingDelete ¶ added in v0.10.0
func (*Catalog) ApplyRoleBindingUpsert ¶ added in v0.10.0
func (c *Catalog) ApplyRoleBindingUpsert(b *rolebinding.RoleBinding) error
func (*Catalog) ApplyRoleDelete ¶ added in v0.10.0
func (*Catalog) ApplyRoleUpsert ¶ added in v0.10.0
func (*Catalog) ApplyServiceAccountDelete ¶ added in v0.10.0
func (*Catalog) ApplyServiceAccountUpsert ¶ added in v0.10.0
func (c *Catalog) ApplyServiceAccountUpsert(sa *serviceaccount.ServiceAccount) error
func (*Catalog) ApplyTeamDelete ¶ added in v0.10.0
func (*Catalog) ApplyTeamUpsert ¶ added in v0.10.0
func (*Catalog) Current ¶
Current returns the live Snapshot. Safe to call from any goroutine; the returned pointer is immutable until the next successful Reload.
func (*Catalog) ForwardEvents ¶ added in v0.20.0
func (c *Catalog) ForwardEvents(f EventForwarder)
ForwardEvents hands every notification the listener receives to f. Call before Hydrate.
func (*Catalog) Hydrate ¶
func (c *Catalog) Hydrate(ctx context.Context, stores *Stores, opts BootstrapOptions) (*Listener, error)
Hydrate is the expensive half of bootstrap: reload settings, optionally auto-seed from YAML, run the first catalog Reload, and construct a NOTIFY listener primed for Run. On any error the Catalog's IsReady stays false and the caller can retry — handlers gate on it and return 503 in the meantime.
func (*Catalog) IsReady ¶
IsReady reports whether the catalog has built its first snapshot successfully. Until then, the in-memory snapshot is the zero-value returned by New — empty maps that look identical to a legitimately empty catalog. The inference plane uses this to refuse traffic with 503 instead of silently serving "no models found" lookups.
func (*Catalog) OnSettingsChange ¶
OnSettingsChange registers fn to run whenever section's value changes (upsert or delete), after the new value is visible to Setting. fn runs synchronously on the NOTIFY listener goroutine, which applies catalog events serially — so fn MUST be cheap and non-blocking. A consumer with heavy work (sink rebuild, network I/O) should have fn do a non-blocking signal and perform the work on its own goroutine. Subscriptions are process-lifetime; there is no unsubscribe.
func (*Catalog) Reload ¶
Reload reads every store, filters to enabled rows, runs cross-entity validation, builds a fresh Snapshot, and atomic-swaps it in. On any error the existing Snapshot stays live — callers can retry.
func (*Catalog) ReloadTokenVersions ¶ added in v0.10.0
ReloadTokenVersions rebuilds only the token-version map and the disabled set — the whole snapshot reaction to a users write.
func (*Catalog) Setting ¶
Setting returns the typed value for section, falling back to the section's Defaults() when no row has been seen yet. ok=false means the section name is not registered.
func (*Catalog) UseClock ¶ added in v0.10.0
UseClock replaces the wall clock every snapshot reads. Called once at composition time, before the first Reload.
func (*Catalog) UseOverlays ¶ added in v0.3.0
func (c *Catalog) UseOverlays(l OverlayLister)
UseOverlays attaches the overlay source. Called once at composition time before the first Reload; nil (the default) keeps overlays dormant.
func (*Catalog) UseTenancy ¶ added in v0.10.0
func (c *Catalog) UseTenancy(t TeamLister, p ProjectLister, sa ServiceAccountLister, g GroupLister, r RoleLister, rb RoleBindingLister, pb PolicyBindingLister)
UseTenancy attaches the Team, Project, ServiceAccount, Group, Role, RoleBinding and PolicyBinding sources. Called once at composition time before the first Reload; nil (the default) keeps tenancy dormant.
func (*Catalog) UseTokenVersions ¶ added in v0.10.0
func (c *Catalog) UseTokenVersions(l TokenVersionLister)
UseTokenVersions attaches the per-user token-version source. Called once at composition time before the first Reload; nil keeps every version absent, which makes verification reject tokens.
type CheckResult ¶ added in v0.20.1
type CheckResult struct {
Previous string
Current string
Changed bool
Pruned *settings.CatalogPrune
}
CheckResult is the catalog-source version before and after one check, and what the prune the check ran did (nil when none ran).
type EventForwarder ¶ added in v0.20.0
type EventForwarder interface {
// Event is one parsed notification, before debouncing.
Event(kind, op, id string)
// Attached runs each time the listener (re)attaches: notifications sent while it was detached were lost.
Attached(ctx context.Context)
}
EventForwarder receives the catalog NOTIFY feed as it arrives, so a second consumer of the same rows stays current without a LISTEN of its own.
type Follower ¶ added in v0.20.1
type Follower struct {
// contains filtered or unexported fields
}
Follower re-checks the channel index on a timer, on Nudge, and on Check.
func NewFollower ¶ added in v0.20.1
func NewFollower(stores *Stores, opts BootstrapOptions) *Follower
NewFollower checks against opts' index and archive URLs and seeds under opts.SeedTryLock. opts.AllowDowngrade is ignored: a follower never seeds an older release.
func (*Follower) Check ¶ added in v0.20.1
func (f *Follower) Check(ctx context.Context) (CheckResult, error)
Check reads the channel index and seeds its latest release when that is newer than the seeded one. A failure keeps the seeded catalog and is recorded in the catalog-source section; the index validator is kept only after a check that settled, so a failed release is retried in full.
func (*Follower) Nudge ¶ added in v0.20.1
Nudge asks Run for a check without waiting for it; a nudge while one is already pending folds into it. tag is the release the nudge announced. It never decides what is seeded: when the check's index doesn't list it yet, Run checks once more after a delay.
type GroupLister ¶ added in v0.10.0
type HostKeyLister ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener subscribes to catalog_events NOTIFY, debounces the payload stream, and applies incremental updates to the Catalog.
func NewListener ¶
NewListener constructs a Listener. Call Run to start it.
type OverlayLister ¶ added in v0.3.0
type PolicyBindingLister ¶ added in v0.10.0
type PolicyBindingLister interface {
List(ctx context.Context) ([]*policybinding.PolicyBinding, error)
}
type PolicyLister ¶
type PricingLister ¶
type ProjectLister ¶ added in v0.10.0
type ProviderLister ¶
type PruneOptions ¶ added in v0.21.0
type PruneOptions struct {
// Auto prunes after every versioned reseed and on a follower's checks.
Auto bool
// Idle is the traffic window; 0 uses DefaultPruneIdle.
Idle time.Duration
// References lists the rows referencing a catalog row (an API singular
// kind) as the control API's delete sees them. Nil fails every prune.
References func(ctx context.Context, stores *Stores, kind, id string) ([]catalogprune.Ref, error)
// Usage answers the traffic guard; nil keeps every detached model and
// host binding.
Usage catalogprune.UsageReader
// UsageReady reports whether Usage can answer yet; the follower's prune
// between releases waits for it. Nil counts a set Usage as ready.
UsageReady func() bool
}
PruneOptions configures the prune of detached catalog rows.
type RateLimitLister ¶
type ResolvedRef ¶ added in v0.20.0
type ResolvedRef struct {
Models []*model.Model
Snapshot *model.Snapshot
// PinHostID is set when the ref named a host ("model@host"); binding selection is then limited to it.
PinHostID string
// Alias is the declared alias that matched, nil for a real catalog name.
Alias *AliasRef
}
ResolvedRef is a caller's model ref resolved against the snapshot's name and alias indices.
type RoleBindingLister ¶ added in v0.10.0
type RoleBindingLister interface {
List(ctx context.Context) ([]*rolebinding.RoleBinding, error)
}
type RoleLister ¶ added in v0.10.0
type ServiceAccountLister ¶ added in v0.10.0
type ServiceAccountLister interface {
List(ctx context.Context) ([]*serviceaccount.ServiceAccount, error)
}
type SettingsLister ¶
type SettingsLister interface {
List(ctx context.Context) ([]*settings.Row, error)
Get(ctx context.Context, section string) (*settings.Row, error)
}
SettingsLister is the narrow read interface the catalog needs to bootstrap and refresh the settings cache. *settings.Store satisfies it.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is the immutable in-memory view. All maps are populated at construction and never written after — read accessors are safe to call from any goroutine.
func Build ¶
func Build( provs []*provider.Provider, hosts []*host.Host, pols []*policy.Policy, rks []*key.Key, models []*model.Model, keys []*hostkey.HostKey, rls []*ratelimit.RateLimit, pricings []*pricing.Pricing, bindings []*binding.Binding, ) *Snapshot
Build assembles a Snapshot from entity slices using the same sanitize rules as Reload. Used by tests; callers supply only the kinds they need — pass nil/empty slices for the rest.
func BuildCatalog ¶ added in v0.20.0
func BuildCatalog(provs []*provider.Provider, hosts []*host.Host, models []*model.Model, pricings []*pricing.Pricing, bindings []*binding.Binding, ovls []*overlay.Overlay) *Snapshot
BuildCatalog assembles a Snapshot of the catalog kinds alone (providers, hosts, models, pricings, bindings, with overlays merged), for callers that resolve model refs without the tenancy, key or policy rows.
func (*Snapshot) AllBindings ¶
AllBindings returns every binding in the snapshot, sorted by name.
func (*Snapshot) AllGroups ¶ added in v0.10.0
AllGroups returns every Group in the snapshot, sorted by slug.
func (*Snapshot) AllHostKeys ¶
AllHostKeys returns every HostKey in the snapshot, sorted by slug.
func (*Snapshot) AllKeys ¶ added in v0.10.0
AllKeys returns every Key in the snapshot, sorted by slug.
func (*Snapshot) AllModels ¶
AllModels returns every enabled Model in stable slug order. Used by the /catalog/resolve endpoint for host-only refs ("@bedrock") that need to walk the entire catalog rather than a single provider.
func (*Snapshot) AllPolicies ¶
AllPolicies returns every Policy in the snapshot, sorted by slug.
func (*Snapshot) AllPolicyBindings ¶ added in v0.10.0
func (s *Snapshot) AllPolicyBindings() []*policybinding.PolicyBinding
AllPolicyBindings returns every PolicyBinding in the snapshot, sorted by slug.
func (*Snapshot) AllPricings ¶
AllPricings returns every Pricing in the snapshot, sorted by slug.
func (*Snapshot) AllProjects ¶ added in v0.10.0
AllProjects returns every Project in the snapshot, sorted by slug.
func (*Snapshot) AllProviders ¶
AllProviders returns every Provider in the snapshot, sorted by slug.
func (*Snapshot) AllRateLimits ¶
AllRateLimits returns every RateLimit in the snapshot, sorted by slug.
func (*Snapshot) AllRoleBindings ¶ added in v0.10.0
func (s *Snapshot) AllRoleBindings() []*rolebinding.RoleBinding
AllRoleBindings returns every RoleBinding in the snapshot, sorted by slug.
func (*Snapshot) AllRoles ¶ added in v0.10.0
AllRoles returns every Role in the snapshot, sorted by slug.
func (*Snapshot) AllServiceAccounts ¶ added in v0.10.0
func (s *Snapshot) AllServiceAccounts() []*serviceaccount.ServiceAccount
AllServiceAccounts returns every ServiceAccount in the snapshot, sorted by slug.
func (*Snapshot) AllTeams ¶ added in v0.10.0
AllTeams returns every Team in the snapshot, sorted by slug.
func (*Snapshot) BindingForModelHost ¶
BindingForModelHost returns the binding for (modelID, hostID), or false. O(1) — the routing hot-path lookup.
func (*Snapshot) BindingsForModel ¶
BindingsForModel returns the bindings declared for a model, sorted by binding name. The returned slice must not be mutated.
func (*Snapshot) Dependents ¶
Dependents returns every refKey that depends on (kind, id). nil if none. The slice is freshly allocated; mutating it doesn't affect the snapshot.
func (*Snapshot) DisabledPolicy ¶ added in v0.10.0
DisabledPolicy returns the Policy with this id when it is present but switched off. Resolution calls it after Policy misses, so a credential pointing at a disabled policy answers 403 policy_disabled rather than silently resolving to something broader.
func (*Snapshot) EnabledHosts ¶
EnabledHosts returns enabled hosts sorted by Meta.Name.
func (*Snapshot) EnabledModels ¶
EnabledModels returns enabled models sorted by Meta.Name.
func (*Snapshot) Generation ¶ added in v0.10.0
Generation identifies this snapshot. Two snapshots are the same view if and only if their generations match.
func (*Snapshot) GroupByName ¶ added in v0.10.0
GroupByName returns the enabled Group with this slug, or false.
func (*Snapshot) GroupsForUser ¶ added in v0.10.0
GroupsForUser returns the names of the groups holding this user, sorted. The returned slice must not be mutated.
func (*Snapshot) HostByName ¶
HostByName returns the enabled Host with this slug, or false.
func (*Snapshot) HostKeysForHost ¶
HostKeysForHost returns every enabled HostKey whose Spec.HostID matches hostID. Order is by hostkey slug — stable across snapshots. Used by routing's policy-less flow (settings.Inference.AllowMissingPolicy) where the policy doesn't narrow the pool. The returned slice is the snapshot's own: callers must not mutate or append to it.
func (*Snapshot) Hosts ¶
Hosts returns all enabled Host rows. Stable order by slug. Used by the /v1/proxy/hosts list endpoint.
func (*Snapshot) KeyByHash ¶ added in v0.10.0
KeyByHash is the hot-path inbound-auth lookup. matchedPrevious is true when the hash matched the pre-rotation credential, which the caller must then check against the grace window. Caller checks IsActive.
func (*Snapshot) KeyHashesForUser ¶ added in v0.10.0
KeyHashesForUser returns the hashes every Key of this user authenticates under, the pre-rotation one included. Read from the principal index, so it costs the user's own keys rather than a walk of the deployment's.
func (*Snapshot) ModelsByName ¶
ModelsByName returns every enabled Model whose Meta.Name matches. The slug is unique per kind, but the index is multivalued to absorb transient overlap during reload. Customer-facing addressing uses SnapshotByName instead — this accessor is admin-only.
func (*Snapshot) ModelsByProvider ¶
ModelsByProvider returns every enabled Model whose owning Provider matches providerID. Stable order by slug. Used by the /catalog/resolve admin endpoint to enumerate a provider's catalog.
func (*Snapshot) PolicyBinding ¶ added in v0.10.0
func (s *Snapshot) PolicyBinding(id string) (*policybinding.PolicyBinding, bool)
PolicyBinding returns the enabled PolicyBinding with this id, or false.
func (*Snapshot) PolicyBindingsForProject ¶ added in v0.10.0
func (s *Snapshot) PolicyBindingsForProject(projectID string) []*policybinding.PolicyBinding
PolicyBindingsForProject returns the project's policy bindings, ordered by effective priority then name. The returned slice must not be mutated.
func (*Snapshot) PolicyByName ¶
PolicyByName returns the enabled Policy with this slug, or false.
func (*Snapshot) PriceByModelHost ¶
PriceByModelHost returns the Pricing that covers (modelID, hostID), or false.
func (*Snapshot) PricingForBinding ¶ added in v0.3.0
PricingForBinding resolves the rate sheet billing against a binding: the binding's explicit Spec.PricingID first, else the host-owned pricing covering the (model, host) pair. Mirrors catalogview's resolution so the admin read-projection and the emit-time cost stamp agree.
func (*Snapshot) Project ¶ added in v0.10.0
Project returns the enabled Project with this id, or false.
func (*Snapshot) ProjectByName ¶ added in v0.10.0
ProjectByName returns the enabled Project with this slug, or false.
func (*Snapshot) ProjectsInTeam ¶ added in v0.10.0
ProjectsInTeam returns the team's projects, sorted by project name. The returned slice must not be mutated.
func (*Snapshot) ProviderByName ¶
ProviderByName returns the enabled Provider with this slug, or false.
func (*Snapshot) ProviderSlug ¶
ProviderSlug returns the Provider.Meta.Name for the given Provider id, or false. Hot-path resolution uses this to compare a Model's owning Provider against the suffix/header hint without needing the full Provider row.
func (*Snapshot) ResolveAlias ¶ added in v0.3.0
ResolveAlias maps a slug-normalized ref to a declared model alias: exact map probe first, then — when patterns is true — the wildcard list in longest-prefix order. Routing calls this only on ResolveSnapshot miss (exact catalog names always win) and passes patterns=false for refs that carry an "@host" pin, because the pin segment is glued into the normalized key and would corrupt a wildcard match.
func (*Snapshot) ResolveModelRef ¶ added in v0.20.0
func (s *Snapshot) ResolveModelRef(name string) ResolvedRef
ResolveModelRef maps a caller-supplied model ref to its snapshot: the slug-normalised name first, declared aliases only after every real name missed. Wildcard alias patterns are skipped for refs carrying an "@host" pin, whose pin segment would corrupt the match.
func (*Snapshot) ResolveSnapshot ¶
ResolveSnapshot maps a slug-normalized model ref to its model + snapshot, plus an optional pinned HostID (set when the ref named a host via "@host"). Bare snapshot names win over synthesized aliases. The caller normalizes the key with slug.From.
func (*Snapshot) RoleBinding ¶ added in v0.10.0
func (s *Snapshot) RoleBinding(id string) (*rolebinding.RoleBinding, bool)
RoleBinding returns the enabled RoleBinding with this id, or false.
func (*Snapshot) RoleBindingsForSubject ¶ added in v0.10.0
func (s *Snapshot) RoleBindingsForSubject(subject string) []*rolebinding.RoleBinding
RoleBindingsForSubject returns the bindings naming this subject ("user:<id>", "group:<name>", "serviceaccount:<id>"), sorted by binding name. The returned slice must not be mutated.
func (*Snapshot) RoleByName ¶ added in v0.10.0
RoleByName returns the enabled Role with this slug, or false.
func (*Snapshot) ScopeChain ¶ added in v0.10.0
ScopeChain returns the scopes a row with this owner lives in, most specific first. A nil owner is a global resource (settings, list calls). An owner whose project or team is absent collapses to the global scope, which is what lets an admin still reach the row.
func (*Snapshot) ScopeChainFor ¶ added in v0.10.0
ScopeChainFor is ScopeChain for a row that is itself a scope. A Team and a Project define the scope they live in; their owner does not name it (a Team is system-owned, a Project team-owned), so a binding at the scope a row defines would otherwise never reach that row. Every other kind delegates to ScopeChain.
func (*Snapshot) ServiceAccount ¶ added in v0.10.0
func (s *Snapshot) ServiceAccount(id string) (*serviceaccount.ServiceAccount, bool)
ServiceAccount returns the enabled ServiceAccount with this id, or false.
func (*Snapshot) ServiceAccountByName ¶ added in v0.10.0
func (s *Snapshot) ServiceAccountByName(name string) (*serviceaccount.ServiceAccount, bool)
ServiceAccountByName returns the enabled ServiceAccount with this slug, or false.
func (*Snapshot) ServiceAccountsForProject ¶ added in v0.10.0
func (s *Snapshot) ServiceAccountsForProject(projectID string) []*serviceaccount.ServiceAccount
ServiceAccountsForProject returns the project's accounts, sorted by name. The returned slice must not be mutated.
func (*Snapshot) SnapshotByName ¶
SnapshotByName returns the Model + Snapshot for a pinned snapshot name, or false. Snapshot names are catalog-wide unique (validation enforces no collision with the owning Model's name or aliases).
func (*Snapshot) SubjectsForKey ¶ added in v0.10.0
SubjectsForKey returns the precomputed subjects the key's principal acts under. The returned slice must not be mutated.
func (*Snapshot) SubjectsForServiceAccount ¶ added in v0.11.0
SubjectsForServiceAccount renders the subjects a service account acts under: its own, the all-accounts group, its project's group when the project is known, then the catch-all.
func (*Snapshot) SystemRateLimitByName ¶ added in v0.10.3
SystemRateLimitByName returns the enabled system-owned RateLimit with this slug, or false. A row of that name owned by anyone else is never a system limit: the binary's buckets are looked up by name alone.
func (*Snapshot) TeamByName ¶ added in v0.10.0
TeamByName returns the enabled Team with this slug, or false.
func (*Snapshot) TokenVersion ¶ added in v0.10.0
TokenVersion returns the user's current token version. Absent (ok=false) means the user is unknown to this snapshot, which invalidates any token claiming to be theirs.
func (*Snapshot) UserDisabled ¶ added in v0.11.0
UserDisabled reports whether userID names a users row marked disabled. False when no users source is attached and for an id with no row.
func (*Snapshot) UserEnabled ¶ added in v0.10.0
UserEnabled reports whether a user may still act. True when no users source is attached: the snapshot cannot tell, and keys predate users.
type Stores ¶
type Stores struct {
Provider *catalogstore.ProviderStore
Host *catalogstore.HostStore
Model *catalogstore.ModelStore
HostKey *hostkey.Store
RateLimit *catalogstore.RateLimitStore
Policy *catalogstore.PolicyStore
Pricing *catalogstore.PricingStore
Binding *catalogstore.BindingStore
Key *key.Store
Overlay *overlay.Store
Settings *settings.Store
Team *team.Store
Project *project.Store
Account *account.Store
Pool *pool.Store
Budget *budget.Store
ServiceAccount *serviceaccount.Store
Group *group.Store
Role *role.Store
RoleBinding *rolebinding.Store
PolicyBinding *policybinding.Store
// Users is the account store, here so a cross-row edit (see InTx) can
// write account rows in the same transaction as catalog rows.
Users *user.Store
// Directory is the auth module's view of the account, tenancy and RBAC tables, the stores its operations write through.
Directory directory.Stores
// SCIMClients holds the identity providers allowed to provision through /scim/v2, by token hash.
SCIMClients scim.TokenStore
// Secrets is the shared secret-resolution registry (env + stored
// backends). Exposed so data-plane components (e.g. the payload-logging
// controller resolving S3 credentials) resolve through the same seam.
Secrets *secret.Registry
// Stored is the stored-secret backend registered in Secrets, exposed so
// the composition root can write a secret (the generated token signing
// key) and run the key ring's background work.
Stored *stored.Backend
// OAuthResolver is the KindOAuth resolver registered in Secrets,
// exposed so the composition root can drive the proactive
// pkgoauth.Refresher against the same instance (shared single-flight).
OAuthResolver *pkgoauth.Resolver
// contains filtered or unexported fields
}
Stores bundles the eight entity stores constructed by Bootstrap. Exposed so callers (admin handlers, seed CLI re-runs, tests) can reach the same underlying stores without re-wiring.
func (*Stores) InTx ¶ added in v0.10.1
InTx runs fn with the stores bound to one transaction (see storage.InTx): every write fn makes commits together, or none does. HostKey is the pool-bound store, for reads only — a stored key's secret is written through the secret backends' own connections and cannot join the transaction.
type TeamLister ¶ added in v0.10.0
type TokenVersionLister ¶ added in v0.10.0
type TokenVersionLister interface {
TokenVersionsAndDisabled(ctx context.Context) (map[string]int, map[string]struct{}, error)
}
TokenVersionLister reads, in one pass over the users table, every enabled user's token version and the ids of disabled users. Satisfied by *app/user.Store.
Source Files
¶
- alias.go
- boot.go
- build.go
- build_binding.go
- build_common.go
- build_host.go
- build_hostkey.go
- build_key.go
- build_model.go
- build_policy.go
- build_pricing.go
- build_provider.go
- build_ratelimit.go
- build_rbac.go
- build_tenancy.go
- catalog.go
- catalog_reload.go
- clone.go
- follow.go
- follow_status.go
- model_ref.go
- notify.go
- notify_apply.go
- notify_debounce.go
- organization_move.go
- overlay_apply.go
- prune.go
- reconcile.go
- reconcile_cascade.go
- reconcile_catalog.go
- reconcile_credentials.go
- reconcile_policy.go
- reconcile_rbac.go
- reconcile_tenancy.go
- reconcile_validate.go
- refs.go
- seed_release.go
- settings.go
- snapshot.go
- snapshot_catalog.go
- snapshot_credentials.go
- snapshot_embed.go
- snapshot_model_index.go
- snapshot_rbac.go
- snapshot_scope.go
- snapshot_tenancy.go
- snapshot_users.go
- stores_tx.go
- subjects.go
- validate.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package catalogtest builds a catalog.Catalog or catalog.Snapshot from rows held in memory, for tests outside app/catalog.
|
Package catalogtest builds a catalog.Catalog or catalog.Snapshot from rows held in memory, for tests outside app/catalog. |