rego

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnnoKindMatcher added in v0.21.0

type AnnoKindMatcher struct {
	APIGroups []string `json:"apiGroups,omitempty"`
	Kinds     []string `json:"kinds,omitempty"`
}

func (AnnoKindMatcher) String added in v0.21.0

func (akm AnnoKindMatcher) String() string

type ConvertedLegacyAnnotations added in v0.21.0

type ConvertedLegacyAnnotations struct {
	Title       string         `json:"title,omitempty"`
	Description string         `json:"description,omitempty"`
	Custom      map[string]any `json:"custom,omitempty"`
}

ConvertedLegacyAnnotations holds OPA Metadata Annotations, which were converted from legacy style annotations

type KindMatcher added in v0.8.0

type KindMatcher struct {
	APIGroup string
	Kinds    []string
}

KindMatcher is the matcher to generate `constraints.spec.match.kinds`

type KindMatchers added in v0.10.0

type KindMatchers []KindMatcher

KindMatchers is a slice of KindMatcher

func (KindMatchers) String added in v0.10.0

func (k KindMatchers) String() string

func (KindMatchers) ToSpec added in v0.21.0

func (k KindMatchers) ToSpec() []any

ToSpec converts KindMatchers to a slice in format compatible with `spec.match.kinds` of a Constraint

type MatchExpressionMatcher added in v0.19.0

type MatchExpressionMatcher struct {
	Key      string   `json:"key"`
	Operator string   `json:"operator"`
	Values   []string `json:"values,omitempty"`
}

MatchExpressionsMatcher is the matcher to generate `constraints.spec.match.labelSelector.matchExpressions`.

type MatchLabelsMatcher added in v0.10.0

type MatchLabelsMatcher map[string]string

MatchLabelsMatcher is the matcher to generate `constraints.spec.match.labelSelector.matchLabels`.

func (MatchLabelsMatcher) String added in v0.10.0

func (m MatchLabelsMatcher) String() string

type Matchers added in v0.8.0

type Matchers struct {
	KindMatchers             KindMatchers
	MatchLabelsMatcher       MatchLabelsMatcher
	MatchExpressionsMatcher  []MatchExpressionMatcher
	NamespaceMatcher         []string
	ExcludedNamespaceMatcher []string
}

Matchers are all of the matchers that can be applied to constraints.

type MetaData added in v0.24.0

type MetaData struct {
	Annotations map[string]string
	Labels      map[string]string
}

type Parameter added in v0.9.0

type Parameter struct {
	Name        string
	Type        string
	IsArray     bool
	Description string
}

Parameter represents a parameter that the policy uses

type Rego added in v0.8.0

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

Rego represents a parsed rego file.

func GetAllSeverities added in v0.8.0

func GetAllSeverities(directory string) ([]Rego, error)

GetAllSeverities gets all of the rego files found in the given directory as well as any subdirectories. Only rego files that contain a valid severity will be returned.

func GetAllSeveritiesWithoutImports added in v0.14.2

func GetAllSeveritiesWithoutImports(directory string) ([]Rego, error)

GetAllSeveritiesWithoutImports gets all of the Rego files found in the given directory as well as any subdirectories, but does not attempt to parse the imports.

func GetViolations added in v0.8.0

func GetViolations(directory string) ([]Rego, error)

GetViolations gets all of the files found in the given directory as well as any subdirectories. Only rego files that have a severity of violation will be returned.

func (Rego) AnnotationExcludedNamespaceMatchers added in v0.21.0

func (r Rego) AnnotationExcludedNamespaceMatchers() []string

func (Rego) AnnotationKindMatchers added in v0.21.0

func (r Rego) AnnotationKindMatchers() []AnnoKindMatcher

func (Rego) AnnotationLabelSelectorMatcher added in v0.21.0

func (r Rego) AnnotationLabelSelectorMatcher() *metav1.LabelSelector

func (Rego) AnnotationNamespaceMatchers added in v0.21.0

func (r Rego) AnnotationNamespaceMatchers() []string

func (Rego) AnnotationParameters added in v0.21.0

func (r Rego) AnnotationParameters() map[string]apiextensionsv1.JSONSchemaProps

