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 (*Rule) CompileMatch ¶
CompileMatch compiles the rule's match expression into a CEL program.
func (*Rule) GetProfile ¶
func (*Rule) MatchFiles ¶
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.