Documentation
¶
Overview ¶
Package access keeps the named API keys issued by the gateway.
Index ¶
- Constants
- Variables
- func ConfigureLAN(on, rotate bool) error
- func Managed(secret string) bool
- func MigrateLegacyLANKey() error
- func MigrateLegacyLANKeyBestEffort()
- func Path() string
- func Restore(keys []Key) error
- func Update(action string, in Change) (string, error)
- func Window(period string, now time.Time) (start, reset time.Time)
- func WithIdentity(ctx context.Context, who Identity) context.Context
- type Change
- type Identity
- type Key
- type Limit
Constants ¶
const Prefix = "sk-magpie-key-"
Variables ¶
var Periods = []string{"day", "week", "month"}
Periods are the windows a limit can be set for.
Functions ¶
func ConfigureLAN ¶
ConfigureLAN starts sharing with a named key. Rotation preserves the key's identity, name and enabled state.
func MigrateLegacyLANKey ¶
func MigrateLegacyLANKey() error
MigrateLegacyLANKey makes the old Settings key a normal, revocable caller key. Keep LANKey for older Magpie versions; LANKeyID marks a completed migration so the retained credential cannot resurrect a removed key.
func MigrateLegacyLANKeyBestEffort ¶
func MigrateLegacyLANKeyBestEffort()
Types ¶
type Identity ¶
Identity is the gateway key a request came with, and its budget.
func Authenticate ¶
Authenticate reloads the store so revocation takes effect in running gateways.
type Key ¶
type Key struct {
ID string `json:"id"`
Name string `json:"name"`
Off bool `json:"off,omitempty"`
LAN bool `json:"lan,omitempty"` // default key and durable migration marker
Secret string `json:"secret,omitempty"`
Masked string `json:"masked,omitempty"`
// Limit is the key's own budget (#585); nil for none.
Limit *Limit `json:"limit,omitempty"`
}
type Limit ¶ added in v0.1.675
type Limit struct {
Period string `json:"period"`
Tokens int64 `json:"tokens,omitempty"`
Cost float64 `json:"cost,omitempty"`
CacheReads bool `json:"cacheReads,omitempty"`
}
Limit is a gateway key's budget for a calendar window in local time (#585): a day from midnight, a week from Monday's midnight, a month from the 1st's. Tokens counts each call's uncached input, output (reasoning included) and cache writes, and its cache reads too when CacheReads is set; Cost is an estimate in US dollars at the prices magpie shows on the Usage page, not a vendor's bill. A cap of 0 is no cap; a limit with neither is no limit.