access

package
v0.1.888 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package access keeps the named API keys issued by the gateway.

Index

Constants

View Source
const Prefix = "sk-magpie-key-"

Variables

View Source
var Periods = []string{"day", "week", "month"}

Periods are the windows a limit can be set for.

Functions

func ConfigureLAN

func ConfigureLAN(on, rotate bool) error

ConfigureLAN starts sharing with a named key. Rotation preserves the key's identity, name and enabled state.

func Managed

func Managed(secret string) bool

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()

func Path

func Path() string

func Restore

func Restore(keys []Key) error

Restore replaces the gateway credentials when restoring their settings.

func Update

func Update(action string, in Change) (string, error)

Update writes the named key store atomically.

func Window added in v0.1.675

func Window(period string, now time.Time) (start, reset time.Time)

Window is the calendar window of period that now is in, in now's location: its start and when the next begins.

func WithIdentity

func WithIdentity(ctx context.Context, who Identity) context.Context

Types

type Change

type Change struct {
	Key  string `json:"key"`
	Name string `json:"name"`
	// Limit is what "limit-key" sets; nil or Unlimited takes the limit off.
	Limit *Limit `json:"limit,omitempty"`
}

type Identity

type Identity struct {
	KeyID, KeyName string
	Limit          *Limit
}

Identity is the gateway key a request came with, and its budget.

func Authenticate

func Authenticate(secret string) (Identity, bool)

Authenticate reloads the store so revocation takes effect in running gateways.

func Caller

func Caller(ctx context.Context) Identity

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"`
}

func Export

func Export() ([]Key, error)

Export returns credentials only for the encrypted backup bundle.

func List

func List() ([]Key, error)

List never returns credentials; only the administrator's copy action does.

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.

func (*Limit) Limited added in v0.1.675

func (l *Limit) Limited() bool

Limited: l caps something.

func (*Limit) Valid added in v0.1.675

func (l *Limit) Valid() (*Limit, error)

Valid is l as it is kept: nil for no limit, an error for one that can't be.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL