Skip to content

Commit

Permalink
Merge branch 'master' into renovate/go-golang.org-x-crypto-vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
niki4 authored Jan 22, 2025
2 parents 9bdc4e7 + cf368e6 commit 267367c
Show file tree
Hide file tree
Showing 50 changed files with 1,457 additions and 260 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
README.md export-ignore
CONTRIBUTING.md export-ignore
4 changes: 4 additions & 0 deletions cmd/abapEnvironmentAssemblePackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ func checkIfFailedAndPrintLogs(builds []buildWithRepository) error {
log.Entry().Errorf("Assembly of %s failed", builds[i].repo.PackageName)
buildFailed = true
}
if builds[i].build.ResultState == abapbuild.Erroneous {
log.Entry().Errorf("Assembly of %s revealed errors", builds[i].repo.PackageName)
buildFailed = true
}
if builds[i].build.BuildID != "" {
if err := builds[i].build.PrintLogs(); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloudFoundryDeploy_generated.go

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

6 changes: 4 additions & 2 deletions cmd/detectExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,11 @@ func getDetectScript(config detectExecuteScanOptions, utils detectUtils) error {

downloadScript := func() error {
if config.UseDetect8 {
return utils.DownloadFile("https://detect.synopsys.com/detect8.sh", "detect.sh", nil, nil)
return utils.DownloadFile("https://detect.blackduck.com/detect8.sh", "detect.sh", nil, nil)
} else if config.UseDetect9 {
return utils.DownloadFile("https://detect.blackduck.com/detect9.sh", "detect.sh", nil, nil)
}
return utils.DownloadFile("https://detect.synopsys.com/detect9.sh", "detect.sh", nil, nil)
return utils.DownloadFile("https://detect.blackduck.com/detect10.sh", "detect.sh", nil, nil)

}

Expand Down
13 changes: 12 additions & 1 deletion 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/detectExecuteScan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func TestRunDetect(t *testing.T) {
utilsMock.AddFile("detect.sh", []byte(""))
err := runDetect(ctx, detectExecuteScanOptions{}, utilsMock, &detectExecuteScanInflux{})

assert.Equal(t, utilsMock.downloadedFiles["https://detect.synopsys.com/detect9.sh"], "detect.sh")
assert.Equal(t, utilsMock.downloadedFiles["https://detect.blackduck.com/detect10.sh"], "detect.sh")
assert.True(t, utilsMock.HasRemovedFile("detect.sh"))
assert.NoError(t, err)
assert.Equal(t, ".", utilsMock.Dir, "Wrong execution directory used")
Expand Down
3 changes: 3 additions & 0 deletions cmd/getConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func GetStageConfig() (config.StepConfig, error) {

defaultConfig := []io.ReadCloser{}
for _, f := range GeneralConfig.DefaultConfig {
if configOptions.OpenFile == nil {
return stepConfig, errors.New("config: open file function not set")
}
fc, err := configOptions.OpenFile(f, GeneralConfig.GitHubAccessTokens)
// only create error for non-default values
if err != nil && f != ".pipeline/defaults.yaml" {
Expand Down
1 change: 1 addition & 0 deletions cmd/metadata_generated.go

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

1 change: 1 addition & 0 deletions cmd/mtaBuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestMtaBuild(t *testing.T) {
SetConfigOptions(ConfigCommandOptions{
OpenFile: config.OpenPiperFile,
})

t.Run("Application name not set", func(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
options := mtaBuildOptions{}
Expand Down
115 changes: 115 additions & 0 deletions cmd/npmExecuteTests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package cmd

import (
"fmt"
"os"
"strings"

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

type vaultUrl struct {
URL string `json:"url"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
}

func npmExecuteTests(config npmExecuteTestsOptions, _ *telemetry.CustomData) {
c := command.Command{}

c.Stdout(log.Writer())
c.Stderr(log.Writer())
err := runNpmExecuteTests(&config, &c)
if err != nil {
log.Entry().WithError(err).Fatal("Step execution failed")
}
}

func runNpmExecuteTests(config *npmExecuteTestsOptions, c command.ExecRunner) error {
if len(config.Envs) > 0 {
c.SetEnv(config.Envs)
}

if len(config.Paths) > 0 {
path := fmt.Sprintf("PATH=%s:%s", os.Getenv("PATH"), strings.Join(config.Paths, ":"))
c.SetEnv([]string{path})
}

if config.WorkingDirectory != "" {
if err := os.Chdir(config.WorkingDirectory); err != nil {
return fmt.Errorf("failed to change directory: %w", err)
}
}

installCommandTokens := strings.Fields(config.InstallCommand)
if err := c.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...); err != nil {
return fmt.Errorf("failed to execute install command: %w", err)
}

parsedURLs, err := parseURLs(config.VaultURLs)
if err != nil {
return err
}

for _, app := range parsedURLs {
if err := runTestForUrl(app.URL, app.Username, app.Password, config, c); err != nil {
return err
}
}

if err := runTestForUrl(config.BaseURL, config.VaultUsername, config.VaultPassword, config, c); err != nil {
return err
}
return nil
}

func runTestForUrl(url, username, password string, config *npmExecuteTestsOptions, command command.ExecRunner) error {
credentialsToEnv(username, password, config.UsernameEnvVar, config.PasswordEnvVar, command)
// we need to reset the env vars as the next test might not have any credentials
defer resetCredentials(config.UsernameEnvVar, config.PasswordEnvVar, command)

runScriptTokens := strings.Fields(config.RunCommand)
if config.UrlOptionPrefix != "" {
runScriptTokens = append(runScriptTokens, config.UrlOptionPrefix+url)
}
if err := command.RunExecutable(runScriptTokens[0], runScriptTokens[1:]...); err != nil {
return fmt.Errorf("failed to execute npm script: %w", err)
}

return nil
}

func parseURLs(urls []map[string]interface{}) ([]vaultUrl, error) {
parsedUrls := []vaultUrl{}

for _, url := range urls {
parsedUrl := vaultUrl{}
urlStr, ok := url["url"].(string)
if !ok {
return nil, fmt.Errorf("url field is not a string")
}
parsedUrl.URL = urlStr
if username, ok := url["username"].(string); ok {
parsedUrl.Username = username
}

if password, ok := url["password"].(string); ok {
parsedUrl.Password = password
}
parsedUrls = append(parsedUrls, parsedUrl)
}
return parsedUrls, nil
}

func credentialsToEnv(username, password, usernameEnv, passwordEnv string, c command.ExecRunner) {
if username == "" || password == "" {
return
}
c.SetEnv([]string{usernameEnv + "=" + username, passwordEnv + "=" + password})
}

func resetCredentials(usernameEnv, passwordEnv string, c command.ExecRunner) {
c.SetEnv([]string{usernameEnv + "=", passwordEnv + "="})
}
Loading

0 comments on commit 267367c

Please sign in to comment.