engine

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 30 Imported by: 4

Documentation

Index

Constants

View Source
const TemplateContextPathScopeKey = "konveyor.io/path-scope"

Variables

This section is empty.

Functions

func ConvertToUTF8 added in v0.9.0

func ConvertToUTF8(content []byte, encodingName string) ([]byte, error)

func GetEncodingFromName added in v0.9.0

func GetEncodingFromName(encodingName string) (encoding.Encoding, error)

TODO: add more encodings

func OpenFileWithEncoding added in v0.9.0

func OpenFileWithEncoding(filePath string, encodingName string) ([]byte, error)

Types

type AndCondition

type AndCondition struct {
	Conditions []ConditionEntry `yaml:"and"`
}

func (AndCondition) Evaluate

type ChainTemplate

type ChainTemplate struct {
	Filepaths     []string               `yaml:"filepaths,omitempty" json:"filepaths,omitempty"`
	Extras        map[string]interface{} `yaml:"extras,omitempty" json:"extras,omitempty"`
	ExcludedPaths []string               `yaml:"excludedPaths,omitempty" json:"excludedPaths,omitempty"`
}

Chain Templates are used by rules and providers to pass context around during rule execution.

func (*ChainTemplate) FilterIncidentsByFilePaths added in v0.7.0

func (c *ChainTemplate) FilterIncidentsByFilePaths(incidents []IncidentContext) []IncidentContext

func (*ChainTemplate) ToMap added in v0.9.0

func (c *ChainTemplate) ToMap() map[string]interface{}

ToMap converts the ChainTemplate to a map suitable for mustache template rendering. All fields are always exposed (even if empty) to ensure templates can reliably reference them without worrying about undefined values.

type CodeSnip

type CodeSnip interface {
	GetCodeSnip(uri.URI, Location) (string, error)
}

type ConditionContext

type ConditionContext struct {
	Tags     map[string]interface{}   `yaml:"tags"`
	Template map[string]ChainTemplate `yaml:"template"`
	RuleID   string                   `yaml:"ruleID"`
}

func (*ConditionContext) Copy added in v0.7.0

This will copy the condition, but this will not copy the ruleID

type ConditionEntry

type ConditionEntry struct {
	From                   string
	As                     string
	Ignorable              bool
	Not                    bool
	ProviderSpecificConfig Conditional
}

func (ConditionEntry) Evaluate

type ConditionResponse

type ConditionResponse struct {
	Matched bool `yaml:"matched"`
	// For each time the condition is hit, add all of the context.
	// keys here, will be used in the message.
	Incidents       []IncidentContext      `yaml:"incidents"`
	TemplateContext map[string]interface{} `yaml:",inline"`
}

type Conditional

type Conditional interface {
	Evaluate(ctx context.Context, log logr.Logger, condCtx ConditionContext) (ConditionResponse, error)
}

type CustomVariable

type CustomVariable struct {
	Pattern            *regexp.Regexp `yaml:"pattern"`
	Name               string         `yaml:"name"`
	DefaultValue       string         `yaml:"defaultValue"`
	NameOfCaptureGroup string         `yaml:"nameOfCaptureGroup"`
}

type IncidentContext

type IncidentContext struct {
	FileURI      uri.URI                `yaml:"fileURI"`
	Effort       *int                   `yaml:"effort"`
	LineNumber   *int                   `yaml:"lineNumber,omitempty"`
	Variables    map[string]interface{} `yaml:"variables"`
	Links        []konveyor.Link        `yaml:"externalLink"`
	CodeLocation *Location              `yaml:"location,omitempty"`
}

type Location

type Location struct {
	StartPosition Position `yaml:"startPosition"`
	EndPosition   Position `yaml:"endPosition"`
}

type Message

type Message struct {
	Text  *string         `yaml:"message,omitempty"`
	Links []konveyor.Link `yaml:"links,omitempty"`
}

type Option

type Option func(engine *ruleEngine)

func WithCodeSnipLimit

func WithCodeSnipLimit(i int) Option

func WithContextLines

func WithContextLines(i int) Option

func WithEncoding added in v0.9.0

func WithEncoding(encoding string) Option

func WithIncidentLimit

func WithIncidentLimit(i int) Option

func WithIncidentSelector

func WithIncidentSelector(selector string) Option

func WithLocationPrefixes added in v0.3.1

func WithLocationPrefixes(location []string) Option

type OrCondition

type OrCondition struct {
	Conditions []ConditionEntry `yaml:"or"`
}

func (OrCondition) Evaluate

func (o OrCondition) Evaluate(ctx context.Context, log logr.Logger, condCtx ConditionContext) (ConditionResponse, error)

