Documentation
¶
Overview ¶
Package policy is the domain layer for the Policy entity: a reusable rule set a policy binding applies to accounts. A policy holds nothing of its own, only references: the models it allows, the pools it draws keys from, and the rate limits and budgets every request under it must fit, each counted once for the bound account (shared) or once per account under it. One kind serves every rung of the ladder; a host-owned policy is a tier preset and links no pools.
Wire format: Policy YAML/JSON carries entity *names*; the admin and seed boundaries resolve names to ids. PG storage: Spec.Models sits in a column, the links in junction tables (see store.go).
Out of scope: which accounts a policy governs (app/policybinding), and resolving the ladder per request (app/plan).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanonicalModelRef ¶ added in v0.10.0
CanonicalModelRef renders a parsed Ref back to its shortest slug form. The Ref's segments are already slug-normalized by modelref.Parse.
func CanonicalizeModelRefs ¶ added in v0.10.0
CanonicalizeModelRefs slugifies every ref to its shortest canonical form and drops post-slug duplicates, preserving order. Catalog resolution (does the ref match an enabled binding?) is a separate, store-backed check the caller layers on top.
Types ¶
type BudgetLink ¶ added in v0.20.0
type BudgetLink struct {
BudgetID string `json:"budgetId" yaml:"budgetId" validate:"required,uuid" doc:"Id of the linked budget."`
Shared *bool `` /* 200-byte string literal not displayed */
}
BudgetLink applies one Budget to a policy's requests.
func (*BudgetLink) IsShared ¶ added in v0.20.0
func (l *BudgetLink) IsShared() bool
IsShared reports whether the link spends one budget for the bound account.
type Policy ¶
type Policy struct {
Meta meta.Metadata `json:"metadata" yaml:"metadata"`
Spec Spec `json:"spec" yaml:"spec"`
}
Policy is the access gate. Composition enforces that every linked id resolves and that the author may use it.
func (*Policy) BudgetIDs ¶ added in v0.20.0
BudgetIDs returns the ids of the linked budgets, in link order.
func (*Policy) CanonicalizeSpecModelRefs ¶ added in v0.10.0
CanonicalizeSpecModelRefs rewrites every grant list on the spec in place: Spec.Models and each RateLimitLink's Models. Errors name the offending field.
func (*Policy) Normalize ¶ added in v0.20.0
func (p *Policy) Normalize()
Normalize gives the read form every boundary returns: models as a list (never null) and every link's shared flag explicit.
func (*Policy) Validate ¶
Validate runs intra-row rules via the shared meta.Validator and enforces:
- Owner.Kind is system, host, team, project or user.
- no pool or budget is linked twice.
- host-owned policies link no pools.
- every model ref names a provider or a provider's model, never a host.
Cross-entity checks (every id resolves; the author may use it) live in app/refcheck.
type RateLimitLink ¶ added in v0.20.0
type RateLimitLink struct {
RateLimitID string `json:"rateLimitId" yaml:"rateLimitId" validate:"required,uuid" doc:"Id of the linked rate limit."`
Models []string `` /* 374-byte string literal not displayed */
Shared *bool `` /* 206-byte string literal not displayed */
}
RateLimitLink applies one RateLimit to a policy's requests: to every model when Models is empty, otherwise only to requests for a model matching one of Models. One rate limit may be linked more than once with different Models or counting.
func (*RateLimitLink) IsShared ¶ added in v0.20.0
func (l *RateLimitLink) IsShared() bool
IsShared reports whether the link counts once for the bound account.
type Spec ¶
type Spec struct {
// Models is the catalog grant: "provider" for every model of a provider, "provider/model" for one model. Empty grants every model the policy's pools can serve. Hosts are the pools' business, so a ref naming one is refused.
Models []string `` /* 372-byte string literal not displayed */
// Enabled defaults to true when nil.
Enabled *bool `` /* 145-byte string literal not displayed */
// PoolIDs are the pools this policy draws keys from, tried in order, so a later pool is the failover for an earlier one. Host-owned policies list none.
PoolIDs []string `` /* 238-byte string literal not displayed */
// RateLimits are the rate limits a request under this policy must fit.
RateLimits []RateLimitLink `` /* 141-byte string literal not displayed */
// Budgets are the budgets a request under this policy must fit.
Budgets []BudgetLink `` /* 175-byte string literal not displayed */
}
Spec carries the model grant, the links, and the enabled flag.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the Policy data-access type. Holds a DB rather than Queries so Upsert can run a multi-table transaction; List reads without one.
func (*Store) Get ¶
Get returns the Policy with the given id and its links, or (nil, nil) if not found.