Documentation
¶
Index ¶
- Constants
- func Analyze(analyzer Analyzer) *cli.Command
- func Convert(analyzer Analyzer) *cli.Command
- func EliminateRedundancies(notOptimized *report.Report, flagPrependPath string) (*report.Report, error)
- func NewApp(analyzer report.AnalyzerDetails) *cli.App
- func NewCommands(analyzer Analyzer) []*cli.Command
- func Run(analyzer Analyzer) *cli.Command
- func Search(analyzer Analyzer) *cli.Command
- func SerializeJSONToFile(report *report.Report, artifactPath string, flagPrependPath string, ...) error
- func SerializeJSONToWriter(report *report.Report, writer io.Writer, flagPrependPath string, indent bool, ...) error
- type Analysis
- type AnalyzeFunc
- type Analyzer
- type CIVarBlock
- type Config
- func (c Config) AnalyzeAllProjects() bool
- func (c *Config) AnalyzeProject(ctx *cli.Context, path string) (io.ReadCloser, error)
- func (c Config) Category() report.Category
- func (c Config) CertOptions() cacert.ImportOptions
- func (c *Config) ConvertReport(input io.Reader, prependPath string) (*report.Report, error)
- func (c Config) Details() report.AnalyzerDetails
- func (c Config) Flags() []cli.Flag
- func (c Config) GeneratedArtifactName() string
- func (c *Config) LoadRuleset(target string) error
- func (c *Config) MatchProject(path string, info os.FileInfo) (bool, error)
- func (c Config) NewAnalysis() Analysis
- func (c *Config) Ruleset() *ruleset.Config
- func (c Config) ScannerDetails() report.ScannerDetails
- func (c *Config) Serialize(report *report.Report, artifactPath string, flagPrependPath string, ...) error
- type ConvertFunc
- type ErrInvalidArgs
- type RulesetConfigFunc
- type SerializerFunc
Constants ¶
const ( // ArtifactNameSAST holds the default name for SAST tool report file. ArtifactNameSAST = "gl-sast-report.json" // ArtifactNameDependencyScanning holds the default name for Dependency Scanning tool report file. ArtifactNameDependencyScanning = "gl-dependency-scanning-report.json" // ArtifactNameContainerScanning holds the default name for Container Scanning tool report file. ArtifactNameContainerScanning = "gl-container-scanning-report.json" // ArtifactNameSecretDetection holds the default name for Secret Detection tool report file. ArtifactNameSecretDetection = "gl-secret-detection-report.json" // ArtifactNameClusterImageScanning hold the default name for the Cluster Image Scanning report file. ArtifactNameClusterImageScanning = "gl-cluster-image-scanning-report.json" // EnvVarIndentReport is the env var (without prefix) for enabling/disabling indentation EnvVarIndentReport = "ANALYZER_INDENT_REPORT" // EnvVarOptimizeReport is the env var (without prefix) for enabling/disabling optimization EnvVarOptimizeReport = "ANALYZER_OPTIMIZE_REPORT" // EnvVarTargetDir is the env var (without prefix) for setting the analyzer target directory. EnvVarTargetDir = "ANALYZER_TARGET_DIR" // EnvVarArtifactDir is the env var (without prefix) for setting the analyzer artifacts directory. EnvVarArtifactDir = "ANALYZER_ARTIFACT_DIR" // EnvVarCIProjectDir is the env var that holds the project dir path // and usually is propagated from GitLab Runner. It's used as // default value for target directory and artifact directory in case // EnvVarTargetDir or EnvVarArtifactDir are not set. EnvVarCIProjectDir = "CI_PROJECT_DIR" )
Variables ¶
This section is empty.
Functions ¶
func Analyze ¶
func Analyze(analyzer Analyzer) *cli.Command
Analyze returns a cli sub-command that wraps the analyzing the project and generating the report.
func Convert ¶
func Convert(analyzer Analyzer) *cli.Command
Convert returns a cli sub-command that converts the analyzer output into an artifact.
func EliminateRedundancies ¶
func EliminateRedundancies(notOptimized *report.Report, flagPrependPath string) (*report.Report, error)
EliminateRedundancies is a function that helps to remove redundancies automatically from reports these optimizations include: - only include findings that refer to (git) tracked files - remove redundant LineEnd information
func NewApp ¶
func NewApp(analyzer report.AnalyzerDetails) *cli.App
NewApp creates a new cli app with the given details describing the analyzer
func NewCommands ¶
func NewCommands(analyzer Analyzer) []*cli.Command
NewCommands function creates a slice of CLI command structs that contains all required analyzer commands: run, search, analyze, convert.
func Run ¶
func Run(analyzer Analyzer) *cli.Command
Run returns a cli sub-command that implements the full analyzer execution cycle.
func Search ¶
func Search(analyzer Analyzer) *cli.Command
Search returns a cli sub-command that implements project search.
Types ¶
type Analysis ¶
type Analysis interface {
MatchProject(path string, info os.FileInfo) (bool, error)
AnalyzeProject(c *cli.Context, path string) (io.ReadCloser, error)
ConvertReport(input io.Reader, prependPath string) (*report.Report, error)
LoadRuleset(projectPath string) error
Ruleset() *ruleset.Config
Serialize(report *report.Report, artifactPath string, flagPrependPath string, indent bool, optimize bool) error
}
Analysis provides the actions performed in the steps of a command.
type AnalyzeFunc ¶
AnalyzeFunc is a type for a function that runs the analyzer command against the files in project dir and emits the analyzer's output for further processing.
type Analyzer ¶
type Analyzer interface {
Details() report.AnalyzerDetails
GeneratedArtifactName() string
Flags() []cli.Flag
AnalyzeAllProjects() bool
CertOptions() cacert.ImportOptions
Category() report.Category
ScannerDetails() report.ScannerDetails
NewAnalysis() Analysis
}
Analyzer describes the required implementation details an analyzer must provide to generate appropriate CLI commands for it to expose.
type CIVarBlock ¶
CIVarBlock represents one arg with value or a flag from the sequence of args/flags
func ParseCIVar ¶
func ParseCIVar(argStr string) (args []CIVarBlock, invalidArgs []string)
ParseCIVar parses the sequence of arg values/flags that are forwarded to upstream scanners. More detail about this usecase is explained here: https://gitlab.com/gitlab-org/gitlab/-/issues/368565
This function parses `argStr` to sequence args/flags separated by spaces and returns it in a slice of CIVarArg. An arg name is represented with a prefix of `-` or `--`. An arg without value is treated as "CLI flag". Arg's value is represented by placing right after its arg name separated by a space or equals(=).
NOTE: If any char is used as value separator other than space or equal(=), the string will be treated as flag.
Some of the input to output examples:
1. "--arg1" >> CLIArg {name: --arg1, flag: true} 2. "--arg1 val" >> CLIArg {name: --arg1, value: val, flag: false} 3. "--arg1=val" >> CLIArg {name: --arg1, value: val, flag: false} 4. "-flag1" >> CLIArg {name: -flag1, flag: true} 5. "-arg1 val" >> CLIArg {name: -arg1, value: val, flag: false} 6. "-a=val" >> CLIArg {name: -a, value: val, flag: false}
type Config ¶
type Config struct {
Analyzer report.AnalyzerDetails // Details about the analyzer which wraps the scanner
ArtifactName string // Name of the generated artifact
Match search.MatchFunc // Match is a function that detects a compatible project.
Analyze AnalyzeFunc // Analyze is a function that performs the analysis where a project was detected.
AnalyzeFlags []cli.Flag // AnalyzeFlags is a set command line options used by the analyze function (optional).
AnalyzeAll bool // AnalyzeAll instructs the run command to analyze the root directory (false by default).
Convert ConvertFunc // Convert is a function that turns the analyzer output into a compatible artifact.
CACertImportOptions cacert.ImportOptions // CACertImportOptions are options for the import of CA certificates.
LoadRulesetConfig RulesetConfigFunc // LoadRulesetConfig is the method to load the configuration for the ruleset used by the analyzer and report.
RulesetConfig *ruleset.Config // RulesetConfig is the configuration for the ruleset used by the analyzer and report.
Scanner report.ScannerDetails // Scanner contains detailed information about the scanner
ScanType report.Category // ScanType is the type of the scan (container_scanning, dependency_scanning, dast, sast)
Serializer SerializerFunc // Serializer implements a function for serializing and optimizing report output
}
Config struct describes the required implementation details an analyzer must provide to generate appropriate CLI commands for it to expose.
func (Config) AnalyzeAllProjects ¶
AnalyzeAllProjects implements AnalyzerAPI.
func (*Config) AnalyzeProject ¶
func (c *Config) AnalyzeProject(ctx *cli.Context, path string) (io.ReadCloser, error)
AnalyzeProject implements Analysis.
func (Config) CertOptions ¶
func (c Config) CertOptions() cacert.ImportOptions
CertOptions implements AnalyzerAPI.
func (*Config) ConvertReport ¶
ConvertReport implements Analysis.
func (Config) Details ¶
func (c Config) Details() report.AnalyzerDetails
Details implements AnalyzerAPI.
func (Config) GeneratedArtifactName ¶
GeneratedArtifactName implements AnalyzerAPI.
func (*Config) LoadRuleset ¶
LoadRuleset implements Analysis.
func (*Config) MatchProject ¶
MatchProject implements Analysis.
func (Config) NewAnalysis ¶
NewAnalysis implements AnalyzerAPI.
func (Config) ScannerDetails ¶
func (c Config) ScannerDetails() report.ScannerDetails
ScannerDetails implements AnalyzerAPI.
type ConvertFunc ¶
type ConvertFunc func(input io.Reader, prependPath string, rulesetConfig *ruleset.Config) (*report.Report, error)
ConvertFunc is a type for a function that parses the analyzer binary raw output and converts it into the report data structure provided by the library.
type ErrInvalidArgs ¶
type ErrInvalidArgs struct{}
ErrInvalidArgs is an error that occurs when any of the analyzer CLI commands receives unexpected arguments.
func (ErrInvalidArgs) Error ¶
func (e ErrInvalidArgs) Error() string
func (ErrInvalidArgs) ExitCode ¶
func (e ErrInvalidArgs) ExitCode() int
ExitCode returns the analyzer CLI application exit code which should be returned upon analyzer termination when ErrInvalidArgs occurs.
type RulesetConfigFunc ¶
RulesetConfigFunc is a type for a function that loads the analyzer's ruleset from the project dir and returns the Ruleset.