rule

package
v0.13.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package rules provides functionality for matching files and directories using CEL (Common Expression Language) expressions.

Rules use CEL expressions to determine if a profile should be applied to a given set of files in a directory. The expressions have access to file paths 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   string `validate:"required" yaml:"match"`   // CEL expression to match file paths.
	Profile string `validate:"required" yaml:"profile"` // 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) GetProfile

func (r *Rule) GetProfile() *profile.Profile

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.

func (*Rule) SetProfile

func (r *Rule) SetProfile(p *profile.Profile)

func (*Rule) String

func (r *Rule) String() string

Jump to

Keyboard shortcuts

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