func (Rego) Annotations added in v0.24.0

func (r Rego) Annotations() map[string]string

Annotations returns the annotations found in the header comment of the rego file.

func (Rego) ConvertLegacyAnnotations added in v0.21.0

func (r Rego) ConvertLegacyAnnotations() (*ConvertedLegacyAnnotations, error)

ConvertLegacyAnnotations converts legacy annotations to ConvertedLegacyAnnotations

func (Rego) Dependencies added in v0.8.0

func (r Rego) Dependencies() []string

Dependencies returns all of the source for the rego files that this rego file depends on.

func (Rego) Description added in v0.8.0

func (r Rego) Description() string

Description returns the entire description found in the header comment of the Rego file.

func (Rego) Enforcement added in v0.8.0

func (r Rego) Enforcement() string

Enforcement returns the enforcement action in the header comment. Defaults to deny if no enforcement action is specified.

func (Rego) FullSource added in v0.15.0

func (r Rego) FullSource() string

FullSource returns the original source code inside of the rego file including comments except the header

func (Rego) GetAnnotation added in v0.21.0

func (r Rego) GetAnnotation(name string) (any, bool)

func (Rego) GetOpenAPISchemaProperties added in v0.21.0

func (r Rego) GetOpenAPISchemaProperties() map[string]apiextensionsv1.JSONSchemaProps

func (Rego) HasMetadataAnnotations added in v0.21.0

func (r Rego) HasMetadataAnnotations() bool

HasMetadataAnnotations checks whether rego file has OPA Metadata Annotations

func (Rego) Kind added in v0.8.0

func (r Rego) Kind() string

Kind returns the Kubernetes Kind of the rego file. The kind of the rego file is determined by the name of the directory that the rego file exists in.

func (Rego) Labels added in v0.24.0

func (r Rego) Labels() map[string]string

Labels returns the labels found in the header comment of the rego file.

func (Rego) LegacyConversionSource added in v0.21.0

func (r Rego) LegacyConversionSource() string

LegacyConversionSource returns the original source code with comments except header, but doesn't trim any trailing whitespace

func (Rego) Matchers added in v0.8.0

func (r Rego) Matchers() (Matchers, error)

Matchers returns all of the matchers found in the rego file.

func (Rego) Name added in v0.8.0

func (r Rego) Name() string

Name returns the name of the rego file. The name of the rego file is its kind as lowercase.

func (Rego) Parameters added in v0.9.0

func (r Rego) Parameters() []Parameter

Parameters returns the list of parsed parameters

func (Rego) Path added in v0.8.0

func (r Rego) Path() string

Path returns the original path of the rego file.

func (Rego) PolicyID added in v0.9.0

func (r Rego) PolicyID() string

PolicyID returns the identifier of the policy. The returned value will be a blank string if an id was not specified in the policy body.

func (Rego) Severity added in v0.8.0

func (r Rego) Severity() Severity

Severity returns the severity of the rego file. When a rego file has multiple rules that are considered to be different severities, the first rule is chosen.

func (Rego) SkipConstraint added in v0.12.0

func (r Rego) SkipConstraint() bool

SkipConstraint returns whether or not the generation of the Constraint should be skipped. It is only set to true when the @skip-constraint tag is present in the comment header block

func (Rego) SkipTemplate added in v0.22.0

func (r Rego) SkipTemplate() bool

SkipTemplate returns whether or not the generation of the Template should be skipped. It is only set to true when the @skip-template tag is present in the comment header block

func (Rego) Source added in v0.8.0

func (r Rego) Source() string

Source returns the original source code inside of the rego file without any comments.

func (Rego) Title added in v0.8.0

func (r Rego) Title() string

Title returns the title found in the header comment of the rego file.

type Severity added in v0.8.0

type Severity string

Severity describes the severity level of the rego file.

const (
	Violation Severity = "Violation"
	Warning   Severity = "Warning"

	// PolicyIDVariable is the name of the variable that contains the policy identifier
	PolicyIDVariable = "policyID"
)

The defined severity levels represent the valid severity levels that a rego file can have.

Jump to

Keyboard shortcuts

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