2020-02-21 13:56:09 +02:00
// Code generated by piper's step-generator. DO NOT EDIT.
2019-12-13 11:55:45 +02:00
package cmd
import (
2020-01-31 15:06:08 +02:00
"fmt"
2019-12-13 11:55:45 +02:00
"os"
2020-01-31 15:06:08 +02:00
"time"
2019-12-13 11:55:45 +02:00
"github.com/SAP/jenkins-library/pkg/config"
"github.com/SAP/jenkins-library/pkg/log"
2020-01-29 14:17:54 +02:00
"github.com/SAP/jenkins-library/pkg/telemetry"
2019-12-13 11:55:45 +02:00
"github.com/spf13/cobra"
)
type detectExecuteScanOptions struct {
2020-10-01 13:34:51 +02:00
Token string ` json:"token,omitempty" `
2020-07-30 10:35:46 +02:00
CodeLocation string ` json:"codeLocation,omitempty" `
ProjectName string ` json:"projectName,omitempty" `
Scanners [ ] string ` json:"scanners,omitempty" `
ScanPaths [ ] string ` json:"scanPaths,omitempty" `
ScanProperties [ ] string ` json:"scanProperties,omitempty" `
ServerURL string ` json:"serverUrl,omitempty" `
Groups [ ] string ` json:"groups,omitempty" `
FailOn [ ] string ` json:"failOn,omitempty" `
Version string ` json:"version,omitempty" `
VersioningModel string ` json:"versioningModel,omitempty" `
ProjectSettingsFile string ` json:"projectSettingsFile,omitempty" `
GlobalSettingsFile string ` json:"globalSettingsFile,omitempty" `
M2Path string ` json:"m2Path,omitempty" `
2019-12-13 11:55:45 +02:00
}
2020-07-28 10:48:19 +02:00
// DetectExecuteScanCommand Executes Synopsys Detect scan
2019-12-13 11:55:45 +02:00
func DetectExecuteScanCommand ( ) * cobra . Command {
2020-04-28 07:42:02 +02:00
const STEP_NAME = "detectExecuteScan"
2019-12-13 11:55:45 +02:00
metadata := detectExecuteScanMetadata ( )
2020-02-04 11:46:43 +02:00
var stepConfig detectExecuteScanOptions
2020-01-31 15:06:08 +02:00
var startTime time . Time
2020-01-15 13:16:25 +02:00
2019-12-13 11:55:45 +02:00
var createDetectExecuteScanCmd = & cobra . Command {
2020-04-28 07:42:02 +02:00
Use : STEP_NAME ,
2020-07-28 10:48:19 +02:00
Short : "Executes Synopsys Detect scan" ,
Long : ` This step executes [ Synopsys Detect ] ( https : //synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/62423113/Synopsys+Detect) scans.
Synopsys Detect command line utlity can be used to run various scans including BlackDuck and Polaris scans . This step allows users to run BlackDuck scans by default .
Please configure your BlackDuck server Url using the serverUrl parameter and the API token of your user using the apiToken parameter for this step . ` ,
2020-06-23 18:05:21 +02:00
PreRunE : func ( cmd * cobra . Command , _ [ ] string ) error {
2020-01-31 15:06:08 +02:00
startTime = time . Now ( )
2020-04-28 07:42:02 +02:00
log . SetStepName ( STEP_NAME )
2019-12-13 11:55:45 +02:00
log . SetVerbose ( GeneralConfig . Verbose )
2020-04-28 07:42:02 +02:00
path , _ := os . Getwd ( )
fatalHook := & log . FatalHook { CorrelationID : GeneralConfig . CorrelationID , Path : path }
log . RegisterHook ( fatalHook )
err := PrepareConfig ( cmd , & metadata , STEP_NAME , & stepConfig , config . OpenPiperFile )
2020-04-16 14:37:45 +02:00
if err != nil {
2020-06-24 10:04:05 +02:00
log . SetErrorCategory ( log . ErrorConfiguration )
2020-04-16 14:37:45 +02:00
return err
}
2020-10-01 13:34:51 +02:00
log . RegisterSecret ( stepConfig . Token )
2020-05-05 08:36:24 +02:00
if len ( GeneralConfig . HookConfig . SentryConfig . Dsn ) > 0 {
sentryHook := log . NewSentryHook ( GeneralConfig . HookConfig . SentryConfig . Dsn , GeneralConfig . CorrelationID )
log . RegisterHook ( & sentryHook )
}
2020-04-16 14:37:45 +02:00
return nil
2019-12-13 11:55:45 +02:00
} ,
2020-06-23 18:05:21 +02:00
Run : func ( _ * cobra . Command , _ [ ] string ) {
2020-01-31 15:06:08 +02:00
telemetryData := telemetry . CustomData { }
telemetryData . ErrorCode = "1"
handler := func ( ) {
2020-10-26 15:20:04 +02:00
config . RemoveVaultSecretFiles ( )
2020-01-31 15:06:08 +02:00
telemetryData . Duration = fmt . Sprintf ( "%v" , time . Since ( startTime ) . Milliseconds ( ) )
2020-09-29 13:49:40 +02:00
telemetryData . ErrorCategory = log . GetErrorCategory ( ) . String ( )
2020-01-31 15:06:08 +02:00
telemetry . Send ( & telemetryData )
}
log . DeferExitHandler ( handler )
defer handler ( )
2020-04-28 07:42:02 +02:00
telemetry . Initialize ( GeneralConfig . NoTelemetry , STEP_NAME )
2020-02-04 11:46:43 +02:00
detectExecuteScan ( stepConfig , & telemetryData )
2020-01-31 15:06:08 +02:00
telemetryData . ErrorCode = "0"
2020-05-18 21:52:54 +02:00
log . Entry ( ) . Info ( "SUCCESS" )
2019-12-13 11:55:45 +02:00
} ,
}
2020-02-04 11:46:43 +02:00
addDetectExecuteScanFlags ( createDetectExecuteScanCmd , & stepConfig )
2019-12-13 11:55:45 +02:00
return createDetectExecuteScanCmd
}
2020-02-04 11:46:43 +02:00
func addDetectExecuteScanFlags ( cmd * cobra . Command , stepConfig * detectExecuteScanOptions ) {
2020-10-01 13:34:51 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . Token , "token" , os . Getenv ( "PIPER_token" ) , "Api token to be used for connectivity with Synopsis Detect server." )
2020-02-04 11:46:43 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . CodeLocation , "codeLocation" , os . Getenv ( "PIPER_codeLocation" ) , "An override for the name Detect will use for the scan file it creates." )
cmd . Flags ( ) . StringVar ( & stepConfig . ProjectName , "projectName" , os . Getenv ( "PIPER_projectName" ) , "Name of the Synopsis Detect (formerly BlackDuck) project." )
2020-05-25 19:48:59 +02:00
cmd . Flags ( ) . StringSliceVar ( & stepConfig . Scanners , "scanners" , [ ] string { ` signature ` } , "List of scanners to be used for Synopsis Detect (formerly BlackDuck) scan." )
cmd . Flags ( ) . StringSliceVar ( & stepConfig . ScanPaths , "scanPaths" , [ ] string { ` . ` } , "List of paths which should be scanned by the Synopsis Detect (formerly BlackDuck) scan." )
2020-10-06 13:32:52 +02:00
cmd . Flags ( ) . StringSliceVar ( & stepConfig . ScanProperties , "scanProperties" , [ ] string { ` --blackduck.signature.scanner.memory=4096 ` , ` --blackduck.timeout=6000 ` , ` --blackduck.trust.cert=true ` , ` --detect.report.timeout=4800 ` , ` --logging.level.com.synopsys.integration=DEBUG ` , ` --detect.maven.excluded.scopes=test ` } , "Properties passed to the Synopsis Detect (formerly BlackDuck) scan. You can find details in the [Synopsis Detect documentation](https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/622846/Using+Synopsys+Detect+Properties)" )
2020-07-30 09:13:46 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . ServerURL , "serverUrl" , os . Getenv ( "PIPER_serverUrl" ) , "Server URL to the Synopsis Detect (formerly BlackDuck) Server." )
2020-07-28 10:48:19 +02:00
cmd . Flags ( ) . StringSliceVar ( & stepConfig . Groups , "groups" , [ ] string { } , "Users groups to be assigned for the Project" )
cmd . Flags ( ) . StringSliceVar ( & stepConfig . FailOn , "failOn" , [ ] string { ` BLOCKER ` } , "Mark the current build as fail based on the policy categories applied." )
2020-07-27 12:01:59 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . Version , "version" , os . Getenv ( "PIPER_version" ) , "Defines the version number of the artifact being build in the pipeline. It is used as source for the Detect version." )
cmd . Flags ( ) . StringVar ( & stepConfig . VersioningModel , "versioningModel" , ` major ` , "The versioning model used for result reporting (based on the artifact version). Example 1.2.3 using `major` will result in version 1" )
2020-07-30 10:35:46 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . ProjectSettingsFile , "projectSettingsFile" , os . Getenv ( "PIPER_projectSettingsFile" ) , "Path or url to the mvn settings file that should be used as project settings file." )
cmd . Flags ( ) . StringVar ( & stepConfig . GlobalSettingsFile , "globalSettingsFile" , os . Getenv ( "PIPER_globalSettingsFile" ) , "Path or url to the mvn settings file that should be used as global settings file" )
cmd . Flags ( ) . StringVar ( & stepConfig . M2Path , "m2Path" , os . Getenv ( "PIPER_m2Path" ) , "Path to the location of the local repository that should be used." )
2019-12-13 11:55:45 +02:00
2020-10-01 13:34:51 +02:00
cmd . MarkFlagRequired ( "token" )
2019-12-13 11:55:45 +02:00
cmd . MarkFlagRequired ( "projectName" )
2020-07-30 09:13:46 +02:00
cmd . MarkFlagRequired ( "serverUrl" )
2019-12-13 11:55:45 +02:00
}
// retrieve step metadata
func detectExecuteScanMetadata ( ) config . StepData {
var theMetaData = config . StepData {
2020-03-19 18:24:35 +02:00
Metadata : config . StepMetadata {
Name : "detectExecuteScan" ,
Aliases : [ ] config . Alias { } ,
} ,
2019-12-13 11:55:45 +02:00
Spec : config . StepSpec {
Inputs : config . StepInputs {
Parameters : [ ] config . StepParameters {
{
2020-10-01 13:34:51 +02:00
Name : "token" ,
2020-09-16 14:50:09 +02:00
ResourceRef : [ ] config . ResourceReference {
{
Name : "detectTokenCredentialsId" ,
Type : "secret" ,
} ,
2020-10-13 14:14:47 +02:00
{
Name : "" ,
Paths : [ ] string { "$(vaultPath)/detect" , "$(vaultBasePath)/$(vaultPipelineName)/detect" , "$(vaultBasePath)/GROUP-SECRETS/detect" } ,
Type : "vaultSecret" ,
} ,
2020-09-16 14:50:09 +02:00
} ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
2020-10-01 13:34:51 +02:00
Aliases : [ ] config . Alias { { Name : "blackduckToken" } , { Name : "detectToken" } , { Name : "apiToken" } , { Name : "detect/apiToken" } } ,
2019-12-13 11:55:45 +02:00
} ,
{
2020-01-15 13:16:25 +02:00
Name : "codeLocation" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
2019-12-13 11:55:45 +02:00
} ,
{
2020-01-15 13:16:25 +02:00
Name : "projectName" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { { Name : "detect/projectName" } } ,
2019-12-13 11:55:45 +02:00
} ,
{
2020-01-15 13:16:25 +02:00
Name : "scanners" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "[]string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "detect/scanners" } } ,
2019-12-13 11:55:45 +02:00
} ,
{
2020-01-15 13:16:25 +02:00
Name : "scanPaths" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "[]string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "detect/scanPaths" } } ,
2019-12-13 11:55:45 +02:00
} ,
{
2020-01-15 13:16:25 +02:00
Name : "scanProperties" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "[]string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "detect/scanProperties" } } ,
2019-12-13 11:55:45 +02:00
} ,
{
2020-01-15 13:16:25 +02:00
Name : "serverUrl" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
2020-07-30 09:13:46 +02:00
Mandatory : true ,
2020-01-15 13:16:25 +02:00
Aliases : [ ] config . Alias { { Name : "detect/serverUrl" } } ,
2019-12-13 11:55:45 +02:00
} ,
2020-07-28 10:48:19 +02:00
{
Name : "groups" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "[]string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "detect/groups" } } ,
} ,
{
Name : "failOn" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "[]string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "detect/failOn" } } ,
} ,
2020-07-27 12:01:59 +02:00
{
2020-09-16 14:50:09 +02:00
Name : "version" ,
ResourceRef : [ ] config . ResourceReference {
{
Name : "commonPipelineEnvironment" ,
Param : "artifactVersion" ,
} ,
} ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "projectVersion" } , { Name : "detect/projectVersion" } } ,
2020-07-27 12:01:59 +02:00
} ,
{
Name : "versioningModel" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "GENERAL" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
} ,
2020-07-30 10:35:46 +02:00
{
Name : "projectSettingsFile" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "GENERAL" , "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "maven/projectSettingsFile" } } ,
} ,
{
Name : "globalSettingsFile" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "GENERAL" , "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "maven/globalSettingsFile" } } ,
} ,
{
Name : "m2Path" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "GENERAL" , "STEPS" , "STAGES" , "PARAMETERS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "maven/m2Path" } } ,
} ,
2019-12-13 11:55:45 +02:00
} ,
} ,
} ,
}
return theMetaData
}