analyzer

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDir

func IsDir(path string) bool

func Ptr

func Ptr[T any](v T) *T

func SaveFindingResult

func SaveFindingResult(result UploadFindingResponse) error

Types

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

func (*Analyzer) RegisterHandler

func (analyzer *Analyzer) RegisterHandler(handler Handler)

func (*Analyzer) RegisterSourceManager

func (analyzer *Analyzer) RegisterSourceManager(sourceManager git.GitEnv)

type ChangedFile

type ChangedFile struct {
	From   string            `json:"from"`
	To     string            `json:"to"`
	Status ChangedFileStatus `json:"status"`
}

func FromObjectChanges

func FromObjectChanges(changes object.Changes) []ChangedFile

type ChangedFileStatus

type ChangedFileStatus string
const Add ChangedFileStatus = "Add"
const Delete ChangedFileStatus = "Delete"
const Modify ChangedFileStatus = "Modify"

type CiScanInfo

type CiScanInfo struct {
	ScanId        string `json:"scanId"`
	ScanUrl       string `json:"scanUrl"`
	LastCommitSha string `json:"lastCommitSha"`
}

type CiScanRequest

type CiScanRequest struct {
	Source         string      `json:"source"`
	RepoId         string      `json:"repoId"`
	RepoUrl        string      `json:"repoUrl"`
	RepoName       string      `json:"repoName"`
	GitAction      GitAction   `json:"gitAction"`
	ScanTitle      string      `json:"scanTitle"`
	CommitHash     string      `json:"commitHash"`
	CommitBranch   string      `json:"commitBranch"`
	TargetBranch   string      `json:"targetBranch"`
	MergeRequestId string      `json:"mergeRequestId"`
	Scanner        string      `json:"scanner"`
	Type           ScannerType `json:"type"`
	JobUrl         string      `json:"jobUrl"`
	IsDefault      *bool       `json:"isDefault"`
}

type Client

type Client struct {
	UserAgent string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseUrl string, apiKey string) *Client

func (*Client) InitScan

func (client *Client) InitScan(request CiScanRequest) (*CiScanInfo, error)

func (*Client) Request

func (client *Client) Request() *resty.Request

func (*Client) TestConnection

func (client *Client) TestConnection() bool

func (*Client) UpdateScan

func (client *Client) UpdateScan(scanId string, request UpdateCIScanRequest) error

func (*Client) UploadDependency

func (client *Client) UploadDependency(request UploadDependencyRequest) (*UploadDependencyResponse, error)

func (*Client) UploadFinding

func (client *Client) UploadFinding(request UploadFindingRequest) (*UploadFindingResponse, error)

type FindingLocation

type FindingLocation struct {
	Path        string `json:"path,omitempty"`
	Snippet     string `json:"snippet,omitempty"`
	StartLine   int    `json:"startLine,omitempty"`
	EndLine     int    `json:"endLine,omitempty"`
	StartColumn int    `json:"startColumn,omitempty"`
	EndColumn   int    `json:"endColumn,omitempty"`
}

func (*FindingLocation) String

func (location *FindingLocation) String() string

type FindingMetadata

type FindingMetadata struct {
	FindingFlow []FindingLocation `json:"findingFlow,omitempty"`
	Cwes        []string          `json:"cwes,omitempty"`
	References  []string          `json:"references,omitempty"`
	Cvss        *string           `json:"cvss,omitempty"`
	CvssScore   *string           `json:"cvssScore,omitempty"`
}

type GitAction

type GitAction string
const (
	GitCommitBranch GitAction = "CommitBranch"
	GitMergeRequest GitAction = "MergeRequest"
	GitCommitTag    GitAction = "CommitTag"
)

type HandleSastFindingPros

type HandleSastFindingPros struct {
	Result        SastResult
	Strategy      ScanStrategy
	ChangedFiles  []ChangedFile
	SourceManager git.GitEnv
}

type Handler

type Handler interface {
	OnStart(source git.GitEnv, scannerName string, scannerType ScannerType) (*CiScanInfo, error)
	OnCompleted()
	OnError(err error)
	HandleSastFindings(input HandleSastFindingPros)
	HandleSCA(sourceManager git.GitEnv, result ScaResult)
}

