Skip to content

Commit

Permalink
added logic of fetching golang private packages for whitesource step (S…
Browse files Browse the repository at this point in the history
…AP#4595)

* added logic of fetching golang private packages for whitesource step and detectExecuteScan step

* changed logic of checking by config.PrivateModulesGitToken

* moved func prepareGolangPrivatePackages to golangBuild.go

* fix (gitOpsUpdateDeployment) add CA bundle options to plain clone and commit to trust enterprise github instances (SAP#4602)

* downloading ca cert bundle when added as config

* adding logging statements

* allowing bats test to handle ca cert

* adding info message

* hard coding file names

* including correct http client util bundle

* removing logging message not needed

* adding cert bundle to commit and push

* improving the condition to add ca cert in commit and push

* fixing unit test

* fixing unit test

* fixing unit test

* fixing unit test

* fixing unit test

* feat(kanikoExecute): add dockerfilePath param to multipleImages (SAP#4569)

* add containerDockerfilePath param to multipleImages

* rename ContainerDockerfilePath param to DockerfilePath

* Fix trailing spaces

---------

Co-authored-by: Egor Balakin <[email protected]>
Co-authored-by: Vyacheslav Starostin <[email protected]>

* fix(helm): forward sourceRepositoryCredentialsId from groovy to go layer (SAP#4604)

forward sourceRepositoryCredentialsId from groovy to go layer in the same way how this is done for the targetRepositoryCredentialsId

* feat(config): exporting generateConfig function and applying minor changes (SAP#4605)

* exporting generateConfig function and applying minor changes

* Added setConfigOptions to set configOptions variable.
Added possibility to set format output, json or yaml for now.

* Correcting mistake on cmd/getDefaults.go

Co-authored-by: Jordi van Liempt <[email protected]>

---------

Co-authored-by: Jordi van Liempt <[email protected]>

* moved func prepareGolangPrivatePackages to pkg/golang

---------

Co-authored-by: Akramdzhon Azamov <[email protected]>
Co-authored-by: Andrei Kireev <[email protected]>
Co-authored-by: Anil Keshav <[email protected]>
Co-authored-by: Egor Balakin <[email protected]>
Co-authored-by: Egor Balakin <[email protected]>
Co-authored-by: Vyacheslav Starostin <[email protected]>
Co-authored-by: Marcus Holl <[email protected]>
Co-authored-by: Jk1484 <[email protected]>
Co-authored-by: Jordi van Liempt <[email protected]>
  • Loading branch information
10 people authored and maxatsap committed Jul 23, 2024
1 parent 4427eb7 commit 83be1a1
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 2 deletions.
9 changes: 9 additions & 0 deletions cmd/detectExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
bd "github.com/SAP/jenkins-library/pkg/blackduck"
"github.com/SAP/jenkins-library/pkg/command"
piperGithub "github.com/SAP/jenkins-library/pkg/github"
"github.com/SAP/jenkins-library/pkg/golang"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/maven"
Expand Down Expand Up @@ -138,6 +139,14 @@ func detectExecuteScan(config detectExecuteScanOptions, _ *telemetry.CustomData,
if err != nil {
log.Entry().WithError(err).Warning("Failed to get GitHub client")
}

if config.PrivateModules == "" && config.PrivateModulesGitToken != "" {
//configuring go private packages
if err := golang.PrepareGolangPrivatePackages("detectExecuteStep", config.PrivateModules, config.PrivateModulesGitToken); err != nil {
log.Entry().Warningf("couldn't set private packages for golang, error: %s", err.Error())
}
}

utils := newDetectUtils(client)
if err := runDetect(ctx, config, utils, influx); err != nil {
log.Entry().
Expand Down
36 changes: 36 additions & 0 deletions cmd/detectExecuteScan_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/golangBuild_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cmd/whitesourceExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/format"
"github.com/SAP/jenkins-library/pkg/golang"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/npm"
"github.com/SAP/jenkins-library/pkg/piperutils"
Expand Down Expand Up @@ -157,6 +158,13 @@ func whitesourceExecuteScan(config ScanOptions, _ *telemetry.CustomData, commonP
}

func runWhitesourceExecuteScan(ctx context.Context, config *ScanOptions, scan *ws.Scan, utils whitesourceUtils, sys whitesource, commonPipelineEnvironment *whitesourceExecuteScanCommonPipelineEnvironment, influx *whitesourceExecuteScanInflux) error {
if config != nil && config.PrivateModules != "" && config.PrivateModulesGitToken != "" {
//configuring go private packages
if err := golang.PrepareGolangPrivatePackages("WhitesourceExecuteStep", config.PrivateModules, config.PrivateModulesGitToken); err != nil {
log.Entry().Warningf("couldn't set private packages for golang, error: %s", err.Error())
}
}

if err := resolveAggregateProjectName(config, scan, sys); err != nil {
return errors.Wrapf(err, "failed to resolve and aggregate project name")
}
Expand Down
36 changes: 36 additions & 0 deletions cmd/whitesourceExecuteScan_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions pkg/golang/golang.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package golang

import (
"fmt"
"os"
"strings"

"github.com/SAP/jenkins-library/pkg/command"
)

type utilsBundle struct {
command.Command
}

// prepare golang private packages for whitesource and blackduck(detectExecuteScan)
func PrepareGolangPrivatePackages(stepName, privateModules, privateModulesGitToken string) error {
utils := &utilsBundle{
Command: command.Command{
StepName: stepName,
},
}
os.Setenv("GOPRIVATE", privateModules)
err := gitConfigurationForPrivateModules(privateModules, privateModulesGitToken, utils)
if err != nil {
return err
}
return nil
}

func gitConfigurationForPrivateModules(privateMod string, token string, utils *utilsBundle) error {
privateMod = strings.ReplaceAll(privateMod, "/*", "")
privateMod = strings.ReplaceAll(privateMod, "*.", "")
modules := strings.Split(privateMod, ",")
for _, v := range modules {
authenticatedRepoURL := fmt.Sprintf("https://%s@%s", token, v)
repoBaseURL := fmt.Sprintf("https://%s", v)
err := utils.RunExecutable("git", "config", "--global", fmt.Sprintf("url.%s.insteadOf", authenticatedRepoURL), repoBaseURL)
if err != nil {
return err
}
}
return nil
}
29 changes: 29 additions & 0 deletions resources/metadata/detectExecuteScan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ spec:
- name: githubTokenCredentialsId
description: Jenkins 'Secret text' credentials ID containing token to authenticate to GitHub.
type: jenkins
- name: golangPrivateModulesGitTokenCredentialsId
description: Jenkins 'Username with password' credentials ID containing username/password for http access to your git repos where your go private modules are stored.
type: jenkins
params:
- name: token
aliases:
Expand Down Expand Up @@ -489,6 +492,32 @@ spec:
- PARAMETERS
- STAGES
- STEPS
- name: privateModules
type: "string"
description: Tells go which modules shall be considered to be private (by setting [GOPRIVATE](https://pkg.go.dev/cmd/go#hdr-Configuration_for_downloading_non_public_code)).
scope:
- GENERAL
- STEPS
- STAGES
- PARAMETERS
alias:
- goprivate
- name: privateModulesGitToken
description: GitHub personal access token as per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line.
scope:
- GENERAL
- PARAMETERS
- STAGES
- STEPS
type: string
secret: true
resourceRef:
- name: golangPrivateModulesGitTokenCredentialsId
type: secret
param: password
- type: vaultSecret
name: golangPrivateModulesGitTokenVaultSecret
default: golang
outputs:
resources:
- name: influx
Expand Down
1 change: 1 addition & 0 deletions resources/metadata/golangBuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ spec:
type: "string"
description: Tells go which modules shall be considered to be private (by setting [GOPRIVATE](https://pkg.go.dev/cmd/go#hdr-Configuration_for_downloading_non_public_code)).
scope:
- GENERAL
- STEPS
- STAGES
- PARAMETERS
Expand Down
29 changes: 29 additions & 0 deletions resources/metadata/whitesourceExecuteScan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ spec:
- name: githubTokenCredentialsId
description: Jenkins 'Secret text' credentials ID containing token to authenticate to GitHub.
type: jenkins
- name: golangPrivateModulesGitTokenCredentialsId
description: Jenkins 'Username with password' credentials ID containing username/password for http access to your git repos where your go private modules are stored.
type: jenkins
params:
- name: agentDownloadUrl
type: string
Expand Down Expand Up @@ -597,6 +600,32 @@ spec:
- PARAMETERS
- STAGES
- STEPS
- name: privateModules
type: "string"
description: Tells go which modules shall be considered to be private (by setting [GOPRIVATE](https://pkg.go.dev/cmd/go#hdr-Configuration_for_downloading_non_public_code)).
scope:
- GENERAL
- STEPS
- STAGES
- PARAMETERS
alias:
- goprivate
- name: privateModulesGitToken
description: GitHub personal access token as per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line.
scope:
- GENERAL
- PARAMETERS
- STAGES
- STEPS
type: string
secret: true
resourceRef:
- name: golangPrivateModulesGitTokenCredentialsId
type: secret
param: password
- type: vaultSecret
name: golangPrivateModulesGitTokenVaultSecret
default: golang
resources:
- name: buildDescriptor
type: stash
Expand Down
3 changes: 2 additions & 1 deletion vars/detectExecuteScan.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ void call(Map parameters = [:]) {
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN)
List credentials = [
[type: 'token', id: 'detectTokenCredentialsId', env: ['PIPER_token']],
[type: 'token', id: 'githubTokenCredentialsId', env: ['PIPER_githubToken']]
[type: 'token', id: 'githubTokenCredentialsId', env: ['PIPER_githubToken']],
[type: 'usernamePassword', id: 'golangPrivateModulesGitTokenCredentialsId', env: ['PIPER_privateModulesGitUsername', 'PIPER_privateModulesGitToken']]
]
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
}
1 change: 1 addition & 0 deletions vars/whitesourceExecuteScan.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void call(Map parameters = [:]) {
[type: 'token', id: 'userTokenCredentialsId', env: ['PIPER_userToken']],
[type: 'token', id: 'githubTokenCredentialsId', env: ['PIPER_githubToken']],
[type: 'file', id: 'dockerConfigJsonCredentialsId', env: ['PIPER_dockerConfigJSON']],
[type: 'usernamePassword', id: 'golangPrivateModulesGitTokenCredentialsId', env: ['PIPER_privateModulesGitUsername', 'PIPER_privateModulesGitToken']]
]
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
}

0 comments on commit 83be1a1

Please sign in to comment.