request

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package request contains components that help to transform an incoming request into OPA-compatible units like a package and a query.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapperOutput

type MapperOutput struct {
	Datastores     []string
	Package        string
	Authorization  bool
	Authentication bool
}

MapperOutput returned by the RequestMapper.

type PathAmbiguousError

type PathAmbiguousError struct {
	RequestURL string
	FirstMatch string
	OtherMatch string
}

PathAmbiguousError is the Error thrown if there are more than one path mapping in the api.yaml-config that match the incoming path.

func (PathAmbiguousError) Error

func (e PathAmbiguousError) Error() string

Textual representation of a PathAmbiguousError.

type PathMapper

type PathMapper interface {

	// Configure the PathMapper and returns nil or any encountered error during processors configuration.
	// Please note that Configure has to be called once before the component can be used (Otherwise Map() will return an error)!
	Configure(appConf *configs.AppConfig) error

	// Map an incoming path to a Datastore and a Package.
	//
	// To make the implementation more flexible, the PathMapper itself decides which type of input it needs.
	// Therefore, an appropriate interface like request.pathMapperInput should be used to transport the needed information
	// for path mapping.
	Map(any) (*MapperOutput, error)
}

PathMapper is the interface that maps an incoming path to a Datastore and a Package. This should be enough for the opa.PolicyCompiler to fire a query for partial evaluation with the datastore as unknowns.

type PathNotFoundError

type PathNotFoundError struct {
	RequestURL string
}

PathNotFoundError is the Error thrown if there is no mapping in the api.yaml-config matching the incoming path.

func (PathNotFoundError) Error

func (e PathNotFoundError) Error() string

Textual representation of a PatNotFoundError.

type PathProcessor

type PathProcessor interface {

	// Configure configures the PathProcessor and returns nil or any encountered error during processors configuration.
	// Please note that Configure has to be called once before the component can be used (Otherwise Process() will return an error)!
	Configure(appConf *configs.AppConfig, processorConf *PathProcessorConfig) error

	// Process processes an incoming path by parsing and afterward mapping it to a Datastore and a Package.
	//
	// To make the implementation more flexible, the PathMapper itself decides which type of input it needs.
	// Therefore, an appropriate interface like request.UrlProcessorInput should be used to transport the needed information
	// for path processing.
	Process(input any) (*PathProcessorOutput, error)
}

PathProcessor is the interface that processes an incoming path by parsing and afterward mapping it to a Datastore and a Package.

This should be enough for the opa.PolicyCompiler to fire a query for partial evaluation with the datastore as unknowns. To separate concerns, the PathProcessor should focus on path parsing and leave the mapping to the request.PathMapper.

type PathProcessorConfig

type PathProcessorConfig struct {
	PathMapper *PathMapper
}

PathProcessorConfig contains all configuration needed by a single request.PathProcessor to run.

Note that this configuration also contains all configurations for nested components. With this in mind, an instance of a PathProcessor can be seen as a standalone thread with all its subcomponents attached to it. As a result of that, two PathProcessors that process different types of paths should be able to run in parallel.

type PathProcessorOutput

type PathProcessorOutput struct {
	Datastores     []string
	Package        string
	Authorization  bool
	Authentication bool
	Path           []string
	Queries        map[string]any
}

PathProcessorOutput is the result of a successfully mapped path.

Datastore and package should be used to map the incoming request to unknowns and a target package for OPA's partial evaluation. Extracted Query-Parameters mapped to their values can i.e. be attached to the input-field of the OPA-query. A slice containing all separated path parts is also returned.

Jump to

Keyboard shortcuts

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