func GetHandler

func GetHandler() Handler

type LocalHandler

type LocalHandler struct{}

func NewLocalHandler

func NewLocalHandler() *LocalHandler

func (*LocalHandler) HandleSCA

func (handler *LocalHandler) HandleSCA(sourceManager git.GitEnv, result ScaResult)

func (*LocalHandler) HandleSastFindings

func (handler *LocalHandler) HandleSastFindings(input HandleSastFindingPros)

func (*LocalHandler) OnCompleted

func (handler *LocalHandler) OnCompleted()

func (*LocalHandler) OnError

func (handler *LocalHandler) OnError(err error)

func (*LocalHandler) OnStart

func (handler *LocalHandler) OnStart(sourceManager git.GitEnv, scannerName string, scannerType ScannerType) (*CiScanInfo, error)

type Package

type Package struct {
	Id       *string `json:"id,omitempty"`
	PkgId    string  `json:"pkgId,omitempty"`
	Group    string  `json:"group,omitempty"`
	Name     string  `json:"name,omitempty"`
	Version  string  `json:"version,omitempty"`
	Type     string  `json:"type,omitempty"`
	License  string  `json:"license,omitempty"`
	Location *string `json:"location,omitempty"`
}

type PackageDependency

type PackageDependency struct {
	PkgId        string   `json:"pkgId,omitempty"`
	Dependencies []string `json:"dependencies,omitempty"`
}

type PackageInfo

type PackageInfo struct {
	Package         Package         `json:"package"`
	Vulnerabilities []Vulnerability `json:"vulnerabilities"`
}

type RemoteHandler

type RemoteHandler struct {
	// contains filtered or unexported fields
}

func NewRemoteHandler

func NewRemoteHandler(codeSecureServer, codeSecureToken string) (*RemoteHandler, error)

func (*RemoteHandler) HandleSCA

func (handler *RemoteHandler) HandleSCA(sourceManager git.GitEnv, result ScaResult)

func (*RemoteHandler) HandleSastFindings

func (handler *RemoteHandler) HandleSastFindings(input HandleSastFindingPros)

func (*RemoteHandler) OnCompleted

func (handler *RemoteHandler) OnCompleted()

func (*RemoteHandler) OnError

func (handler *RemoteHandler) OnError(err error)

func (*RemoteHandler) OnStart

func (handler *RemoteHandler) OnStart(sourceManager git.GitEnv, scannerName string, scannerType ScannerType) (*CiScanInfo, error)

type SastAnalyzer

type SastAnalyzer struct {
	Analyzer
	// contains filtered or unexported fields
}

SastAnalyzer start

func NewSastAnalyzer

func NewSastAnalyzer(option SastAnalyzerOption) *SastAnalyzer

func (*SastAnalyzer) RegisterScanner

func (analyzer *SastAnalyzer) RegisterScanner(scanner SastScanner)

func (*SastAnalyzer) Run

func (analyzer *SastAnalyzer) Run()

type SastAnalyzerOption

type SastAnalyzerOption struct {
	ProjectPath string
	Scanner     SastScanner
}

type SastFinding

type SastFinding struct {
	ID             string           `json:"id,omitempty"`
	RuleID         string           `json:"ruleId,omitempty" json:"ruleID,omitempty"`
	Identity       string           `json:"identity,omitempty" json:"identity,omitempty"`
	Name           string           `json:"name,omitempty" json:"name,omitempty"`
	Description    string           `json:"description,omitempty" json:"description,omitempty"`
	Category       string           `json:"category,omitempty" json:"category,omitempty"`
	Recommendation string           `json:"recommendation,omitempty" json:"recommendation,omitempty"`
	Severity       Severity         `json:"severity,omitempty" json:"severity,omitempty"`
	Location       *FindingLocation `json:"location,omitempty" json:"location,omitempty"`
	Metadata       *FindingMetadata `json:"metadata,omitempty" json:"metadata,omitempty"`
}

type SastResult

type SastResult struct {
	Findings []SastFinding
}

