Documentation
¶
Overview ¶
Package declarative keeps a Keystone configuration in a file and applies it through the Admin API. Models, rules and user rate limits are the Admin API's own messages, so the format follows ktms.v1 field for field.
Index ¶
Constants ¶
const APIVersion = "ktms.ai-process.dev/v1alpha1"
APIVersion names this format; it may still change within 1.x.
const SchemaURL = "https://raw.githubusercontent.com/ai-process/ktms/main/schema/ktms-config.schema.json"
SchemaURL is where the published schema lives, for editors' $schema hints.
Variables ¶
var KeyScopes = []string{apikeys.ScopeGenerate, apikeys.ScopeAdmin, apikeys.ScopeAdminRead}
KeyScopes are the scopes a client key in the file may carry.
Functions ¶
Types ¶
type APIKey ¶
type APIKey struct {
Name string `json:"name"`
Scopes []string `json:"scopes,omitempty"`
Organization string `json:"organization,omitempty"`
Team string `json:"team,omitempty"`
Policy *pb.APIKeyPolicy `json:"-"`
}
APIKey is a client key, matched by name. Its secret exists only in the apply that mints it.
type Config ¶
type Config struct {
APIVersion string
Models []*pb.ModelSpec
Rules []*pb.RuleSpec
Organizations []Organization
APIKeys []APIKey
VendorKeys []VendorKey
SpendLimits []SpendLimit
UserRateLimits []*pb.UserRateLimitSpec
// contains filtered or unexported fields
}
Config is a desired configuration. A nil section is not managed: apply leaves that part of Keystone alone. A present one, even empty, is managed, and --prune deletes what it does not list.
func Parse ¶
Parse reads YAML (or JSON) into a Config and checks it on its own; checks that need the live configuration happen in Plan.
type Options ¶
type Options struct {
// Prune deletes what a managed section does not list. Admin-scope keys
// are never revoked by a prune: one of them is likely the caller's own.
Prune bool
// Env looks up vendor keys; os.LookupEnv when nil.
Env func(string) (string, bool)
}
Options tune a plan.
type Organization ¶
Organization groups teams; both are matched by name.
type Plan ¶
Plan is the ordered set of Admin API calls that turns the live configuration into the desired one.
func Build ¶
Build compares the desired configuration with the live one. It fails when the two cannot be reconciled through the Admin API (a key whose scopes or team changed, a revoked key named again, a missing vendor key variable).
type Result ¶
type Result struct {
// Minted holds new client keys by name. They exist nowhere else: show them once.
Minted map[string]string
}
Result is what an apply produced that only it can show.
type SpendLimit ¶
type SpendLimit struct {
SubjectType string `json:"subject_type"`
SubjectID string `json:"subject_id"`
Period string `json:"period"`
LimitUSD float64 `json:"limit_usd,omitempty"`
LimitNanoUSD int64 `json:"limit_nanousd,omitempty"`
}
SpendLimit caps a key's or a user's spend per UTC day or month. Team caps belong to Team.MonthlyBudgetUSD.
func (SpendLimit) Nano ¶
func (l SpendLimit) Nano() int64
Nano is the cap in nano-USD, whichever of the two fields the file used.
type State ¶
type State struct {
Config *pb.GetConfigResponse
Keys []*pb.APIKeyInfo
Orgs []*pb.Organization
Teams []*pb.Team
}
State is Keystone's live configuration as the Admin API reports it.