You've already forked sap-jenkins-library
							
							
				mirror of
				https://github.com/SAP/jenkins-library.git
				synced 2025-10-30 23:57:50 +02:00 
			
		
		
		
	detect: add parameter aliases (#2099)
* align parameters for Detect * include feedback * update generation and formatting Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Daniel Kurzynski <daniel.kurzynski@sap.com>
This commit is contained in:
		| @@ -2,9 +2,10 @@ package cmd | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
|  | ||||
| 	piperhttp "github.com/SAP/jenkins-library/pkg/http" | ||||
| 	"github.com/SAP/jenkins-library/pkg/maven" | ||||
| 	"strings" | ||||
|  | ||||
| 	sliceUtils "github.com/SAP/jenkins-library/pkg/piperutils" | ||||
|  | ||||
| @@ -68,7 +69,7 @@ func addDetectArgs(args []string, config detectExecuteScanOptions, fileUtils pip | ||||
| 	args = append(args, config.ScanProperties...) | ||||
|  | ||||
| 	args = append(args, fmt.Sprintf("--blackduck.url=%v", config.ServerURL)) | ||||
| 	args = append(args, fmt.Sprintf("--blackduck.api.token=%v", config.APIToken)) | ||||
| 	args = append(args, fmt.Sprintf("--blackduck.api.token=%v", config.Token)) | ||||
| 	// ProjectNames, VersionName, GroupName etc can contain spaces and need to be escaped using double quotes in CLI | ||||
| 	// Hence the string need to be surrounded by \" | ||||
| 	args = append(args, fmt.Sprintf("--detect.project.name=\\\"%v\\\"", config.ProjectName)) | ||||
|   | ||||
| @@ -14,7 +14,7 @@ import ( | ||||
| ) | ||||
|  | ||||
| type detectExecuteScanOptions struct { | ||||
| 	APIToken            string   `json:"apiToken,omitempty"` | ||||
| 	Token               string   `json:"token,omitempty"` | ||||
| 	CodeLocation        string   `json:"codeLocation,omitempty"` | ||||
| 	ProjectName         string   `json:"projectName,omitempty"` | ||||
| 	Scanners            []string `json:"scanners,omitempty"` | ||||
| @@ -58,7 +58,7 @@ Please configure your BlackDuck server Url using the serverUrl parameter and the | ||||
| 				log.SetErrorCategory(log.ErrorConfiguration) | ||||
| 				return err | ||||
| 			} | ||||
| 			log.RegisterSecret(stepConfig.APIToken) | ||||
| 			log.RegisterSecret(stepConfig.Token) | ||||
|  | ||||
| 			if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { | ||||
| 				sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) | ||||
| @@ -89,7 +89,7 @@ Please configure your BlackDuck server Url using the serverUrl parameter and the | ||||
| } | ||||
|  | ||||
| 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.Token, "token", os.Getenv("PIPER_token"), "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().StringSliceVar(&stepConfig.Scanners, "scanners", []string{`signature`}, "List of scanners to be used for Synopsis Detect (formerly BlackDuck) scan.") | ||||
| @@ -104,7 +104,7 @@ func addDetectExecuteScanFlags(cmd *cobra.Command, stepConfig *detectExecuteScan | ||||
| 	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.") | ||||
|  | ||||
| 	cmd.MarkFlagRequired("apiToken") | ||||
| 	cmd.MarkFlagRequired("token") | ||||
| 	cmd.MarkFlagRequired("projectName") | ||||
| 	cmd.MarkFlagRequired("serverUrl") | ||||
| } | ||||
| @@ -120,7 +120,7 @@ func detectExecuteScanMetadata() config.StepData { | ||||
| 			Inputs: config.StepInputs{ | ||||
| 				Parameters: []config.StepParameters{ | ||||
| 					{ | ||||
| 						Name: "apiToken", | ||||
| 						Name: "token", | ||||
| 						ResourceRef: []config.ResourceReference{ | ||||
| 							{ | ||||
| 								Name: "detectTokenCredentialsId", | ||||
| @@ -130,7 +130,7 @@ func detectExecuteScanMetadata() config.StepData { | ||||
| 						Scope:     []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:      "string", | ||||
| 						Mandatory: true, | ||||
| 						Aliases:   []config.Alias{{Name: "detect/apiToken"}}, | ||||
| 						Aliases:   []config.Alias{{Name: "blackduckToken"}, {Name: "detectToken"}, {Name: "apiToken"}, {Name: "detect/apiToken"}}, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "codeLocation", | ||||
|   | ||||
| @@ -2,13 +2,14 @@ package cmd | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	piperhttp "github.com/SAP/jenkins-library/pkg/http" | ||||
| 	"github.com/SAP/jenkins-library/pkg/mock" | ||||
| 	"net/http" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"testing" | ||||
|  | ||||
| 	piperhttp "github.com/SAP/jenkins-library/pkg/http" | ||||
| 	"github.com/SAP/jenkins-library/pkg/mock" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| @@ -99,7 +100,7 @@ func TestAddDetectArgs(t *testing.T) { | ||||
| 			options: detectExecuteScanOptions{ | ||||
| 				ScanProperties:  []string{"--scan1=1", "--scan2=2"}, | ||||
| 				ServerURL:       "https://server.url", | ||||
| 				APIToken:        "apiToken", | ||||
| 				Token:           "apiToken", | ||||
| 				ProjectName:     "testName", | ||||
| 				Version:         "1.0", | ||||
| 				VersioningModel: "major-minor", | ||||
| @@ -123,7 +124,7 @@ func TestAddDetectArgs(t *testing.T) { | ||||
| 			args: []string{"--testProp1=1"}, | ||||
| 			options: detectExecuteScanOptions{ | ||||
| 				ServerURL:       "https://server.url", | ||||
| 				APIToken:        "apiToken", | ||||
| 				Token:           "apiToken", | ||||
| 				ProjectName:     "testName", | ||||
| 				Version:         "1.0", | ||||
| 				VersioningModel: "major-minor", | ||||
| @@ -149,7 +150,7 @@ func TestAddDetectArgs(t *testing.T) { | ||||
| 			args: []string{"--testProp1=1"}, | ||||
| 			options: detectExecuteScanOptions{ | ||||
| 				ServerURL:       "https://server.url", | ||||
| 				APIToken:        "apiToken", | ||||
| 				Token:           "apiToken", | ||||
| 				ProjectName:     "testName", | ||||
| 				CodeLocation:    "testLocation", | ||||
| 				FailOn:          []string{"BLOCKER", "MAJOR"}, | ||||
|   | ||||
| @@ -19,9 +19,14 @@ spec: | ||||
|         description: Jenkins 'Secret text' credentials ID containing the API token used to authenticate with the Synopsis Detect (formerly BlackDuck) Server. | ||||
|         type: jenkins | ||||
|     params: | ||||
|       - name: apiToken | ||||
|       - name: token | ||||
|         aliases: | ||||
|           - name: blackduckToken | ||||
|           - name: detectToken | ||||
|           - name: apiToken | ||||
|             deprecated: true | ||||
|           - name: detect/apiToken | ||||
|             deprecated: true | ||||
|         description: Api token to be used for connectivity with Synopsis Detect server. | ||||
|         type: string | ||||
|         mandatory: true | ||||
|   | ||||
| @@ -11,7 +11,7 @@ void call(Map parameters = [:]) { | ||||
|     final script = checkScript(this, parameters) ?: this | ||||
|     parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN) | ||||
|     List credentials = [ | ||||
|         [type: 'token', id: 'detectTokenCredentialsId', env: ['PIPER_apiToken']] | ||||
|         [type: 'token', id: 'detectTokenCredentialsId', env: ['PIPER_token']] | ||||
|     ] | ||||
|     piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user