type SastScanner

type SastScanner interface {
	Name() string
	Type() ScannerType
	Scan(option ScanOption) (*SastResult, error)
}

type ScaAnalyzer

type ScaAnalyzer struct {
	Analyzer
	// contains filtered or unexported fields
}

ScaAnalyzer start

func NewScaAnalyzer

func NewScaAnalyzer() *ScaAnalyzer

func (*ScaAnalyzer) RegisterScanner

func (analyzer *ScaAnalyzer) RegisterScanner(scanner ScaScanner)

func (*ScaAnalyzer) Run

func (analyzer *ScaAnalyzer) Run()

type ScaResult

type ScaResult struct {
	Packages            []Package
	PackageDependencies []PackageDependency
	Vulnerabilities     []Vulnerability
}

type ScaScanner

type ScaScanner interface {
	Name() string
	Type() ScannerType
	Scan() (*ScaResult, error)
}

type ScanOption

type ScanOption struct {
	ChangedFiles      []ChangedFile
	ScanStrategy      ScanStrategy
	BaseLineCommitSha string
}

type ScanStatus

type ScanStatus string
const (
	StatusCompleted ScanStatus = "Completed"
	StatusRunning   ScanStatus = "Running"
	StatusError     ScanStatus = "Error"
)

type ScanStrategy

type ScanStrategy string
const (
	AllFiles        ScanStrategy = "AllFiles"
	ChangedFileOnly ScanStrategy = "ChangedFileOnly"
)

func (ScanStrategy) String

func (a ScanStrategy) String() string

type ScannerType

type ScannerType string
const (
	ScannerTypeSast            ScannerType = "Sast"
	ScannerTypeDast            ScannerType = "Dast"
	ScannerTypeIast            ScannerType = "Iast"
	ScannerTypeDependency      ScannerType = "Dependency"
	ScannerTypeContainer       ScannerType = "Container"
	ScannerTypeSecretDetection ScannerType = "Secret"
)

type Severity

type Severity string
const (
	SeverityCritical Severity = "Critical"
	SeverityHigh     Severity = "High"
	SeverityMedium   Severity = "Medium"
	SeverityLow      Severity = "Low"
	SeverityInfo     Severity = "Info"
)

type UpdateCIScanRequest

type UpdateCIScanRequest struct {
	Status      *ScanStatus `json:"status,omitempty"`
	Description *string     `json:"description,omitempty"`
}

type UploadDependencyRequest

type UploadDependencyRequest struct {
	ScanId              string              `json:"scanId,omitempty"`
	Packages            []Package           `json:"packages,omitempty"`
	PackageDependencies []PackageDependency `json:"packageDependencies,omitempty"`
	Vulnerabilities     []Vulnerability     `json:"vulnerabilities,omitempty"`
}

type UploadDependencyResponse

type UploadDependencyResponse struct {
	Packages []PackageInfo `json:"packages,omitempty"`
	IsBlock  bool          `json:"isBlock,omitempty"`
}

type UploadFindingRequest

type UploadFindingRequest struct {
	ScanId       string        `json:"scanId,omitempty"`
	Findings     []SastFinding `json:"findings,omitempty"`
	Strategy     ScanStrategy  `json:"strategy,omitempty"`
	ChangedFiles []ChangedFile `json:"changedFiles,omitempty"`
}

type UploadFindingResponse

type UploadFindingResponse struct {
	FindingUrl        string        `json:"findingUrl,omitempty"`
	NewFindings       []SastFinding `json:"newFindings,omitempty"`
	ConfirmedFindings []SastFinding `json:"confirmedFindings,omitempty"`
	OpenFindings      []SastFinding `json:"openFindings,omitempty"`
	FixedFindings     []SastFinding `json:"fixedFindings,omitempty"`
	IsBlock           bool          `json:"isBlock,omitempty"`
}

type Vulnerability

type Vulnerability struct {
	Identity     string
	Name         string
	Description  string
	FixedVersion string
	Severity     Severity
	PkgId        string
	PkgName      string
	PublishedAt  *string
	Metadata     *FindingMetadata
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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