catalog

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 43 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 (modelsByPolicy, pricingByModelHost, etc.) are derived indices over the snapshot — they hold pointers to the same rows.

Index

Constants

View Source
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.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap(ctx context.Context, opts BootstrapOptions) (*Catalog, *Listener, *Stores, error)

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

func BootstrapStores(ctx context.Context, opts BootstrapOptions) (*Catalog, *Stores, error)

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 UserSubjects added in v0.10.0

func UserSubjects(userID string, localGroups, idpGroups []string) []string

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 BindingLister interface {
	List(ctx context.Context) ([]*binding.Binding, error)
}

type BootstrapOptions

type BootstrapOptions struct {
	Pool      *pgxpool.Pool
	MasterKey []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 — 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 wyolet/relay-catalog GitHub
	// archive). 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
}

BootstrapOptions configures the one-call Bootstrap helper. Pool and MasterKey are 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 (c *Catalog) ApplyGroupDelete(id string) error

func (*Catalog) ApplyGroupUpsert added in v0.10.0

func (c *Catalog) ApplyGroupUpsert(g *group.Group) error

func (*Catalog) ApplyHostDelete

func (c *Catalog) ApplyHostDelete(id string) error

func (*Catalog) ApplyHostKeyDelete

func (c *Catalog) ApplyHostKeyDelete(id string) error

func (*Catalog) ApplyHostKeyUpsert

func (c *Catalog) ApplyHostKeyUpsert(k *hostkey.HostKey) error

func (*Catalog) ApplyHostUpsert

func (c *Catalog) ApplyHostUpsert(h *host.Host) error

func (*Catalog) ApplyKeyDelete added in v0.10.0

func (c *Catalog) ApplyKeyDelete(id string) error

func (*Catalog) ApplyKeyUpsert added in v0.10.0

func (c *Catalog) ApplyKeyUpsert(k *key.Key) error

func (*Catalog) ApplyModelDelete

func (c *Catalog) ApplyModelDelete(id string) error

func (*Catalog) ApplyModelUpsert

func (c *Catalog) ApplyModelUpsert(m *model.Model) error

func (*Catalog) ApplyOverlayDelete added in v0.3.0

func (c *Catalog) ApplyOverlayDelete(kind, resourceID string) error

ApplyOverlayDelete removes an overlay and restores the target's pristine template (factory reset).

func (*Catalog) ApplyOverlayUpsert added in v0.3.0

func (c *Catalog) ApplyOverlayUpsert(o *overlay.Overlay) error

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 (c *Catalog) ApplyPolicyBindingDelete(id string) error

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 (c *Catalog) ApplyPolicyDelete(id string) error

func (*Catalog) ApplyPolicyUpsert

func (c *Catalog) ApplyPolicyUpsert(p *policy.Policy) error

func (*Catalog) ApplyPricingDelete

func (c *Catalog) ApplyPricingDelete(id string) error

func (*Catalog) ApplyPricingUpsert

func (c *Catalog) ApplyPricingUpsert(p *pricing.Pricing) error

func (*Catalog) ApplyProjectDelete added in v0.10.0

func (c *Catalog) ApplyProjectDelete(id string) error

func (*Catalog) ApplyProjectUpsert added in v0.10.0

func (c *Catalog) ApplyProjectUpsert(p *project.Project) error

func (*Catalog) ApplyProviderDelete

func (c *Catalog) ApplyProviderDelete(id string) error

func (*Catalog) ApplyProviderUpsert

func (c *Catalog) ApplyProviderUpsert(p *provider.Provider) error

func (*Catalog) ApplyRateLimitDelete

func (c *Catalog) ApplyRateLimitDelete(id string) error

func (*Catalog) ApplyRateLimitUpsert

func (c *Catalog) ApplyRateLimitUpsert(r *ratelimit.RateLimit) error

func (*Catalog) ApplyRoleBindingDelete added in v0.10.0

