provider

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 41 Imported by: 25

Documentation

Index

Constants

View Source
const (
	// Dep source label is a label key that any provider can use, to label the dependencies as coming from a particular source.
	// Examples from java are: open-source and internal. A provider can also have a user provide file that will tell them which
	// depdendencies to label as this value. This label will be used to filter out these dependencies from a given analysis
	DepSourceLabel   = "konveyor.io/dep-source"
	DepLanguageLabel = "konveyor.io/language"
	DepExcludeLabel  = "konveyor.io/exclude"
	// LspServerPath is a provider specific config used to specify path to a LSP server
	LspServerPathConfigKey = "lspServerPath"
	IncludedPathsConfigKey = "includedPaths"
	ExcludedDirsConfigKey  = "excludedDirs"
	EncodingConfigKey      = "encoding"
)
View Source
const (
	JWT_SECRET_ENV_VAR = "JWT_SECRET"
)

Variables

We need to make these Vars, because you can not take a pointer of the constant.

Functions

func FullDepDAGResponse

func FullDepDAGResponse(ctx context.Context, clients []ServiceClient) (map[uri.URI][]DepDAGItem, error)

func FullDepsResponse

func FullDepsResponse(ctx context.Context, clients []ServiceClient) (map[uri.URI][]*Dep, error)

func FullNotifyFileChangesResponse added in v0.7.0

func FullNotifyFileChangesResponse(ctx context.Context, clients []ServiceClient, changes ...FileChange) error

func FullPrepareResponse added in v0.9.0

func FullPrepareResponse(ctx context.Context, clients []ServiceClient, conditionsByCap []ConditionsByCap) error

func GetEncodingFromConfig added in v0.9.0

func GetEncodingFromConfig(i InitConfig) string

func GetExcludedDirsFromConfig added in v0.7.0

func GetExcludedDirsFromConfig(i InitConfig) []string

GetExcludedDirsFromConfig returns directories to exclude from analysis. It starts with sensible defaults (node_modules, vendor, .git, dist, build, target, venv) to prevent "argument list too long" errors when analyzing projects with large dependency directories. User-configured excludes are appended to these defaults. An empty array for excludedDirs explicitly clears the defaults (to analyze everything).

func GetIncludedPathsFromConfig added in v0.5.0

func GetIncludedPathsFromConfig(i InitConfig, allowFilePaths bool) []string

GetIncludedPathsFromConfig returns validated includedPaths from provider settings if allowFilePaths is not set, path to a file is converted into a path to its base dir

func HasCapability

func HasCapability(caps []Capability, name string) bool

func MultilineGrep

func MultilineGrep(ctx context.Context, window int, path, pattern string) (int, error)

MultilineGrep searches for a multi-line pattern in a file and returns line number when matched window determines how many lines to load in mem at a time, uses ctx to abort search on timeout fails when a line in file overflows 64K, returns -1 and error on failure

func NewPrepareProgressReporterAdapter added in v0.9.0

func NewPrepareProgressReporterAdapter(providerName string, reporter PrepareProgressReporter) progress.ProgressReporter

NewPrepareProgressReporterAdapter creates a progress.ProgressReporter from a PrepareProgressReporter. The adapter converts progress.ProgressEvent to PrepareProgressReporter.ReportProgress calls.

Parameters:

  • providerName: Name of the provider (e.g., "java", "nodejs")
  • reporter: The underlying PrepareProgressReporter

Example usage:

adapter := provider.NewPrepareProgressReporterAdapter("java", prepareReporter)
throttled := progress.NewThrottledReporter("provider_prepare", adapter)

func NormalizePathForComparison added in v0.9.0

func NormalizePathForComparison(path string) string

