extractors

package
v2.3.2-rc.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

Classification extractors

(formerly known as "YAML classification policies")

Companion package for github.com/fluxninja/aperture/api/gen/proto/go/aperture/classification/v1

Label extractors (shortly – extractors) are a high-level way to specify how to extract a flow label given http request metadata, without a need to write rego code.

Eg.:

extractor:
  json:
    from: request.http.body
    pointer: /query

Internally, multiple extractors will be compiled to a single rego module.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BadExtractor = badExtractor{}

BadExtractor occurs when extractor is invalid.

View Source
var BadLabelName = badLabelName{}

BadLabelName is an error occurring when label name is invalid.

View Source
var BadPackageName = badPackageName{}

BadPackageName occurs when package name is invalid.

Functions

func CompileToRego

func CompileToRego(
	packageName string,
	labelExtractors map[string]*classificationv1.Extractor,
) (string, error)

CompileToRego compiles the extractors into a rego.

func IsRegoIdent

func IsRegoIdent(ident string) bool

IsRegoIdent checks if string is a valid rego identifier – not a rego keyword and composed of allowed characters - alphanumeric and underscore.

Types

type AttributePath

type AttributePath []string

AttributePath is a dot-separated path to attribute to extract data from

Should be either: * one of the fields of [Attribute Context]ctx, or * a special "request.http.bearer" pseudo-attribute.

Eg. Request.http.method

func ParseAttributePath

func ParseAttributePath(path string) AttributePath

ParseAttributePath parses a string into an attribute path.

func (AttributePath) String

func (p AttributePath) String() string

String returns the attribute path as a dot-separated string.

type JSONPointer

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

JSONPointer represents a parsed JSON pointer

https://datatracker.ietf.org/doc/html/rfc6901

func ParseJSONPointer

func ParseJSONPointer(pointer string) (JSONPointer, error)

ParseJSONPointer parses a pointer into a JSONPointer.

func (JSONPointer) Segments

func (p JSONPointer) Segments() []string

Segments returns the segments of the JSON pointer.

func (JSONPointer) String

func (p JSONPointer) String() string

String returns the string representation of the JSON pointer escapedSegments.

type PathTemplate

type PathTemplate struct {
	Prefix              []string
	NumParams           int
	HasTrailingWildcard bool
}

PathTemplate is an OpenAPI-inspired path template

See github.com/fluxninja/aperture/api/gen/proto/go/aperture/classification/v1.PathTemplateMatcher.

func ParsePathTemplate

func ParsePathTemplate(pathTemplate string) (PathTemplate, error)

ParsePathTemplate parses a path template string into a PathTemplate.

func (PathTemplate) IsMoreSpecificThan

func (pt PathTemplate) IsMoreSpecificThan(other PathTemplate) bool

IsMoreSpecificThan returns whether path template might specific than other (eg. /foo is more specific than /*).

Note: This function might have false positives (eg. /foo/bar is treated as more specific than /xyz, even though they're not related), but it should not have any false negatives.

This function can be used as sorting comparator.

func (PathTemplate) NumSegments

func (pt PathTemplate) NumSegments() int

NumSegments returns the number of segments in the path template.

func (PathTemplate) String

func (pt PathTemplate) String() string

String returns string representation of the path template.

Jump to

Keyboard shortcuts

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