func (c *Catalog) ApplyRoleBindingDelete(id string) error

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 (c *Catalog) ApplyRoleDelete(id string) error

func (*Catalog) ApplyRoleUpsert added in v0.10.0

func (c *Catalog) ApplyRoleUpsert(r *role.Role) error

func (*Catalog) ApplyServiceAccountDelete added in v0.10.0

func (c *Catalog) ApplyServiceAccountDelete(id string) error

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 (c *Catalog) ApplyTeamDelete(id string) error

func (*Catalog) ApplyTeamUpsert added in v0.10.0

func (c *Catalog) ApplyTeamUpsert(t *team.Team) error

func (*Catalog) Current

func (c *Catalog) Current() *Snapshot

Current returns the live Snapshot. Safe to call from any goroutine; the returned pointer is immutable until the next successful Reload.

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, load the hostkey master-key version, 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

func (c *Catalog) IsReady() bool

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

func (c *Catalog) OnSettingsChange(section string, fn func())

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

func (c *Catalog) Reload(ctx context.Context) error

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

func (c *Catalog) ReloadTokenVersions(ctx context.Context) error

ReloadTokenVersions rebuilds only the token-version map — the whole snapshot reaction to a users write.

func (*Catalog) Setting

func (c *Catalog) Setting(section string) (any, bool)

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

func (c *Catalog) UseClock(now func() time.Time)

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

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 GroupLister added in v0.10.0

type GroupLister interface {
	List(ctx context.Context) ([]*group.Group, error)
}

type HostKeyLister

type HostKeyLister interface {
	List(ctx context.Context) ([]*hostkey.HostKey, error)
}

type HostLister

type HostLister interface {
	List(ctx context.Context) ([]*host.Host, error)
}

type KeyLister added in v0.10.0

type KeyLister interface {
	List(ctx context.Context) ([]*key.Key, error)
}

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

func NewListener(cat *Catalog, pool *pgxpool.Pool, stores listenerStores) *Listener

NewListener constructs a Listener. Call Run to start it.

func (*Listener) Run

func (l *Listener) Run(ctx context.Context) error

Run blocks until ctx is cancelled. It reconnects on any connection error.

type ModelLister

type ModelLister interface {
	List(ctx context.Context) ([]*model.Model, error)
}

type OverlayLister added in v0.3.0

type OverlayLister interface {
	List(ctx context.Context) ([]*overlay.Overlay, error)
}

type PolicyBindingLister added in v0.10.0

type PolicyBindingLister interface {
	List(ctx context.Context) ([]*policybinding.PolicyBinding, error)
}

type PolicyLister

type PolicyLister interface {
	List(ctx context.Context) ([]*policy.Policy, error)
}

type PricingLister

type PricingLister interface {
	List(ctx context.Context) ([]*pricing.Pricing, error)
}

type ProjectLister added in v0.10.0

type ProjectLister interface {
	List(ctx context.Context) ([]*project.Project, error)
}

type ProviderLister

type ProviderLister interface {
	List(ctx context.Context) ([]*provider.Provider, error)
}

type RateLimitLister

type RateLimitLister interface {
	List(ctx context.Context) ([]*ratelimit.RateLimit, error)
}

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 RoleLister interface {
	List(ctx context.Context) ([]*role.Role, error)
}

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 catalog-embed and tests; callers supply only the kinds they need — pass nil/empty slices for the rest.

func (*Snapshot) AllBindings

func (s *Snapshot) AllBindings() []*binding.Binding

AllBindings returns every binding in the snapshot, sorted by name.

func (*Snapshot) AllGroups added in v0.10.0

func (s *Snapshot) AllGroups() []*group.Group

AllGroups returns every Group in the snapshot, sorted by slug.

func (*Snapshot) AllHostKeys

func (s *Snapshot) AllHostKeys() []*hostkey.HostKey

AllHostKeys returns every HostKey in the snapshot, sorted by slug.

