policy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package policy is the policy document an administrator writes for the gateway: its types, strict decoding, the canonical encoding (one byte form per meaning, so two policies compare byte for byte) and an offline check of how a policy decides a described request.

The types are the gateway's own; a policy built or changed here is accepted or refused by the gateway exactly as written. Publishing a policy is never done here: it goes through the gateway's Admin API and its confirmed activation.

Index

Constants

View Source
const (
	SchemaVersion = document.SchemaVersion
	ProfileCore   = document.ProfileCore
)

SchemaVersion is the policy schema version this gateway reads, and ProfileCore the only profile it supports.

Variables

This section is empty.

Functions

func Encode

func Encode(p Policy) ([]byte, error)

Encode returns the canonical form of p: 2-space JSON with members in struct order and a trailing newline, lists sorted where their order carries no meaning. It fails only on a schema that is not valid JSON.

Types

type API

type API = document.API

The policy document's types.

type BodyRule

type BodyRule = document.BodyRule

The policy document's types.

type CORS

type CORS = document.CORS

The policy document's types.

type Decision

type Decision = compile.Answer

Decision is how a policy decides a Request. Check and Code name the refusing check and its error code; NotChecked lists what an offline check cannot decide.

func Check

func Check(p Policy, req Request) (Decision, error)

Check compiles p as the gateway would publish it and decides req in the request handler's order: route, access, roles, forward path. It cannot check a token, rate limits, bodies, blocked accounts or addresses, which need a running gateway. A policy the gateway would refuse is returned as its *PolicyError; an invalid request names the refused field.

type Forward

type Forward = document.Forward

The policy document's types.

type HeaderCondition

type HeaderCondition = document.HeaderCondition

The policy document's types.

type Operation

type Operation = document.Operation

The policy document's types.

type Permit

type Permit = document.Permit

The policy document's types.

type Policy

type Policy = document.Policy

The policy document's types.

func Decode

func Decode(data []byte) (Policy, error)

Decode strictly decodes a policy document: unknown, repeated or non-lower-case members and anything after the document are refused with a *PolicyError. It checks the document's shape; Check also checks what it means.

type PolicyError

type PolicyError = document.PolicyError

PolicyError is a refusal: a stable code and the field it concerns.

type RateRule

type RateRule = document.RateRule

The policy document's types.

type Request

type Request struct {
	Method  string
	Path    string
	Host    string
	Headers map[string]string
	Roles   []string
}

Request describes a request to check. Roles stand for a verified token's roles; Host and Headers for the request's, which conditions select by.

type ResponseHeaders

type ResponseHeaders = document.ResponseHeaders

The policy document's types.

type Role

type Role = document.Role

The policy document's types.

type Upstream

type Upstream = document.Upstream

The policy document's types.

type When

type When = document.When

The policy document's types.

Jump to

Keyboard shortcuts

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