Documentation
¶
Overview ¶
Package apply is the single loader that turns manifest documents into Postgres rows. It has two halves: Plan diffs the submitted documents against the stored rows and reports what would change; Execute authorizes every mutating entry and then writes them, in dependency order.
The boot seed is Plan+Execute over a directory with no authorizer and no prune (see app/seed), so a seed and a POST /apply of the same tree produce the same rows and the same diff vocabulary.
Deliberately out of scope: transactions across kinds (stores are per-kind with their own tx; a mid-way store failure is reported with the partial applied list and re-applying converges), field-level ownership beyond the dirty flag, and reconcile loops.
Index ¶
- Variables
- func Authorize(ctx context.Context, p *Result, authzr authz.Authorizer) error
- type Action
- type AuthzError
- type Counts
- type DuplicateError
- type Entry
- type GovernanceError
- type InvalidError
- type LicenseError
- type Options
- type ReservedNameError
- type Result
- type Rows
- type StoreError
- type Stores
- type UnsupportedKindError
Constants ¶
This section is empty.
Variables ¶
var ErrSelectorRequired = errors.New("apply: prune requires a selector")
ErrSelectorRequired is returned when Prune is set without a selector — an unfiltered prune would delete every user row the manifest omits.
var KindRoutes = map[string]struct{ Plural, Singular string }{
"Team": {"teams", "team"},
"Project": {"projects", "project"},
"Provider": {"providers", "provider"},
"Host": {"hosts", "host"},
"RateLimit": {"rate-limits", "rate-limit"},
"HostKey": {"host-keys", "host-key"},
"Model": {"models", "model"},
"Pricing": {"pricings", "pricing"},
"HostBinding": {"host-bindings", "host-binding"},
"Policy": {"policies", "policy"},
"Group": {"groups", "group"},
"Role": {"roles", "role"},
"ServiceAccount": {"service-accounts", "service-account"},
"Key": {"keys", "key"},
"RoleBinding": {"role-bindings", "role-binding"},
"PolicyBinding": {"policy-bindings", "policy-binding"},
"Overlay": {"models.overlay", "model"},
}
KindRoutes maps a manifest kind to the API plural and singular the RBAC verb and the export query use. Kinds absent from a manifest (Setting) are not listed.
Functions ¶
func Authorize ¶
Authorize checks every entry against authzr and returns an *AuthzError for the first denied write. A nil authorizer skips the pass — the boot seed has no actor. Callers that only plan (dry run) run it too, so a caller who may write nothing never sees the diff.
Non-writing entries (unchanged, skip-dirty) are authorized under get and reported as forbidden when denied — the name comes from the caller's own bundle, so saying "this one was ignored" leaks nothing, while dropping it silently made a scoped apply look complete when half of it was skipped.
Types ¶
type Action ¶
type Action string
Action is what a plan entry would do to one row.
const ( ActionCreate Action = "create" ActionUpdate Action = "update" ActionUnchanged Action = "unchanged" // ActionSkipDirty is an operator-edited row the run refused to // overwrite. Reported as drift; nothing is written. ActionSkipDirty Action = "skip-dirty" ActionDelete Action = "delete" // ActionConflict is a row another writer changed between Plan and // Execute. Nothing is written for it; re-planning picks up the change. ActionConflict Action = "conflict" // ActionForbidden is a row in the bundle the caller may not read. // Nothing is written for it and nothing about the stored row is // reported — the name is the caller's own. ActionForbidden Action = "forbidden" )
type AuthzError ¶
AuthzError reports the row that failed authorization. Nothing was written.
func (*AuthzError) Error ¶
func (e *AuthzError) Error() string
func (*AuthzError) Unwrap ¶
func (e *AuthzError) Unwrap() error
type Counts ¶
type Counts struct {
Create int `json:"create"`
Update int `json:"update"`
Unchanged int `json:"unchanged"`
SkipDirty int `json:"skipDirty"`
Delete int `json:"delete"`
Conflict int `json:"conflict"`
Forbidden int `json:"forbidden"`
}
Counts summarises a plan.
type DuplicateError ¶
type DuplicateError struct {
Kind, Name string
}
DuplicateError reports two submitted documents naming the same row. Last one wins would silently discard the first.
func (*DuplicateError) Error ¶
func (e *DuplicateError) Error() string
type Entry ¶
type Entry struct {
Kind string `json:"kind"`
Name string `json:"name"`
ID string `json:"id,omitempty"`
// Action is what would happen (or happened) to this row.
Action Action `json:"action"`
// ChangedFields lists the authorable JSON paths that differ, in the
// same vocabulary an audit row's change.fields uses.
ChangedFields []string `json:"changedFields,omitempty"`
// IDMismatch reports a metadata.id in the document that does not match
// the row its name resolved to. Ids stay server-owned: the document's
// id is ignored and the mismatch reported.
IDMismatch string `json:"idMismatch,omitempty"`
// contains filtered or unexported fields
}
Entry is one planned row change.
func Execute ¶
Execute authorizes every mutating entry up front and only then writes. A denied row aborts the whole run with an *AuthzError and no writes (all-or-nothing at the authorization step). Writes are sequential in plan order; a store failure returns a *StoreError carrying what already landed. A nil authorizer skips authorization — the boot seed has no actor.
type GovernanceError ¶
GovernanceError reports a row whose mutation the governance settings refuse. Nothing was planned or written.
func (*GovernanceError) Error ¶
func (e *GovernanceError) Error() string
func (*GovernanceError) Unwrap ¶
func (e *GovernanceError) Unwrap() error
type InvalidError ¶
InvalidError reports a document whose translated row failed its kind's Validate. Nothing was planned or written.
func (*InvalidError) Error ¶
func (e *InvalidError) Error() string
func (*InvalidError) Unwrap ¶
func (e *InvalidError) Unwrap() error
type LicenseError ¶
type LicenseError struct{ Kind, Name, Feature string }
LicenseError reports a document declaring a feature this deployment is not licensed for. Unwraps to license.ErrRequired, which the HTTP layer maps to 403 with the license_required body.
func (*LicenseError) Error ¶
func (e *LicenseError) Error() string
func (*LicenseError) Unwrap ¶
func (e *LicenseError) Unwrap() error
type Options ¶
type Options struct {
Stores *Stores
// Force writes over rows an operator edited via the control API
// (meta.Dirty), resetting them to the manifest. Default false: dirty
// rows are reported as skip-dirty and left alone.
Force bool
// Prune deletes rows that match Selector and are absent from the
// submitted set. Requires Selector; never touches system-, provider-,
// or host-owned rows.
Prune bool
Selector string
// Gov supplies the governance:<kind> sections every planned mutation is
// checked against. Nil skips the check — the boot seed runs before the
// settings cache exists.
Gov settings.Reader
// License gates the features a manifest may declare. Nil skips the
// gate: the loaders below the control API (the boot seed, the CLI's
// seed subcommand) load an operator's own tree from disk, which is not
// the surface the licence sells. The control plane always supplies one.
License license.Checker
// Authz is the authorizer Execute will use. Plan reads it only to know
// whether there is one at all: without an authorizer the caller is a
// loader running as the deployment itself (boot seed, CLI), which may
// re-parent a row the same way an admin can. The control plane always
// supplies one, so a scoped caller still cannot chown across scopes.
Authz authz.Authorizer
}
Options configures a plan.
type ReservedNameError ¶
type ReservedNameError struct{ Kind, Name string }
ReservedNameError reports a document claiming a name relay owns.
func (*ReservedNameError) Error ¶
func (e *ReservedNameError) Error() string
type Result ¶
type Result struct {
Entries []Entry `json:"entries"`
Counts Counts `json:"counts"`
// contains filtered or unexported fields
}
Result is the full ordered set of entries one apply would run — the plan. (The verb Plan is the function that builds it.)
type Rows ¶
type Rows struct {
Providers []*provider.Provider
Hosts []*host.Host
RateLimits []*ratelimit.RateLimit
HostKeys []*hostkey.HostKey
Models []*model.Model
Pricings []*pricing.Pricing
Bindings []*binding.Binding
Policies []*policy.Policy
Keys []*key.Key
Teams []*team.Team
Projects []*project.Project
ServiceAccounts []*serviceaccount.ServiceAccount
Groups []*group.Group
Roles []*role.Role
RoleBindings []*rolebinding.RoleBinding
PolicyBindings []*policybinding.PolicyBinding
Overlays []*overlay.Overlay
Users []*user.User
}
Rows is every existing row of every kind, loaded once so planning, pruning, and export share a single read of Postgres.
type StoreError ¶
StoreError reports a write that failed part-way through. Applied lists the entries that landed before it.
func (*StoreError) Error ¶
func (e *StoreError) Error() string
func (*StoreError) Unwrap ¶
func (e *StoreError) Unwrap() error
type Stores ¶
type Stores struct {
Provider *provider.Store
Host *host.Store
RateLimit *ratelimit.Store
HostKey *hostkey.Store
Model *model.Store
Policy *policy.Store
Pricing *pricing.Store
HostBinding *binding.Store
Key *key.Store
Team *team.Store
Project *project.Store
ServiceAccount *serviceaccount.Store
Group *group.Store
Role *role.Store
RoleBinding *rolebinding.Store
PolicyBinding *policybinding.Store
Overlay *overlay.Store
// User is read-only here: users are not a manifest kind, but group
// members and user-principal keys name them, so the resolver needs
// their slugs.
User *user.Store
}
Stores bundles every store a plan reads or writes. Declared here rather than reused from app/catalog: app/catalog depends on the boot seed, which depends on this package.
type UnsupportedKindError ¶
type UnsupportedKindError struct{ Kind string }
UnsupportedKindError reports a document apply cannot write. Settings and identity rows have their own endpoints; ignoring them would make a bundle look applied when half of it was dropped.
func (*UnsupportedKindError) Error ¶
func (e *UnsupportedKindError) Error() string