func (*Snapshot) AllKeys added in v0.10.0

func (s *Snapshot) AllKeys() []*key.Key

AllKeys returns every Key in the snapshot, sorted by slug.

func (*Snapshot) AllModels

func (s *Snapshot) AllModels() []*model.Model

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

func (s *Snapshot) AllPolicies() []*policy.Policy

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

func (s *Snapshot) AllPricings() []*pricing.Pricing

AllPricings returns every Pricing in the snapshot, sorted by slug.

func (*Snapshot) AllProjects added in v0.10.0

func (s *Snapshot) AllProjects() []*project.Project

AllProjects returns every Project in the snapshot, sorted by slug.

func (*Snapshot) AllProviders

func (s *Snapshot) AllProviders() []*provider.Provider

AllProviders returns every Provider in the snapshot, sorted by slug.

func (*Snapshot) AllRateLimits

func (s *Snapshot) AllRateLimits() []*ratelimit.RateLimit

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

func (s *Snapshot) AllRoles() []*role.Role

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

func (s *Snapshot) AllTeams() []*team.Team

AllTeams returns every Team in the snapshot, sorted by slug.

func (*Snapshot) Binding

func (s *Snapshot) Binding(id string) (*binding.Binding, bool)

Binding returns the enabled HostBinding with this id, or false.

func (*Snapshot) BindingForModelHost

func (s *Snapshot) BindingForModelHost(modelID, hostID string) (*binding.Binding, bool)

BindingForModelHost returns the binding for (modelID, hostID), or false. O(1) — the routing hot-path lookup.

func (*Snapshot) BindingsForModel

func (s *Snapshot) BindingsForModel(modelID string) []*binding.Binding

BindingsForModel returns the bindings declared for a model, sorted by binding name. The returned slice must not be mutated.

func (*Snapshot) Dependents

func (s *Snapshot) Dependents(kind refKind, id string) []refKey

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

func (s *Snapshot) DisabledPolicy(id string) (*policy.Policy, bool)

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

func (s *Snapshot) EnabledHosts() []*host.Host

EnabledHosts returns enabled hosts sorted by Meta.Name.

func (*Snapshot) EnabledModels

func (s *Snapshot) EnabledModels() []*model.Model

EnabledModels returns enabled models sorted by Meta.Name.

func (*Snapshot) Generation added in v0.10.0

func (s *Snapshot) Generation() uint64

Generation identifies this snapshot. Two snapshots are the same view if and only if their generations match.

func (*Snapshot) Group added in v0.10.0

func (s *Snapshot) Group(id string) (*group.Group, bool)

Group returns the enabled Group with this id, or false.

func (*Snapshot) GroupByName added in v0.10.0

func (s *Snapshot) GroupByName(name string) (*group.Group, bool)

GroupByName returns the enabled Group with this slug, or false.

func (*Snapshot) GroupsForUser added in v0.10.0

func (s *Snapshot) GroupsForUser(userID string) []string

GroupsForUser returns the names of the groups holding this user, sorted. The returned slice must not be mutated.

func (*Snapshot) Host

func (s *Snapshot) Host(id string) (*host.Host, bool)

Host returns the enabled Host with this id, or false.

func (*Snapshot) HostByName

func (s *Snapshot) HostByName(name string) (*host.Host, bool)

HostByName returns the enabled Host with this slug, or false.

func (*Snapshot) HostKey

func (s *Snapshot) HostKey(id string) (*hostkey.HostKey, bool)

HostKey returns the enabled HostKey with this id, or false.

func (*Snapshot) HostKeysForHost

func (s *Snapshot) HostKeysForHost(hostID string) []*hostkey.HostKey

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) HostKeysInPolicy

func (s *Snapshot) HostKeysInPolicy(policyID string) []*hostkey.HostKey

HostKeysInPolicy returns the HostKeys attached to this Policy in declaration order (relevant for KeySelectionPrioritized).