type Perform

type Perform struct {
	Message Message  `yaml:",inline"`
	Tag     []string `yaml:"tag,omitempty"`
}

func (*Perform) Validate

func (p *Perform) Validate() error

type Position

type Position struct {
	/*Line defined:
	 * Line position in a document (zero-based).
	 * If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document.
	 * If a line number is negative, it defaults to 0.
	 */
	Line int `yaml:"line"`

	/*Character defined:
	 * Character offset on a line in a document (zero-based). Assuming that the line is
	 * represented as a string, the `character` value represents the gap between the
	 * `character` and `character + 1`.
	 *
	 * If the character value is greater than the line length it defaults back to the
	 * line length.
	 * If a line number is negative, it defaults to 0.
	 */
	Character int `yaml:"character"`
}

type Rule

type Rule struct {
	RuleMeta        `yaml:",inline" json:",inline"`
	Perform         Perform          `yaml:",inline" json:"perform,omitempty"`
	When            Conditional      `yaml:"when,omitempty" json:"when,omitempty"`
	Snipper         CodeSnip         `yaml:"-" json:"-"`
	CustomVariables []CustomVariable `yaml:"customVariables,omitempty" json:"customVariables,omitempty"`
}

type RuleEngine

type RuleEngine interface {
	// RunRules runs the given rulesets with optional selectors
	RunRules(context context.Context, rules []RuleSet, selectors ...RuleSelector) []konveyor.RuleSet

	// RunRulesWithOptions runs the given rulesets with run-specific options (e.g., progress reporter) and selectors
	RunRulesWithOptions(context context.Context, rules []RuleSet, opts []RunOption, selectors ...RuleSelector) []konveyor.RuleSet

	// RunRulesScoped runs the given rulesets with a scope and optional selectors
	RunRulesScoped(ctx context.Context, ruleSets []RuleSet, scopes Scope, selectors ...RuleSelector) []konveyor.RuleSet

	// RunRulesScopedWithOptions runs the given rulesets with a scope, run-specific options, and selectors
	RunRulesScopedWithOptions(ctx context.Context, ruleSets []RuleSet, scopes Scope, opts []RunOption, selectors ...RuleSelector) []konveyor.RuleSet

	// Stop stops the rule engine and waits for all workers to complete
	Stop()
}

RuleEngine is the interface for running analysis rules

func CreateRuleEngine

func CreateRuleEngine(ctx context.Context, workers int, log logr.Logger, options ...Option) RuleEngine

type RuleMeta

type RuleMeta struct {
	RuleID      string             `yaml:"ruleID,omitempty" json:"ruleID,omitempty"`
	Description string             `yaml:"description,omitempty" json:"description,omitempty"`
	Category    *konveyor.Category `yaml:"category,omitempty" json:"category,omitempty"`
	Labels      []string           `yaml:"labels,omitempty" json:"labels,omitempty"`
	Effort      *int               `json:"effort,omitempty"`
	UsesHasTags bool
}

func (*RuleMeta) GetLabels

func (r *RuleMeta) GetLabels() []string

type RuleSelector

type RuleSelector interface {
	Matches(*RuleMeta) (bool, error)
}

RuleSelector selects rules based on rule metadata

type RuleSet

type RuleSet struct {
	Name        string   `json:"name,omitempty" yaml:"name,omitempty"`
	Description string   `json:"description,omitempty" yaml:"description,omitempty"`
	Labels      []string `json:"labels,omitempty" yaml:"labels,omitempty"`
	Tags        []string `json:"tags,omitempty" yaml:"tags,omitempty"`
	Rules       []Rule   `json:"rules,omitempty" yaml:"rules,omitempty"`
}

type RunOption added in v0.9.0

type RunOption func(*runConfig)

RunOption configures options for a specific RunRules invocation

func WithProgressReporter added in v0.9.0

func WithProgressReporter(reporter progress.ProgressReporter) RunOption

WithProgressReporter sets the progress reporter for this run

type Scope added in v0.7.0

type Scope interface {
	Name() string
	// For now this is the only place that we are considering adding a scope
	// in the future, we could scope other things
	AddToContext(*ConditionContext) error
	FilterResponse(IncidentContext) bool
}

Scopes apply to individual calls to the providers and will add inforamtion to the ConditionContext To apply the scope. It is the responsiblity of the provider to use these correctly.

func ExcludedPathsScope added in v0.7.0

func ExcludedPathsScope(paths []string, log logr.Logger) Scope

func IncludedPathsScope added in v0.7.0

func IncludedPathsScope(paths []string, log logr.Logger) Scope

func NewScope added in v0.7.0

func NewScope(scopes ...Scope) Scope

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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