Documentation
¶
Overview ¶
Package config owns PlugIt's on-disk layout and files: platform config paths, API directory names, owner-only atomic writes, plugit.yaml loading and validation (SPEC §3.6), and the manifest.json parse cache.
Index ¶
- Constants
- Variables
- func CheckCredentialTransport(baseURL string, allowInsecure bool) error
- func EnsureDir(dir string) error
- func MarshalAPI(c *API) ([]byte, error)
- func ReadManifest(path string, key CacheKey) (*model.Manifest, error)
- func ReadSnapshot(path string) (data []byte, sha256Hex string, err error)
- func RootDir(override string) (string, error)
- func SaveAPI(p Paths, c *API) error
- func ValidateAPIName(name string) error
- func WriteFileAtomic(path string, data []byte) (err error)
- func WriteManifest(path string, key CacheKey, m *model.Manifest) error
- type API
- type Auth
- type AuthType
- type CacheKey
- type Fixed
- type Lint
- type Log
- type LogArgs
- type Network
- type Paths
- func (p Paths) APIConfig(name string) (string, error)
- func (p Paths) APIDir(name string) (string, error)
- func (p Paths) APINames() ([]string, error)
- func (p Paths) DB() string
- func (p Paths) GlobalConfig() string
- func (p Paths) HTTPToken(name string) (string, error)
- func (p Paths) Manifest(name string) (string, error)
- func (p Paths) Root() string
- func (p Paths) SpecSnapshot(name string) (string, error)
- type Policy
- type Source
- type ToolOverride
- type Toolset
Constants ¶
const ( DefaultTimeout = 30 * time.Second MaxTimeout = 10 * time.Minute DefaultMaxResponseBytes = 1 << 20 MaxMaxResponseBytes = 64 << 20 )
Limits on network settings. They keep a hand-edited value from disabling the protections they exist for (SPEC T12).
const ( FlowClientCredentials = "client_credentials" FlowDeviceCode = "device_code" )
OAuth flows (auth.flow).
const CurrentVersion = 6
CurrentVersion is the plugit.yaml schema version this build reads and writes. Changing the schema means bumping it and adding a migration.
const DefaultRetention = 30 * 24 * time.Hour
DefaultRetention is how long the call log keeps an API's calls when log.retention is unset (SPEC §3.6).
const MaxConfigBytes = 1 << 20
MaxConfigBytes caps plugit.yaml. A real config is a few kilobytes.
const MaxManifestBytes = 256 << 20
MaxManifestBytes caps manifest.json (the same cap as the parse child's output).
const MaxSnapshotBytes = 20 << 20
MaxSnapshotBytes caps spec.snapshot.json (the spec fetch limit).
Variables ¶
var ( ErrInvalidConfig = errors.New("invalid config") ErrUnsupportedVersion = errors.New("unsupported config version") ErrAPINotFound = errors.New("API not found") )
Sentinel errors callers can match with errors.Is.
var ErrCacheMiss = errors.New("manifest cache miss")
ErrCacheMiss means manifest.json is missing, unreadable or out of date.
var ErrInvalidAPIName = errors.New("invalid API name")
ErrInvalidAPIName is returned when an API name is not safe to use as a directory name.
Functions ¶
func CheckCredentialTransport ¶ added in v0.2.0
CheckCredentialTransport refuses plain http to a remote host when a credential is sent (SPEC T8), unless allowInsecure is on. The URL is never echoed.
func EnsureDir ¶
EnsureDir creates dir and any missing parents. Every directory it creates, and dir itself even if it already existed, is restricted to the current user (0700, or an owner-only protected DACL on Windows). Existing parents are left untouched.
func MarshalAPI ¶
MarshalAPI renders c as plugit.yaml. The result is validated by parsing it back, so a file plugit writes always loads.
func ReadManifest ¶
ReadManifest returns the cached manifest if it was built for key. Every failure, including a missing file, wraps ErrCacheMiss.
func ReadSnapshot ¶
ReadSnapshot reads spec.snapshot.json and returns it with its sha256.
func RootDir ¶
RootDir returns the PlugIt config root. A non-empty override (the --config-dir flag) wins and is made absolute. Otherwise it is os.UserConfigDir()/plugit.
func SaveAPI ¶
SaveAPI writes apis/<name>/plugit.yaml atomically and owner-only, creating the API directory if needed.
func ValidateAPIName ¶
ValidateAPIName reports whether name can be used as an API name. Names become directory names under apis/, so anything that could escape that directory or misbehave on some OS is rejected.
func WriteFileAtomic ¶
WriteFileAtomic writes data to path so that readers see either the old file or the complete new one, never a partial write. The result is readable and writable only by the current user. The parent directory must exist.
Types ¶
type API ¶
type API struct {
Version int `yaml:"version"`
Name string `yaml:"name"`
Source Source `yaml:"source"`
BaseURL string `yaml:"base_url"`
Prefix string `yaml:"prefix,omitempty"`
Fixed []Fixed `yaml:"fixed,omitempty"`
Network Network `yaml:"network"`
Auth Auth `yaml:"auth"`
Policy Policy `yaml:"policy"`
Log Log `yaml:"log"`
Lint Lint `yaml:"lint,omitempty"`
Toolsets map[string]Toolset `yaml:"toolsets"`
}
API is one API's plugit.yaml (SPEC §3.6). Secret-bearing fields hold references (env:, keyring:), never values.
func ParseAPI ¶
ParseAPI decodes and validates a plugit.yaml document and fills in defaults. Unknown and duplicate keys are errors, so a typo can't silently disable a safety setting. All problems are reported together.
func (*API) PolicyMode ¶
PolicyMode is the validated policy mode.
func (*API) RetentionPeriod ¶
RetentionPeriod is log.retention as a duration ("30d" or a Go duration). Validate has checked the syntax; anything unparsable falls back to the default.
type Auth ¶
type Auth struct {
Type AuthType `yaml:"type,omitempty"`
Header string `yaml:"header,omitempty"`
Param string `yaml:"param,omitempty"`
Secret string `yaml:"secret,omitempty"`
Flow string `yaml:"flow,omitempty"`
TokenURL string `yaml:"token_url,omitempty"`
DeviceURL string `yaml:"device_url,omitempty"`
ClientID string `yaml:"client_id,omitempty"`
Scopes []string `yaml:"scopes,omitempty"`
}
Auth describes the API credential.
type CacheKey ¶
type CacheKey struct {
SpecSHA256 string `json:"spec_sha256"`
Prefix string `json:"prefix"`
Parser string `json:"parser"`
UnsafePaths bool `json:"unsafe_paths,omitempty"`
}
CacheKey is everything a parsed manifest depends on. A cache whose key differs in any field is stale.
type Fixed ¶
type Fixed struct {
Name string `yaml:"name"`
In string `yaml:"in,omitempty"`
Value string `yaml:"value"`
}
Fixed is a parameter sent on every request and hidden from the model.
type Lint ¶ added in v0.2.0
type Lint struct {
Ignore []string `yaml:"ignore,omitempty"`
}
Lint holds lint settings (version 6).
type Log ¶
type Log struct {
Args LogArgs `yaml:"args,omitempty"`
ResponsePreview bool `yaml:"response_preview"`
Retention string `yaml:"retention,omitempty"`
}
Log holds call-log settings (the call log itself arrives in M4).
type Network ¶
type Network struct {
AllowPrivate bool `yaml:"allow_private"`
AllowInsecure bool `yaml:"allow_insecure,omitempty"`
Timeout time.Duration `yaml:"timeout,omitempty"`
MaxResponseBytes int64 `yaml:"max_response_bytes,omitempty"`
}
Network holds per-API network limits.
type Paths ¶
type Paths struct {
// contains filtered or unexported fields
}
Paths computes file locations under a config root. It does no I/O.
func (Paths) APINames ¶
APINames lists the saved APIs: directories under apis/ with a valid name and a plugit.yaml, sorted.
func (Paths) GlobalConfig ¶
GlobalConfig is the path of the global defaults file.
type Policy ¶
type Policy struct {
Mode string `yaml:"mode,omitempty"`
RateLimit string `yaml:"rate_limit,omitempty"`
}
Policy holds the API-wide call policy.
type ToolOverride ¶
type ToolOverride struct {
Name string `yaml:"name,omitempty"`
Description string `yaml:"description,omitempty"`
Policy string `yaml:"policy,omitempty"`
RateLimit string `yaml:"rate_limit,omitempty"`
ResponseFields []string `yaml:"response_fields,omitempty"`
LintIgnore []string `yaml:"lint_ignore,omitempty"`
}
ToolOverride customizes one tool. Empty fields keep the generated value.
func (ToolOverride) IsZero ¶
func (o ToolOverride) IsZero() bool
IsZero reports whether the override changes nothing.