config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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).

View Source
const (
	FlowClientCredentials = "client_credentials"
	FlowDeviceCode        = "device_code"
)

OAuth flows (auth.flow).

View Source
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.

View Source
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).

View Source
const MaxConfigBytes = 1 << 20

MaxConfigBytes caps plugit.yaml. A real config is a few kilobytes.

View Source
const MaxManifestBytes = 256 << 20

MaxManifestBytes caps manifest.json (the same cap as the parse child's output).

View Source
const MaxSnapshotBytes = 20 << 20

MaxSnapshotBytes caps spec.snapshot.json (the spec fetch limit).

Variables

View Source
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.

View Source
var ErrCacheMiss = errors.New("manifest cache miss")

ErrCacheMiss means manifest.json is missing, unreadable or out of date.

View Source
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

func CheckCredentialTransport(baseURL string, allowInsecure bool) error

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

func EnsureDir(dir string) error

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

func MarshalAPI(c *API) ([]byte, error)

MarshalAPI renders c as plugit.yaml. The result is validated by parsing it back, so a file plugit writes always loads.

func ReadManifest

func ReadManifest(path string, key CacheKey) (*model.Manifest, error)

ReadManifest returns the cached manifest if it was built for key. Every failure, including a missing file, wraps ErrCacheMiss.

func ReadSnapshot

func ReadSnapshot(path string) (data []byte, sha256Hex string, err error)

ReadSnapshot reads spec.snapshot.json and returns it with its sha256.

func RootDir

func RootDir(override string) (string, error)

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

func SaveAPI(p Paths, c *API) error

SaveAPI writes apis/<name>/plugit.yaml atomically and owner-only, creating the API directory if needed.

func ValidateAPIName

func ValidateAPIName(name string) error

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

func WriteFileAtomic(path string, data []byte) (err error)

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.

func WriteManifest

func WriteManifest(path string, key CacheKey, m *model.Manifest) error

WriteManifest writes the manifest cache atomically and owner-only.

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 LoadAPI

func LoadAPI(p Paths, name string) (*API, error)

LoadAPI reads and validates apis/<name>/plugit.yaml.

func ParseAPI

func ParseAPI(data []byte) (*API, error)

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

func (c *API) PolicyMode() policy.Mode

PolicyMode is the validated policy mode.

func (*API) RetentionPeriod

func (c *API) RetentionPeriod() time.Duration

RetentionPeriod is log.retention as a duration ("30d" or a Go duration). Validate has checked the syntax; anything unparsable falls back to the default.

func (*API) Validate

func (c *API) Validate() error

Validate checks a config with defaults applied. Errors name the field and never echo secret values.

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 AuthType

type AuthType string

AuthType is how the API credential is attached.

const (
	AuthNone   AuthType = "none"
	AuthBearer AuthType = "bearer"
	AuthHeader AuthType = "header"
	AuthQuery  AuthType = "query"
	AuthBasic  AuthType = "basic"
	AuthOAuth2 AuthType = "oauth2"
)

Auth types (SPEC §3.6, §9 item 2).

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

func (Lint) IsZero added in v0.2.0

func (l Lint) IsZero() bool

IsZero lets an empty lint block be left out of the file.

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 LogArgs

type LogArgs string

LogArgs says how call arguments are logged.

const (
	LogArgsNone     LogArgs = "none"
	LogArgsRedacted LogArgs = "redacted"
	LogArgsFull     LogArgs = "full"
)

Log argument modes.

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 NewPaths

func NewPaths(root string) Paths

NewPaths returns the layout rooted at root.

func (Paths) APIConfig

func (p Paths) APIConfig(name string) (string, error)

APIConfig is the path of an API's user-owned plugit.yaml.

func (Paths) APIDir

func (p Paths) APIDir(name string) (string, error)

APIDir is the directory holding one API's config and spec snapshot.

func (Paths) APINames

func (p Paths) APINames() ([]string, error)

APINames lists the saved APIs: directories under apis/ with a valid name and a plugit.yaml, sorted.

func (Paths) DB

func (p Paths) DB() string

DB is the path of the sqlite call log.

func (Paths) GlobalConfig

func (p Paths) GlobalConfig() string

GlobalConfig is the path of the global defaults file.

func (Paths) HTTPToken

func (p Paths) HTTPToken(name string) (string, error)

HTTPToken is the file holding an API's HTTP transport token.

func (Paths) Manifest

func (p Paths) Manifest(name string) (string, error)

Manifest is the path of an API's parsed-manifest cache.

func (Paths) Root

func (p Paths) Root() string

Root is the config root directory.

func (Paths) SpecSnapshot

func (p Paths) SpecSnapshot(name string) (string, error)

SpecSnapshot is the path of an API's normalized spec snapshot.

type Policy

type Policy struct {
	Mode      string `yaml:"mode,omitempty"`
	RateLimit string `yaml:"rate_limit,omitempty"`
}

Policy holds the API-wide call policy.

type Source

type Source struct {
	URL    string `yaml:"url"`
	SHA256 string `yaml:"sha256,omitempty"`
}

Source records where the spec came from.

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.

type Toolset

type Toolset struct {
	Tools       map[string]ToolOverride `yaml:"tools,omitempty"`
	IncludeTags []string                `yaml:"include_tags,omitempty"`
	Methods     []string                `yaml:"methods,omitempty"`
}

Toolset is a named selection of tools with per-tool overrides.

Jump to

Keyboard shortcuts

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