fake

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(client *resty.Client, builder *Builder) error

Create sends the constructed policy to the specified client.

func IDFromMethodPath

func IDFromMethodPath(method string, path string) string

IDFromMethodPath generates a unique ID for the policy based on the method and path.

func IDFromRequest

func IDFromRequest(req *restful.Request) string

IDFromRequest generates a unique ID for the policy based on request

func InputFromRequest

func InputFromRequest(req *restful.Request) (map[Input]interface{}, error)

InputFromRequest extracts different types of inputs (auth, meta, etc.) from a restful request.

Types

type Builder

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

Builder is a struct for building fake policies. It holds information about the method, path, input, value, status, and result of a policy.

func NewPolicyBuilder

func NewPolicyBuilder(method string, path string) *Builder

func (*Builder) Complete

func (b *Builder) Complete() (*opa.Policy, error)

Complete finalizes the policy construction and returns the policy. It uses a template to generate the policy based on the set conditions.

func (*Builder) Result

func (b *Builder) Result(result interface{}) *Builder

Result sets the HTTP response body expected in the policy rule.

func (*Builder) Status

func (b *Builder) Status(status int) *Builder

Status sets the HTTP status code expected in the policy rule.

func (*Builder) When

func (b *Builder) When(input Input, value interface{}) *Builder

When sets the condition for the policy rule based on the input and value. Supported input: InputAuth | InputMeta | InputQuery | InputBody | InputPath

type Input

type Input string

Input is a custom type representing different types of request inputs.

const (
	InputAuth  Input = "auth"
	InputMeta  Input = "meta"
	InputQuery Input = "query"
	InputBody  Input = "body"
	InputPath  Input = "path"
)

func (Input) Field

func (i Input) Field(fields ...Input) Input

Field extends an Input by appending additional fields.

type PolicyHandler

type PolicyHandler struct {
	*zap.SugaredLogger
	Store Store
}

PolicyHandler is a struct that handles OPA policies requests.

func (*PolicyHandler) Filter

func (h *PolicyHandler) Filter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

Filter is a method that intercepts and processes incoming HTTP requests using OPA policies. It evaluates the request against a specific policy identified by the request's method and path, and modifies the response based on the policy's evaluation results.

func (*PolicyHandler) Handle

func (h *PolicyHandler) Handle(req *restful.Request, resp *restful.Response)

func (*PolicyHandler) Name

func (h *PolicyHandler) Name() string

func (*PolicyHandler) Setup

type Store

type Store interface {
	Setup(ctx context.Context) error
	Create(ctx context.Context, p *opa.Policy) error
	Get(ctx context.Context, id string) (*opa.Policy, error)
	Delete(ctx context.Context, id string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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