func (*Snapshot) HostSlug

func (s *Snapshot) HostSlug(hostID string) (string, bool)

HostSlug returns the Host.Meta.Name for the given Host id, or false.

func (*Snapshot) Hosts

func (s *Snapshot) Hosts() []*host.Host

Hosts returns all enabled Host rows. Stable order by slug. Used by the /v1/proxy/hosts list endpoint.

func (*Snapshot) Key added in v0.10.0

func (s *Snapshot) Key(id string) (*key.Key, bool)

Key returns the enabled Key with this id, or false.

func (*Snapshot) KeyByHash added in v0.10.0

func (s *Snapshot) KeyByHash(hash string) (k *key.Key, matchedPrevious bool)

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

func (s *Snapshot) KeyHashesForUser(userID string) []string

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) Model

func (s *Snapshot) Model(id string) (*model.Model, bool)

Model returns the enabled Model with this id, or false.

func (*Snapshot) ModelsByName

func (s *Snapshot) ModelsByName(name string) []*model.Model

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

func (s *Snapshot) ModelsByProvider(providerID string) []*model.Model

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) ModelsInPolicy

func (s *Snapshot) ModelsInPolicy(policyID string) []*model.Model

ModelsInPolicy returns the Models attached to this Policy in declaration order. nil if the Policy is unknown or empty.

func (*Snapshot) Policy

func (s *Snapshot) Policy(id string) (*policy.Policy, bool)

Policy returns the enabled Policy with this id, or false.

func (*Snapshot) PolicyAllowsCombo

func (s *Snapshot) PolicyAllowsCombo(policyID, modelID, hostID string) bool

PolicyAllowsCombo reports whether the policy grants (modelID, hostID).

An id naming no enabled policy grants nothing. Answering "allowed" for one is the wrong default in the direction that matters: a host key whose tier policy was switched off or deleted would pass the tier gate for every model, and the upstream reservation would find no rules to meter it by. A policy that IS enabled and carries no materialized set is the implicit wildcard and allows everything — implicit-wildcard customer policies handle deprecation separately at resolution, and tier policies allow all by design.

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

func (s *Snapshot) PolicyByName(name string) (*policy.Policy, bool)

PolicyByName returns the enabled Policy with this slug, or false.

func (*Snapshot) PolicyGrantsHost added in v0.10.1

func (s *Snapshot) PolicyGrantsHost(policyID, hostID string) bool

PolicyGrantsHost reports whether the policy's explicit grant set holds any model on hostID. An implicit-wildcard policy has no set and answers false: its only authorization is the host-key gate, which a keyless host skips.

func (*Snapshot) PriceByModelHost

func (s *Snapshot) PriceByModelHost(modelID, hostID string) (*pricing.Pricing, bool)

PriceByModelHost returns the Pricing that covers (modelID, hostID), or false.

func (*Snapshot) Pricing

func (s *Snapshot) Pricing(id string) (*pricing.Pricing, bool)

Pricing returns the enabled Pricing with this id, or false.

func (*Snapshot) PricingForBinding added in v0.3.0

func (s *Snapshot) PricingForBinding(b *binding.Binding) (*pricing.Pricing, bool)

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

func (s *Snapshot) Project(id string) (*project.Project, bool)

Project returns the enabled Project with this id, or false.

func (*Snapshot) ProjectByName added in v0.10.0

func (s *Snapshot) ProjectByName(name string) (*project.Project, bool)

ProjectByName returns the enabled Project with this slug, or false.

func (*Snapshot) ProjectsInTeam added in v0.10.0

func (s *Snapshot) ProjectsInTeam(teamID string) []*project.Project

ProjectsInTeam returns the team's projects, sorted by project name. The returned slice must not be mutated.

func (*Snapshot) Provider

func (s *Snapshot) Provider(id string) (*provider.Provider, bool)

Provider returns the enabled Provider with this id, or false.

