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
- Variables
- func Export(live *State, w io.Writer) error
- func ExportListed(live *State, w io.Writer) error
- func Schema() []byte
- type APIKey
- type Change
- type Config
- type MCPCredential
- type Op
- type Options
- type Organization
- type Plan
- type Result
- type SpendLimit
- type State
- type Team
- type VendorKey
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.ScopeMCP, apikeys.ScopeAdmin, apikeys.ScopeAdminRead}
KeyScopes are the scopes a client key in the file may carry.
Functions ¶
func Export ¶
Export writes the live configuration in the file format. Secrets are not exported: each vendor key and MCP credential becomes a reference to an environment variable to fill in, and client keys are listed without theirs. Revoked keys are left out.
func ExportListed ¶ added in v1.3.3
ExportListed is Export without the sections that list nothing, for a new file: a section it leaves out stays unmanaged, so --prune never empties it.
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
MCPServers []*pb.MCPServerSpec
MCPCredentials []MCPCredential
// 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 MCPCredential ¶ added in v1.4.0
type MCPCredential struct {
Server string `json:"server"`
Header string `json:"header,omitempty"`
ValueEnv string `json:"value_env"`
}
MCPCredential is the header the MCP gateway adds to a server's requests. The value is read from an environment variable, never from the file.
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.