2025-05-15 16:50:59 +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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Action int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
ActionUnknown Action = iota
|
|
|
|
|
ActionAllow
|
|
|
|
|
ActionConfirm
|
|
|
|
|
ActionBlock
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PackageVersionAnalysisResult struct {
|
|
|
|
|
PackageVersion *packagev1.PackageVersion
|
|
|
|
|
|
|
|
|
|
// Analyser specific analysis ID
|
|
|
|
|
AnalysisID string
|
|
|
|
|
|
|
|
|
|
// Reference URL for the analysis
|
|
|
|
|
ReferenceURL string
|
|
|
|
|
|
|
|
|
|
// The action to take as recommended by the analyzer
|
|
|
|
|
Action Action
|
|
|
|
|
|
|
|
|
|
// Summary of the analysis
|
|
|
|
|
Summary string
|
|
|
|
|
|
2026-04-10 19:07:15 +05:30
|
|
|
// Whether the package is flagged as malware by inference
|
|
|
|
|
IsMalware bool
|
|
|
|
|
|
|
|
|
|
// Whether the malware verdict has been verified (confirmed by a human or verification system)
|
|
|
|
|
IsVerified bool
|
|
|
|
|
|
2025-05-15 16:50:59 +05:30
|
|
|
// Analyzer specific data
|
|
|
|
|
Data any
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Contract for implementing package version specific analyzers
|
|
|
|
|
type PackageVersionAnalyzer interface {
|
|
|
|
|
Analyzer
|
|
|
|
|
|
|
|
|
|
Analyze(ctx context.Context, packageVersion *packagev1.PackageVersion) (*PackageVersionAnalysisResult, error)
|
|
|
|
|
}
|