2020-02-21 12:56:09 +01:00
// Code generated by piper's step-generator. DO NOT EDIT.
2019-12-13 09:55:45 +00:00
package cmd
import (
2020-01-31 14:06:08 +01:00
"fmt"
2019-12-13 09:55:45 +00:00
"os"
2020-01-31 14:06:08 +01:00
"time"
2019-12-13 09:55:45 +00:00
"github.com/SAP/jenkins-library/pkg/config"
"github.com/SAP/jenkins-library/pkg/log"
2020-01-29 13:17:54 +01:00
"github.com/SAP/jenkins-library/pkg/telemetry"
2019-12-13 09:55:45 +00:00
"github.com/spf13/cobra"
)
type detectExecuteScanOptions struct {
APIToken string ` json:"apiToken,omitempty" `
CodeLocation string ` json:"codeLocation,omitempty" `
ProjectName string ` json:"projectName,omitempty" `
ProjectVersion string ` json:"projectVersion,omitempty" `
Scanners [ ] string ` json:"scanners,omitempty" `
ScanPaths [ ] string ` json:"scanPaths,omitempty" `
ScanProperties [ ] string ` json:"scanProperties,omitempty" `
ServerURL string ` json:"serverUrl,omitempty" `
}
// DetectExecuteScanCommand Executes Synopsis Detect scan
func DetectExecuteScanCommand ( ) * cobra . Command {
metadata := detectExecuteScanMetadata ( )
2020-02-04 10:46:43 +01:00
var stepConfig detectExecuteScanOptions
2020-01-31 14:06:08 +01:00
var startTime time . Time
2020-01-15 12:16:25 +01:00
2019-12-13 09:55:45 +00:00
var createDetectExecuteScanCmd = & cobra . Command {
Use : "detectExecuteScan" ,
Short : "Executes Synopsis Detect scan" ,
Long : ` This step executes [Synopsis Detect](https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/62423113/Synopsys+Detect) scans. ` ,
PreRunE : func ( cmd * cobra . Command , args [ ] string ) error {
2020-01-31 14:06:08 +01:00
startTime = time . Now ( )
2019-12-13 09:55:45 +00:00
log . SetStepName ( "detectExecuteScan" )
log . SetVerbose ( GeneralConfig . Verbose )
2020-04-16 14:37:45 +02:00
err := PrepareConfig ( cmd , & metadata , "detectExecuteScan" , & stepConfig , config . OpenPiperFile )
if err != nil {
return err
}
log . RegisterSecret ( stepConfig . APIToken )
return nil
2019-12-13 09:55:45 +00:00
} ,
2020-02-04 10:46:43 +01:00
Run : func ( cmd * cobra . Command , args [ ] string ) {
2020-01-31 14:06:08 +01:00
telemetryData := telemetry . CustomData { }
telemetryData . ErrorCode = "1"
handler := func ( ) {
telemetryData . Duration = fmt . Sprintf ( "%v" , time . Since ( startTime ) . Milliseconds ( ) )
telemetry . Send ( & telemetryData )
}
log . DeferExitHandler ( handler )
defer handler ( )
2020-01-29 13:17:54 +01:00
telemetry . Initialize ( GeneralConfig . NoTelemetry , "detectExecuteScan" )
2020-02-04 10:46:43 +01:00
detectExecuteScan ( stepConfig , & telemetryData )
2020-01-31 14:06:08 +01:00
telemetryData . ErrorCode = "0"
2019-12-13 09:55:45 +00:00
} ,
}
2020-02-04 10:46:43 +01:00
addDetectExecuteScanFlags ( createDetectExecuteScanCmd , & stepConfig )
2019-12-13 09:55:45 +00:00
return createDetectExecuteScanCmd
}
2020-02-04 10:46:43 +01:00
func addDetectExecuteScanFlags ( cmd * cobra . Command , stepConfig * detectExecuteScanOptions ) {
cmd . Flags ( ) . StringVar ( & stepConfig . APIToken , "apiToken" , os . Getenv ( "PIPER_apiToken" ) , "Api token to be used for connectivity with Synopsis Detect server." )
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." )
cmd . Flags ( ) . StringVar ( & stepConfig . ProjectVersion , "projectVersion" , os . Getenv ( "PIPER_projectVersion" ) , "Version of the Synopsis Detect (formerly BlackDuck) project." )
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." )
cmd . Flags ( ) . StringSliceVar ( & stepConfig . ScanProperties , "scanProperties" , [ ] string { "--blackduck.signature.scanner.memory=4096" , "--blackduck.timeout=6000" , "--blackduck.trust.cert=true" , "--detect.policy.check.fail.on.severities=BLOCKER,CRITICAL,MAJOR" , "--detect.report.timeout=4800" , "--logging.level.com.synopsys.integration=DEBUG" } , "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)" )
cmd . Flags ( ) . StringVar ( & stepConfig . ServerURL , "serverUrl" , os . Getenv ( "PIPER_serverUrl" ) , "Server url to the Synopsis Detect (formerly BlackDuck) Server." )
2019-12-13 09:55:45 +00:00
cmd . MarkFlagRequired ( "apiToken" )
cmd . MarkFlagRequired ( "projectName" )
cmd . MarkFlagRequired ( "projectVersion" )
}
// retrieve step metadata
func detectExecuteScanMetadata ( ) config . StepData {
var theMetaData = config . StepData {
2020-03-19 17:24:35 +01:00
Metadata : config . StepMetadata {
Name : "detectExecuteScan" ,
Aliases : [ ] config . Alias { } ,
} ,
2019-12-13 09:55:45 +00:00
Spec : config . StepSpec {
Inputs : config . StepInputs {
Parameters : [ ] config . StepParameters {
{
2020-01-15 12:16:25 +01:00
Name : "apiToken" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { { Name : "detect/apiToken" } } ,
2019-12-13 09:55:45 +00:00
} ,
{
2020-01-15 12:16:25 +01:00
Name : "codeLocation" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
2019-12-13 09:55:45 +00:00
} ,
{
2020-01-15 12:16:25 +01:00
Name : "projectName" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { { Name : "detect/projectName" } } ,
2019-12-13 09:55:45 +00:00
} ,
{
2020-01-15 12:16:25 +01:00
Name : "projectVersion" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { { Name : "detect/projectVersion" } } ,
2019-12-13 09:55:45 +00:00
} ,
{
2020-01-15 12:16:25 +01:00
Name : "scanners" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "[]string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "detect/scanners" } } ,
2019-12-13 09:55:45 +00:00
} ,
{
2020-01-15 12:16:25 +01:00
Name : "scanPaths" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "[]string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "detect/scanPaths" } } ,
2019-12-13 09:55:45 +00:00
} ,
{
2020-01-15 12:16:25 +01:00
Name : "scanProperties" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "[]string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "detect/scanProperties" } } ,
2019-12-13 09:55:45 +00:00
} ,
{
2020-01-15 12:16:25 +01:00
Name : "serverUrl" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "detect/serverUrl" } } ,
2019-12-13 09:55:45 +00:00
} ,
} ,
} ,
} ,
}
return theMetaData
}