apipolicy

package
v0.16.6 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 26 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 apipolicy implements positive API validation from pinned local artifacts. It neither selects an upstream nor authenticates a caller. Response validation can prevent delivery but cannot undo an operation already executed by an origin.

Index

Constants

View Source
const MaxBytes = 1 << 20
View Source
const MaxDepth = 32
View Source
const MaxNodes = 4096

Variables

View Source
var ErrInvalid = errors.New("API policy validation failed")

Errors never include instance values, credentials, or schema diagnostics.

Functions

func ParseJSON

func ParseJSON(data []byte) (any, error)

ParseJSON rejects duplicate members and bounds work before schema evaluation.

Types

type Artifact

type Artifact struct {
	Path   string `json:"path"`
	SHA256 string `json:"sha256"`
}

type Binding

type Binding struct {
	Method string `json:"method"`
	Path   string `json:"path"`
}

type Bundle

type Bundle struct {
	// contains filtered or unexported fields
}

func Load

func Load(bootstrapDir, descriptorPath, descriptorSHA256 string) (*Bundle, error)

Load confines all artifact opens (including symlink resolution) to bootstrapDir. The declaration itself is pinned by descriptorSHA256 in the WAF configuration.

func (*Bundle) GRPCMethod

func (b *Bundle) GRPCMethod(path string) error

GRPCMethod is the call-header gate. Unknown methods require explicit POST passthrough. It runs before opening an origin stream.

func (*Bundle) Passthrough

func (b *Bundle) Passthrough(method, path string) bool

func (*Bundle) Resolve

func (b *Bundle) Resolve(method, path string) (*Operation, error)

Resolve requires either a declared operation or an explicit exact passthrough. A nil operation with nil error is an intentional passthrough, never a fallback.

func (*Bundle) ValidateGRPC

func (b *Bundle) ValidateGRPC(path string, response bool, data []byte) error

ValidateGRPC must run on each complete decompressed message before releasing its frame. It never remarshal/replaces the wire, so unknown fields survive.

type Declaration

type Declaration struct {
	Version     string                  `json:"version"`
	Artifacts   map[string]Artifact     `json:"artifacts"`
	OpenAPI     string                  `json:"openapi,omitempty"`
	Descriptors string                  `json:"descriptors,omitempty"`
	GRPC        map[string]MethodPolicy `json:"grpc,omitempty"`
	Passthrough []Binding               `json:"passthrough,omitempty"`
}

Declaration is the descriptorPath JSON document. Every external resource must be explicitly declared and SHA-256 pinned, including the FileDescriptorSet.

type FieldPolicy

type FieldPolicy struct {
	Required bool `json:"required,omitempty"`
	Schema   any  `json:"schema"`
}

FieldPolicy validates typed protobuf values. Missing presence-aware fields are distinct from explicit default values; implicit-presence scalars use defaults. Enum names are strings; unknown enum numbers remain numbers. Bytes are base64.

type MethodPolicy

type MethodPolicy struct {
	Request  map[string]FieldPolicy `json:"request"`
	Response map[string]FieldPolicy `json:"response,omitempty"`
}

type Operation

type Operation struct {
	// contains filtered or unexported fields
}

Operation is an immutable route-independent validation binding. A router can resolve its own destination and use the same request/response gates.

func (*Operation) ValidateRequest

func (o *Operation) ValidateRequest(r *http.Request, body io.Reader) error

func (*Operation) ValidateResponse

func (o *Operation) ValidateResponse(status int, headers http.Header, body io.Reader) error

ValidateResponse runs only when the caller explicitly enables its delivery gate. The origin has already executed; no response gate is a transaction undo.

func (*Operation) ValidateResponseForMethod

func (o *Operation) ValidateResponseForMethod(method string, status int, headers http.Header, body io.Reader) error

ValidateResponseForMethod validates representation metadata without requiring payload bytes where HTTP forbids a response body.

Jump to

Keyboard shortcuts

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