Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added logic of fetching golang private packages for whitesource step #4595

Merged
merged 14 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/detectExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ func detectExecuteScan(config detectExecuteScanOptions, _ *telemetry.CustomData,
if err != nil {
log.Entry().WithError(err).Warning("Failed to get GitHub client")
}

if config.BuildTool == golangBuildTool {
akram8008 marked this conversation as resolved.
Show resolved Hide resolved
//configuring go private packages
if err := prepareGolangPrivatePackages(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.

24 changes: 24 additions & 0 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,27 @@ func fileExists(filename string) bool {
}
return !info.IsDir()
}

const golangBuildTool = "golang"

// prepare golang private packages for whitesource and blackduck(detectExecuteScan)
func prepareGolangPrivatePackages(privateModules, privateModulesGitToken string) error {
akram8008 marked this conversation as resolved.
Show resolved Hide resolved

goConfig := golangBuildOptions{
PrivateModules: privateModules,
PrivateModulesGitToken: privateModulesGitToken,
} // only these parameters are enough to configure

utils := newGolangBuildUtils(goConfig)

goModFile, err := readGoModFile(utils) // returns nil if go.mod doesnt exist
if err != nil {
return err
}

if err = prepareGolangEnvironment(&goConfig, goModFile, utils); err != nil {
return err
}

return nil
}
7 changes: 7 additions & 0 deletions cmd/whitesourceExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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.BuildTool == golangBuildTool && config != nil {
akram8008 marked this conversation as resolved.
Show resolved Hide resolved
//configuring go private packages
if err := prepareGolangPrivatePackages(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.

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)
}