From 9774eaab86a7ee69a31c58ceaf29aeec7190b020 Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Mon, 13 Mar 2023 16:47:16 +0300 Subject: [PATCH] fix(codeqlExecuteScan): added parameters threads and ram (#4269) --- cmd/codeqlExecuteScan.go | 22 +++++++++++++++++++++- cmd/codeqlExecuteScan_generated.go | 22 ++++++++++++++++++++++ resources/metadata/codeqlExecuteScan.yaml | 15 +++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index f48b3c41fa..6f08046391 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -187,10 +187,18 @@ func runCodeqlExecuteScan(config *codeqlExecuteScanOptions, telemetryData *telem if len(language) > 0 { cmd = append(cmd, "--language="+language) - } else if len(config.Language) > 0 { + } else { cmd = append(cmd, "--language="+config.Language) } + if len(config.Threads) > 0 { + cmd = append(cmd, "--threads="+config.Threads) + } + + if len(config.Ram) > 0 { + cmd = append(cmd, "--ram="+config.Ram) + } + //codeql has an autobuilder which tries to build the project based on specified programming language if len(config.BuildCommand) > 0 { cmd = append(cmd, "--command="+config.BuildCommand) @@ -209,6 +217,12 @@ func runCodeqlExecuteScan(config *codeqlExecuteScanOptions, telemetryData *telem cmd = nil cmd = append(cmd, "database", "analyze", "--format=sarif-latest", fmt.Sprintf("--output=%vtarget/codeqlReport.sarif", config.ModulePath), config.Database) + if len(config.Threads) > 0 { + cmd = append(cmd, "--threads="+config.Threads) + } + if len(config.Ram) > 0 { + cmd = append(cmd, "--ram="+config.Ram) + } cmd = codeqlQuery(cmd, config.QuerySuite) err = execute(utils, cmd, GeneralConfig.Verbose) if err != nil { @@ -220,6 +234,12 @@ func runCodeqlExecuteScan(config *codeqlExecuteScanOptions, telemetryData *telem cmd = nil cmd = append(cmd, "database", "analyze", "--format=csv", fmt.Sprintf("--output=%vtarget/codeqlReport.csv", config.ModulePath), config.Database) + if len(config.Threads) > 0 { + cmd = append(cmd, "--threads="+config.Threads) + } + if len(config.Ram) > 0 { + cmd = append(cmd, "--ram="+config.Ram) + } cmd = codeqlQuery(cmd, config.QuerySuite) err = execute(utils, cmd, GeneralConfig.Verbose) if err != nil { diff --git a/cmd/codeqlExecuteScan_generated.go b/cmd/codeqlExecuteScan_generated.go index 9ec04e36fd..d78bb07d16 100644 --- a/cmd/codeqlExecuteScan_generated.go +++ b/cmd/codeqlExecuteScan_generated.go @@ -28,6 +28,8 @@ type codeqlExecuteScanOptions struct { Database string `json:"database,omitempty"` QuerySuite string `json:"querySuite,omitempty"` UploadResults bool `json:"uploadResults,omitempty"` + Threads string `json:"threads,omitempty"` + Ram string `json:"ram,omitempty"` AnalyzedRef string `json:"analyzedRef,omitempty"` Repository string `json:"repository,omitempty"` CommitID string `json:"commitId,omitempty"` @@ -178,6 +180,8 @@ func addCodeqlExecuteScanFlags(cmd *cobra.Command, stepConfig *codeqlExecuteScan cmd.Flags().StringVar(&stepConfig.Database, "database", `codeqlDB`, "Path to the CodeQL database to create. This directory will be created, and must not already exist.") cmd.Flags().StringVar(&stepConfig.QuerySuite, "querySuite", os.Getenv("PIPER_querySuite"), "The name of a CodeQL query suite. If omitted, the default query suite for the language of the database being analyzed will be used.") cmd.Flags().BoolVar(&stepConfig.UploadResults, "uploadResults", false, "Allows you to upload codeql SARIF results to your github project. You will need to set githubToken for this.") + cmd.Flags().StringVar(&stepConfig.Threads, "threads", `0`, "Use this many threads for the codeql operations.") + cmd.Flags().StringVar(&stepConfig.Ram, "ram", os.Getenv("PIPER_ram"), "Use this much ram (MB) for the codeql operations.") cmd.Flags().StringVar(&stepConfig.AnalyzedRef, "analyzedRef", os.Getenv("PIPER_analyzedRef"), "Name of the ref that was analyzed.") cmd.Flags().StringVar(&stepConfig.Repository, "repository", os.Getenv("PIPER_repository"), "URL of the GitHub instance") cmd.Flags().StringVar(&stepConfig.CommitID, "commitId", os.Getenv("PIPER_commitId"), "SHA of commit that was analyzed.") @@ -287,6 +291,24 @@ func codeqlExecuteScanMetadata() config.StepData { Aliases: []config.Alias{}, Default: false, }, + { + Name: "threads", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, + Type: "string", + Mandatory: false, + Aliases: []config.Alias{}, + Default: `0`, + }, + { + Name: "ram", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, + Type: "string", + Mandatory: false, + Aliases: []config.Alias{}, + Default: os.Getenv("PIPER_ram"), + }, { Name: "analyzedRef", ResourceRef: []config.ResourceReference{ diff --git a/resources/metadata/codeqlExecuteScan.yaml b/resources/metadata/codeqlExecuteScan.yaml index 96577c17fe..c267ea536d 100644 --- a/resources/metadata/codeqlExecuteScan.yaml +++ b/resources/metadata/codeqlExecuteScan.yaml @@ -105,6 +105,21 @@ spec: - STAGES - STEPS default: false + - name: threads + type: string + description: "Use this many threads for the codeql operations." + scope: + - PARAMETERS + - STAGES + - STEPS + default: "0" + - name: ram + type: string + description: "Use this much ram (MB) for the codeql operations." + scope: + - PARAMETERS + - STAGES + - STEPS - name: analyzedRef type: string description: "Name of the ref that was analyzed."