policy

package
v0.0.0-...-089ce19 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package policy defines the network policy that the proxy can choose to enforce.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRule

func RegisterRule(rulename string, constructor func() Rule)

RegisterRule adds a rule to the rule registry. The rule registry contains implementations of the Rule interface recognized by the proxy. Updates to the policy will try to unmarshal json structs into the registered rules. Expects the rule name and a constructor returning the Rule type.

Types

type MatchingType

type MatchingType string
const (
	FullMatch   MatchingType = "full"
	PrefixMatch MatchingType = "prefix"
)

type Policy

type Policy struct {
	// AnyOf expects incoming requests to satisfy one of these Rules.
	AnyOf []Rule `json:"anyOf"`
}

Policy contains a list of Rules that will be applied to the request.

func (Policy) Apply

func (p Policy) Apply(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response)

Apply enforces the policy on the request. Returns http.StatusForbidden if the request does not satisfy the policy rules.

func (*Policy) UnmarshalJSON

func (p *Policy) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for the Policy class. Expects rule_type to specify an existing rule in the rule registry.

type Rule

type Rule interface {
	Allows(req *http.Request) bool
}

Rule interface with method to check compliance of incoming http(s) requests.

type URLMatchRule

type URLMatchRule struct {
	Host      string       `json:"host"`
	Path      string       `json:"path"`
	PathMatch MatchingType `json:"matchPathBy"`
}

Implements the Rule interface. Matches the request URL based on the MatchingType.

func (URLMatchRule) Allows

func (rule URLMatchRule) Allows(req *http.Request) bool

Jump to

Keyboard shortcuts

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