func (*Snapshot) ProviderByName

func (s *Snapshot) ProviderByName(name string) (*provider.Provider, bool)

ProviderByName returns the enabled Provider with this slug, or false.

func (*Snapshot) ProviderSlug

func (s *Snapshot) ProviderSlug(providerID string) (string, bool)

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) RateLimit

func (s *Snapshot) RateLimit(id string) (*ratelimit.RateLimit, bool)

RateLimit returns the enabled RateLimit with this id, or false.

func (*Snapshot) RateLimitByName

func (s *Snapshot) RateLimitByName(name string) (*ratelimit.RateLimit, bool)

RateLimitByName returns the enabled RateLimit with this slug, or false. Used by proxy-mode dispatch to look up the system-owned inference-api-proxy / inference-api-proxy-anonymous buckets.

func (*Snapshot) RateLimitOfPolicy

func (s *Snapshot) RateLimitOfPolicy(policyID string) *ratelimit.RateLimit

RateLimitOfPolicy returns the single RateLimit bound to this Policy, or nil when none is configured.

func (*Snapshot) ResolveAlias added in v0.3.0

func (s *Snapshot) ResolveAlias(key string, patterns bool) (AliasRef, bool)

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) ResolveSnapshot

func (s *Snapshot) ResolveSnapshot(key string) (*model.Model, *model.Snapshot, string, bool)

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) Role added in v0.10.0

func (s *Snapshot) Role(id string) (*role.Role, bool)

Role returns the enabled Role with this id, or false.

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

func (s *Snapshot) RoleByName(name string) (*role.Role, bool)

RoleByName returns the enabled Role with this slug, or false.

func (*Snapshot) ScopeChain added in v0.10.0

func (s *Snapshot) ScopeChain(o *meta.Owner) []meta.Owner

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

func (s *Snapshot) ScopeChainFor(kind, id string, o *meta.Owner) []meta.Owner

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

func (s *Snapshot) SnapshotByName(name string) (*model.Model, *model.Snapshot, bool)

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

func (s *Snapshot) SubjectsForKey(keyID string) []string

SubjectsForKey returns the precomputed subjects the key's principal acts under. The returned slice must not be mutated.

func (*Snapshot) Team added in v0.10.0

func (s *Snapshot) Team(id string) (*team.Team, bool)

Team returns the enabled Team with this id, or false.

func (*Snapshot) TeamByName added in v0.10.0

func (s *Snapshot) TeamByName(name string) (*team.Team, bool)

TeamByName returns the enabled Team with this slug, or false.

func (*Snapshot) TokenVersion added in v0.10.0

func (s *Snapshot) TokenVersion(userID string) (int, bool)

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) UserEnabled added in v0.10.0

func (s *Snapshot) UserEnabled(userID string) bool

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  *provider.Store
	Host      *host.Store
	Model     *model.Store
	HostKey   *hostkey.Store
	RateLimit *ratelimit.Store
	Policy    *policy.Store
	Pricing   *pricing.Store
	Binding   *binding.Store
	Key       *key.Store
	Overlay   *overlay.Store
	Settings  *settings.Store
	Team      *team.Store
	Project   *project.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

	// 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 *pkgsecret.Registry

	// Stored is the AES-GCM stored-secret backend registered in Secrets,
	// exposed so the composition root can write a secret (the generated
	// token signing key) through the same master-key path.
	Stored *pkgsecret.StoredResolver

	// 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

func (s *Stores) InTx(ctx context.Context, fn func(ctx context.Context, tx *Stores) error) error

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 TeamLister interface {
	List(ctx context.Context) ([]*team.Team, error)
}

type TokenVersionLister added in v0.10.0

type TokenVersionLister interface {
	TokenVersions(ctx context.Context) (map[string]int, error)
}

TokenVersionLister reads users.token_version for every user. Satisfied by *app/user.Store.

Jump to

Keyboard shortcuts

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