Files
pmg/analyzer/analyzer.go
T

48 lines
891 B
Go
Raw Normal View History

2025-05-14 09:30:43 +05:30
package analyzer
import (
"context"
packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1"
)
// A base interface for all analyzers
type Analyzer interface {
Name() string
}
2025-05-14 18:56:58 +05:30
type Action int
const (
ActionUnknown Action = iota
ActionAllow
ActionConfirm
ActionBlock
)
type PackageVersionAnalysisResult struct {
PackageVersion *packagev1.PackageVersion
// Analyser specific analysis ID
2025-05-14 09:30:43 +05:30
AnalysisID string
2025-05-14 18:56:58 +05:30
2025-05-14 19:08:25 +05:30
// Reference URL for the analysis
ReferenceURL string
2025-05-14 18:56:58 +05:30
// The action to take as recommended by the analyzer
Action Action
// Summary of the analysis
Summary string
// Analyzer specific data
Data any
2025-05-14 09:30:43 +05:30
}
2025-05-14 18:56:58 +05:30
// Contract for implementing package version specific analyzers
type PackageVersionAnalyzer interface {
2025-05-14 09:30:43 +05:30
Analyzer
2025-05-14 18:56:58 +05:30
Analyze(ctx context.Context, packageVersion *packagev1.PackageVersion) (*PackageVersionAnalysisResult, error)
2025-05-14 09:30:43 +05:30
}