rule

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package rule determines which profile should be used, by using CEL (Common Expression Language) expressions.

The expressions have access to file paths, content, and directory information, allowing for flexible matching logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rule

type Rule struct {

	// Match is a CEL expression to match file paths.
	Match string `json:"match" jsonschema:"title=Match Expression"`
	// Profile is the name of the profile to use when this rule matches.
	Profile string `json:"profile" jsonschema:"title=Profile Name"`
	// contains filtered or unexported fields
}

Rule uses a CEL matcher to determine if its profile should be applied.

CEL expressions have access to variables:

  • `files` (list<string>): All file paths in directory
  • `dir` (string): The directory path being processed

CEL expressions must return a boolean value:

  • files.exists(f, pathExt(f) in [".yaml", ".yml"]) - true if any YAML files exist
  • files.exists(f, pathBase(f) in ["Chart.yaml", "values.yaml"]) - true if Chart or values files exist
  • files.exists(f, pathBase(f) == "Chart.yaml") - true if Chart.yaml exists
  • files.exists(f, !pathBase(f).matches(".*test.*")) - true if non-test files exist
  • files.exists(f, pathBase(f) == "Chart.yaml" && yamlPath(f, "$.apiVersion") == "v2") - true if Helm v2 charts exist
  • false - rule doesn't match

CEL path functions available:

  • pathBase(string): Returns the last element of the path (filename)
  • pathDir(string): Returns all but the last element of the path (directory)
  • pathExt(string): Returns the file extension including the dot
  • yamlPath(file, path): Reads a YAML file and extracts value at path (returns null if not found)

CEL also provides standard functions like `endsWith`, `contains`, `startsWith`, `matches`, along with list functions like `filter`, `exists`, `in`, and logical operators like `&&`, `||`, and `!`.

Use the `in` operator to check membership in lists, e.g.: pathBase(f) in ["Chart.yaml"].

func MustNew

func MustNew(profileName, match string) *Rule

MustNew creates a new rule and panics if there's an error.

func New

func New(profileName, match string) (*Rule, error)

New creates a new rule with the given profile name and match expression.

func (*Rule) CompileMatch

func (r *Rule) CompileMatch() error

CompileMatch compiles the rule's match expression into a CEL program.

func (*Rule) MatchFiles

func (r *Rule) MatchFiles(dirPath string, files []string) bool

MatchFiles evaluates the rule against a collection of files in a directory. This allows CEL expressions to operate on the entire file collection and return a boolean result.

The CEL expression must return a boolean value indicating whether the rule matches.

Jump to

Keyboard shortcuts

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