NormalizePathForComparison normalizes a file path for consistent comparison across platforms. It handles:

  • URI schemes (file:///, file:)
  • Path separators (converts backslashes to forward slashes)
  • Case sensitivity (normalizes to lowercase on Windows)
  • Special URI schemes (preserves them as-is, e.g., csharp:)

This function is commonly used when filtering paths or comparing file URIs from LSP servers.

Types

type AnalysisMode

type AnalysisMode string
const (
	FullAnalysisMode       AnalysisMode = "full"
	SourceOnlyAnalysisMode AnalysisMode = "source-only"
)

type BaseClient

type BaseClient interface {
	Capabilities() []Capability
	// Init initiates and returns a service client along with additional init config for the builtin provider
	Init(context.Context, logr.Logger, InitConfig) (ServiceClient, InitConfig, error)
}

type Capability

type Capability struct {
	Name   string
	Input  openapi3.SchemaOrRef
	Output openapi3.SchemaOrRef
}

func ToProviderCap added in v0.4.0

func ToProviderCap(r *openapi3.Reflector, log logr.Logger, input interface{}, name string) (Capability, error)

func ToProviderInputOutputCap added in v0.4.0

func ToProviderInputOutputCap(r *openapi3.Reflector, log logr.Logger, input, output interface{}, name string) (Capability, error)

type Client

type Client interface {
	BaseClient
	ServiceClient
}

type CodeSnipProvider

type CodeSnipProvider struct {
	Providers []engine.CodeSnip
}

func (CodeSnipProvider) GetCodeSnip

func (p CodeSnipProvider) GetCodeSnip(u uri.URI, l engine.Location) (string, error)

type ConditionsByCap added in v0.9.0

type ConditionsByCap struct {
	Cap        string   `json:"cap"`
	Conditions [][]byte `json:"conditions"`
}

type Config

type Config struct {
	Name         string       `yaml:"name,omitempty" json:"name,omitempty"`
	BinaryPath   string       `yaml:"binaryPath,omitempty" json:"binaryPath,omitempty"`
	Address      string       `yaml:"address,omitempty" json:"address,omitempty"`
	UseSocket    bool         `yaml:"useSocket,omitempty" json:"useSocket,omitempty"`
	CertPath     string       `yaml:"certPath,omitempty" json:"certPath,omitempty"`
	JWTToken     string       `yaml:"jwtToken,omitempty" json:"jwtToken,omitempty"`
	Proxy        *Proxy       `yaml:"proxyConfig,omitempty" json:"proxyConfig,omitempty"`
	InitConfig   []InitConfig `yaml:"initConfig,omitempty" json:"initConfig,omitempty"`
	ContextLines int
	// PrepareProgressReporter is an optional interface for reporting progress during Prepare() phase.
	// Used by GRPC providers to report progress during provider initialization.
	PrepareProgressReporter PrepareProgressReporter `yaml:"-" json:"-"`
	LogLevel                *int                    `yaml:"logLevel,omitempty" json:"logLevel,omitempty"`
}

func GetConfig

func GetConfig(filepath string) ([]Config, error)

type Dep

type Dep = konveyor.Dep

func ConvertDagItemsToList

func ConvertDagItemsToList(items []DepDAGItem) []*Dep

Convert Dag Item List to flat list.

type DepDAGItem

type DepDAGItem = konveyor.DepDAGItem

type DependencyCondition

type DependencyCondition struct {
	DependencyConditionCap

	Client Client
}

TODO where should this go

func (DependencyCondition) Evaluate

type DependencyConditionCap added in v0.4.0

type DependencyConditionCap struct {
	Upperbound string `json:"upperbound,omitempty" title:"Upperbound" description:"Match versions lower than or equal to"`
	Lowerbound string `json:"lowerbound,omitempty" title:"Lowerbound" description:"Match versions greater than or equal to"`
	Name       string `json:"name" title:"Name" description:"Name of the dependency"`

	// NameRegex will be a valid go regex that will be used to
	// search the name of a given dependency.
	// Examples include kubernetes* or jakarta-.*-2.2.
	NameRegex string `json:"name_regex,omitempty" title:"NameRegex" description:"Regex pattern to match the name"`
}

type DependencyLocationResolver

type DependencyLocationResolver interface {
	GetLocation(ctx context.Context, dep konveyor.Dep, depFile string) (engine.Location, error)
}
type ExternalLinks struct {
	URL   string `yaml:"url"`
	Title string `yaml:"title"`
}

type FileChange added in v0.7.0

type FileChange struct {
	Path    string
	Content string
	Saved   bool
}

type FileSearcher added in v0.7.0

type FileSearcher struct {
	BasePath string
	// additional search paths can be added e.g. working copy paths
	AdditionalPaths           []string
	ProviderConfigConstraints IncludeExcludeConstraints
	RuleScopeConstraints      IncludeExcludeConstraints
	// fail on first file operation error
	FailFast bool
	Log      logr.Logger
}

FileSearcher takes global include / exclude patterns and base locations for search

func (*FileSearcher) Search added in v0.7.0

func (f *FileSearcher) Search(s SearchCriteria) ([]string, error)

Search searches files using SearchCriteria defining search constraints filters files by inclusion rules, applies exclusion after inclusion constraints take priority in order of - 1. Search time constraints (highest priority) 2. Rule scope constraints 3. Provider config level constraints

type IncidentContext

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

type IncludeExcludeConstraints added in v0.7.0

type IncludeExcludeConstraints struct {
	IncludePathsOrPatterns []string
	ExcludePathsOrPatterns []string
}

type InitConfig

type InitConfig struct {
	// This is the location of the code base that the
	// Provider will be responisble for parsing
	// TODO: rootUri, which is what this maps to in the LSP spec, is deprecated.
	// We should instead use workspaceFolders.
	Location string `yaml:"location,omitempty" json:"location,omitempty"`

	// This is the path to look for the dependencies for the project.
	// It is relative to the Location
	// TODO: This only allows for one directory for dependencies. Use DependencyFolders instead
	DependencyPath string `yaml:"dependencyPath,omitempty" json:"dependencyPath,omitempty"`

	AnalysisMode AnalysisMode `yaml:"analysisMode" json:"analysisMode"`

	// This will have to be defined for each provider
	ProviderSpecificConfig map[string]interface{} `yaml:"providerSpecificConfig,omitempty" json:"providerSpecificConfig,omitempty"`

	Proxy *Proxy `yaml:"proxyConfig,omitempty" json:"proxyConfig,omitempty"`

	// This will be unusable connecting over a network but can be used in code.
	RPC RPCClient `yaml:"-" json:"-"`

	PipeName string `yaml:"pipeName" json:"pipeName"`

	// Given a pipe name for the init config, we will use that pipe and connect to an already inited provider.
	Initialized bool `yaml:"initialized" json:"initialized"`

	// LogLevel for the provider logger verbosity
	LogLevel *int `yaml:"logLevel,omitempty" json:"logLevel,omitempty"`

	// PrepareProgressReporter is an optional interface for reporting progress during Prepare() phase.
	// If provided, the provider will call ReportProgress() as it processes files during symbol cache population.
	PrepareProgressReporter PrepareProgressReporter `yaml:"-" json:"-"`
}

type InternalInit

type InternalInit interface {
	ProviderInit(context.Context, []InitConfig) ([]InitConfig, error)
}

InternalInit interface is going to be used to init the full config of a provider. used by the engine/analyzer to get a provider ready. It takes additional init configs that may be returned by other providers when they are initialized

type InternalProviderClient

type InternalProviderClient interface {
	InternalInit
	Client
}

type Location

type Location struct {
	StartPosition Position
	EndPosition   Position
}

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 float64 `json:"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 float64 `json:"character"`
}

type PrepareProgressEvent added in v0.9.0

type PrepareProgressEvent struct {
	ProviderName   string
	FilesProcessed int
	TotalFiles     int
}

PrepareProgressEvent represents a progress update during Prepare() phase. This struct is used for GRPC streaming between external providers and the main analyzer.

type PrepareProgressReporter added in v0.9.0

type PrepareProgressReporter interface {
	// ReportProgress reports progress for a specific provider.
	// providerName: Name of the provider (e.g., "nodejs", "java")
	// filesProcessed: Number of files processed so far
	// totalFiles: Total number of files to process
	ReportProgress(providerName string, filesProcessed, totalFiles int)
}

PrepareProgressReporter is an interface for reporting progress during the Prepare() phase. Implementations should handle concurrent calls safely as progress updates may come from multiple goroutines.

func NewPrepareProgressAdapter added in v0.9.0

func NewPrepareProgressAdapter(reporter progress.ProgressReporter) PrepareProgressReporter

NewPrepareProgressAdapter creates a PrepareProgressReporter from a progress.ProgressReporter. This adapter converts Prepare() progress updates into ProgressEvents with "provider_prepare" stage.

Example usage:

reporter := progress.NewTextReporter(os.Stderr)
prepareReporter := provider.NewPrepareProgressAdapter(reporter)

initConfig := provider.InitConfig{
    Location: "/path/to/code",
    PrepareProgressReporter: prepareReporter,
}

type PrepareProgressStreamer added in v0.9.0

type PrepareProgressStreamer interface {
	// StartProgressStream creates and returns a channel for streaming progress events.
	// The returned channel will receive progress events during Prepare() phase.
	StartProgressStream() <-chan *PrepareProgressEvent

	// StopProgressStream stops the progress stream and closes the channel.
	StopProgressStream()
}

PrepareProgressStreamer is an optional interface that ServiceClient implementations can provide to support streaming progress events over GRPC.

type ProviderCondition

type ProviderCondition struct {
	Client           ServiceClient
	Capability       string
	ConditionInfo    interface{}
	Rule             engine.Rule
	Ignore           bool
	DepLabelSelector *labels.LabelSelector[*Dep]
}

func (ProviderCondition) Evaluate

func (ProviderCondition) Ignorable

func (p ProviderCondition) Ignorable() bool

type ProviderContext

type ProviderContext struct {
	Tags             map[string]interface{}          `yaml:"tags"`
	Template         map[string]engine.ChainTemplate `yaml:"template"`
	RuleID           string                          `yaml:"ruleID"`
	DepLabelSelector string                          `yaml:"depLabelSelector,omitempty"`
}

func (*ProviderContext) GetScopedFilepaths added in v0.7.0

func (p *ProviderContext) GetScopedFilepaths() (included []string, excluded []string)

type ProviderEvaluateResponse

type ProviderEvaluateResponse struct {
	Matched         bool                   `yaml:"matched"`
	Incidents       []IncidentContext      `yaml:"incidents"`
	TemplateContext map[string]interface{} `yaml:"templateContext"`
}

func FullResponseFromServiceClients

func FullResponseFromServiceClients(ctx context.Context, clients []ServiceClient, cap string, conditionInfo []byte) (ProviderEvaluateResponse, error)

type Proxy

type Proxy httpproxy.Config

func (Proxy) ToEnvVars

func (p Proxy) ToEnvVars() map[string]string

type RPCClient added in v0.7.0

type RPCClient interface {
	Call(context.Context, string, any) *jsonrpc2.AsyncCall
	Notify(context.Context, string, any) error
	Close() error
}

type SearchCriteria added in v0.7.0

type SearchCriteria struct {
	Patterns           []string
	ConditionFilepaths []string
}

SearchCriteria defines a specific search criteria during search time, used for condition specific search this takes the highest priority when searching

type Server

type Server interface {
	// This will start the GRPC server and will wait until the context is cancelled.
	Start(context.Context) error
}

func NewServer

func NewServer(client BaseClient, port int, certPath string, keyPath string, secretKey string, socketPath string, logger logr.Logger) Server

Provider GRPC Service TOOD: HANDLE INIT CONFIG CHANGES

type ServiceClient

type ServiceClient interface {
	// Prepare will pass all conditions to the provider before evaluation
	// so that the provider can pre-process conditions for faster responses
	Prepare(ctx context.Context, conditionsByCap []ConditionsByCap) error

	// Evaluate will evaluate a condition and return a response
	Evaluate(ctx context.Context, cap string, conditionInfo []byte) (ProviderEvaluateResponse, error)

	Stop()

	// GetDependencies will get the dependencies
	// It is the responsibility of the provider to determine how that is done
	GetDependencies(ctx context.Context) (map[uri.URI][]*Dep, error)
	// GetDependencies will get the dependencies and return them as a linked list
	// Top level items are direct dependencies, the rest are indirect dependencies
	GetDependenciesDAG(ctx context.Context) (map[uri.URI][]DepDAGItem, error)
	// Used to notify changes to files in the project
	NotifyFileChanges(ctx context.Context, changes ...FileChange) error
}

For some period of time during POC this will be in tree, in the future we need to write something that can do this w/ external binaries

type Startable

type Startable interface {
	Start(context.Context) error
}

type UnimplementedDependenciesComponent

type UnimplementedDependenciesComponent struct{}

func (*UnimplementedDependenciesComponent) GetDependencies

func (p *UnimplementedDependenciesComponent) GetDependencies(ctx context.Context) (map[uri.URI][]*Dep, error)

We don't have dependencies

func (*UnimplementedDependenciesComponent) GetDependenciesDAG

func (p *UnimplementedDependenciesComponent) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]DepDAGItem, error)

We don't have dependencies

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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