1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-09-16 09:26:22 +02:00

refactor: align parameter name for username (#1960)

Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
This commit is contained in:
Christopher Fenner
2020-09-16 11:33:03 +02:00
committed by GitHub
parent 328ee34369
commit df9f75b04d
12 changed files with 35 additions and 32 deletions

View File

@@ -125,8 +125,8 @@ func runNexusUpload(utils nexusUploadUtils, uploader nexus.Uploader, options *ne
func uploadNpmArtifacts(utils nexusUploadUtils, uploader nexus.Uploader, options *nexusUploadOptions) error {
execRunner := utils.getExecRunner()
environment := []string{"npm_config_registry=http://" + uploader.GetNpmRepoURL(), "npm_config_email=project-piper@no-reply.com"}
if options.User != "" && options.Password != "" {
auth := b64.StdEncoding.EncodeToString([]byte(options.User + ":" + options.Password))
if options.Username != "" && options.Password != "" {
auth := b64.StdEncoding.EncodeToString([]byte(options.Username + ":" + options.Password))
environment = append(environment, "npm_config__auth="+auth)
} else {
log.Entry().Info("No credentials provided for npm upload, trying to upload anonymously.")
@@ -226,7 +226,7 @@ const settingsPath = ".pipeline/nexusMavenSettings.xml"
func setupNexusCredentialsSettingsFile(utils nexusUploadUtils, options *nexusUploadOptions,
mavenOptions *maven.ExecuteOptions) (string, error) {
if options.User == "" || options.Password == "" {
if options.Username == "" || options.Password == "" {
return "", nil
}
@@ -236,7 +236,7 @@ func setupNexusCredentialsSettingsFile(utils nexusUploadUtils, options *nexusUpl
}
log.Entry().Debugf("Writing nexus credentials to environment")
utils.getExecRunner().SetEnv([]string{"NEXUS_username=" + options.User, "NEXUS_password=" + options.Password})
utils.getExecRunner().SetEnv([]string{"NEXUS_username=" + options.Username, "NEXUS_password=" + options.Password})
mavenOptions.ProjectSettingsFile = settingsPath
mavenOptions.Defines = append(mavenOptions.Defines, "-DrepositoryId="+settingsServerID)

View File

@@ -22,7 +22,7 @@ type nexusUploadOptions struct {
ArtifactID string `json:"artifactId,omitempty"`
GlobalSettingsFile string `json:"globalSettingsFile,omitempty"`
M2Path string `json:"m2Path,omitempty"`
User string `json:"user,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
}
@@ -69,7 +69,7 @@ If an image for mavenExecute is configured, and npm packages are to be published
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
log.RegisterSecret(stepConfig.User)
log.RegisterSecret(stepConfig.Username)
log.RegisterSecret(stepConfig.Password)
if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 {
@@ -108,7 +108,7 @@ func addNexusUploadFlags(cmd *cobra.Command, stepConfig *nexusUploadOptions) {
cmd.Flags().StringVar(&stepConfig.ArtifactID, "artifactId", os.Getenv("PIPER_artifactId"), "The artifact ID used for both the .mtar and mta.yaml files deployed for MTA projects, ignored for Maven.")
cmd.Flags().StringVar(&stepConfig.GlobalSettingsFile, "globalSettingsFile", os.Getenv("PIPER_globalSettingsFile"), "Path to the mvn settings file that should be used as global settings file.")
cmd.Flags().StringVar(&stepConfig.M2Path, "m2Path", os.Getenv("PIPER_m2Path"), "The path to the local .m2 directory, only used for Maven projects.")
cmd.Flags().StringVar(&stepConfig.User, "user", os.Getenv("PIPER_user"), "Username for accessing the Nexus endpoint.")
cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "Username for accessing the Nexus endpoint.")
cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for accessing the Nexus endpoint.")
cmd.MarkFlagRequired("url")
@@ -189,7 +189,7 @@ func nexusUploadMetadata() config.StepData {
Aliases: []config.Alias{{Name: "maven/m2Path"}},
},
{
Name: "user",
Name: "username",
ResourceRef: []config.ResourceReference{{Name: "nexusCredentialsId", Param: "username"}},
Scope: []string{"PARAMETERS"},
Type: "string",

View File

@@ -361,7 +361,7 @@ func TestUploadNpmProjects(t *testing.T) {
utils.AddFile("package.json", testPackageJson)
uploader := mockUploader{}
options := createOptions()
options.User = "admin"
options.Username = "admin"
options.Password = "admin123"
err := runNexusUpload(&utils, &uploader, &options)
@@ -627,7 +627,7 @@ func TestUploadMavenProjects(t *testing.T) {
utils.AddFile("pom.xml", testPomXml)
uploader := mockUploader{}
options := createOptions()
options.User = "admin"
options.Username = "admin"
options.Password = "admin123"
err := runNexusUpload(&utils, &uploader, &options)
@@ -661,7 +661,7 @@ func TestUploadMavenProjects(t *testing.T) {
func TestSetupNexusCredentialsSettingsFile(t *testing.T) {
utils := newMockUtilsBundle(false, true, false)
options := nexusUploadOptions{User: "admin", Password: "admin123"}
options := nexusUploadOptions{Username: "admin", Password: "admin123"}
mavenOptions := maven.ExecuteOptions{}
settingsPath, err := setupNexusCredentialsSettingsFile(&utils, &options, &mavenOptions)

View File

@@ -95,7 +95,7 @@ func (a Action) String() string {
}
const loginScript = `#!/bin/bash
xs login -a {{.APIURL}} -u {{.User}} -p '{{.Password}}' -o {{.Org}} -s {{.Space}} {{.LoginOpts}}
xs login -a {{.APIURL}} -u {{.Username}} -p '{{.Password}}' -o {{.Org}} -s {{.Space}} {{.LoginOpts}}
`
const logoutScript = `#!/bin/bash

View File

@@ -23,7 +23,7 @@ type xsDeployOptions struct {
Mode string `json:"mode,omitempty"`
OperationID string `json:"operationId,omitempty"`
APIURL string `json:"apiUrl,omitempty"`
User string `json:"user,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Org string `json:"org,omitempty"`
Space string `json:"space,omitempty"`
@@ -84,7 +84,7 @@ func XsDeployCommand() *cobra.Command {
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
log.RegisterSecret(stepConfig.User)
log.RegisterSecret(stepConfig.Username)
log.RegisterSecret(stepConfig.Password)
if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 {
@@ -123,7 +123,7 @@ func addXsDeployFlags(cmd *cobra.Command, stepConfig *xsDeployOptions) {
cmd.Flags().StringVar(&stepConfig.Mode, "mode", `DEPLOY`, "Controls if there is a standard deployment or a blue green deployment. Values: 'DEPLOY', 'BG_DEPLOY'")
cmd.Flags().StringVar(&stepConfig.OperationID, "operationId", os.Getenv("PIPER_operationId"), "The operation ID. Used in case of bg-deploy in order to resume or abort a previously started deployment.")
cmd.Flags().StringVar(&stepConfig.APIURL, "apiUrl", os.Getenv("PIPER_apiUrl"), "The api url (e.g. https://example.org:12345")
cmd.Flags().StringVar(&stepConfig.User, "user", os.Getenv("PIPER_user"), "User")
cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "Username")
cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password")
cmd.Flags().StringVar(&stepConfig.Org, "org", os.Getenv("PIPER_org"), "The org")
cmd.Flags().StringVar(&stepConfig.Space, "space", os.Getenv("PIPER_space"), "The space")
@@ -133,7 +133,7 @@ func addXsDeployFlags(cmd *cobra.Command, stepConfig *xsDeployOptions) {
cmd.MarkFlagRequired("mtaPath")
cmd.MarkFlagRequired("mode")
cmd.MarkFlagRequired("apiUrl")
cmd.MarkFlagRequired("user")
cmd.MarkFlagRequired("username")
cmd.MarkFlagRequired("password")
cmd.MarkFlagRequired("org")
cmd.MarkFlagRequired("space")
@@ -207,12 +207,12 @@ func xsDeployMetadata() config.StepData {
Aliases: []config.Alias{},
},
{
Name: "user",
Name: "username",
ResourceRef: []config.ResourceReference{{Name: "credentialsId", Param: "username"}},
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
Type: "string",
Mandatory: true,
Aliases: []config.Alias{},
Aliases: []config.Alias{{Name: "user"}},
},
{
Name: "password",

View File

@@ -53,7 +53,7 @@ func (f *FileUtilsMock) Glob(pattern string) (matches []string, err error) {
func TestDeploy(t *testing.T) {
myXsDeployOptions := xsDeployOptions{
APIURL: "https://example.org:12345",
User: "me",
Username: "me",
Password: "secretPassword",
Org: "myOrg",
Space: "mySpace",

View File

@@ -42,7 +42,7 @@ func TestNexus3UploadMta(t *testing.T) {
})
err := container.whenRunningPiperCommand("nexusUpload", "--groupId=mygroup", "--artifactId=mymta",
"--user=admin", "--password=admin123", "--mavenRepository=maven-releases", "--url=http://localhost:8081")
"--username=admin", "--password=admin123", "--mavenRepository=maven-releases", "--url=http://localhost:8081")
if err != nil {
t.Fatalf("Piper command failed %s", err)
}
@@ -67,7 +67,7 @@ func TestNexus3UploadMaven(t *testing.T) {
},
})
err := container.whenRunningPiperCommand("nexusUpload", "--user=admin", "--password=admin123",
err := container.whenRunningPiperCommand("nexusUpload", "--username=admin", "--password=admin123",
"--mavenRepository=maven-releases", "--url=http://localhost:8081")
if err != nil {
t.Fatalf("Piper command failed %s", err)
@@ -95,7 +95,7 @@ func TestNexus3UploadNpm(t *testing.T) {
},
})
err := container.whenRunningPiperCommand("nexusUpload", "--user=admin", "--password=admin123",
err := container.whenRunningPiperCommand("nexusUpload", "--username=admin", "--password=admin123",
"--npmRepository=npm-repo", "--url=http://localhost:8081")
if err != nil {
t.Fatalf("Piper command failed %s", err)
@@ -132,7 +132,7 @@ func TestNexus2Upload(t *testing.T) {
"nexusUpload",
"--groupId=mygroup",
"--artifactId=mymta",
"--user=admin",
"--username=admin",
"--password=admin123",
"--mavenRepository=releases",
"--version=nexus2",
@@ -147,7 +147,7 @@ func TestNexus2Upload(t *testing.T) {
piperOptions = []string{
"nexusUpload",
"--user=admin",
"--username=admin",
"--password=admin123",
"--mavenRepository=releases",
"--version=nexus2",
@@ -162,7 +162,7 @@ func TestNexus2Upload(t *testing.T) {
piperOptions = []string{
"nexusUpload",
"--user=admin",
"--username=admin",
"--password=admin123",
"--npmRepository=npm-repo",
"--version=nexus2",

View File

@@ -110,7 +110,7 @@ spec:
- STEPS
aliases:
- name: maven/m2Path
- name: user
- name: username
type: string
description: Username for accessing the Nexus endpoint.
scope:

View File

@@ -88,9 +88,12 @@ spec:
- STAGES
- STEPS
mandatory: true
- name: user
- name: username
aliases:
- name: user
deprecated: true
type: string
description: User
description: Username
scope:
- PARAMETERS
- STAGES

View File

@@ -199,7 +199,7 @@ class XsDeployTest extends BasePiperTest {
new CommandLineMatcher()
.hasProlog('./piper getConfig --stepMetadata \'.pipeline/metadata/xsDeploy.yaml\''),
new CommandLineMatcher()
.hasProlog('#!/bin/bash ./piper xsDeploy --defaultConfig ".pipeline/additionalConfigs/default_pipeline_environment.yml" --user \\$\\{USERNAME\\} --password \\$\\{PASSWORD\\}'),
.hasProlog('#!/bin/bash ./piper xsDeploy --defaultConfig ".pipeline/additionalConfigs/default_pipeline_environment.yml" --username \\$\\{USERNAME\\} --password \\$\\{PASSWORD\\}'),
not(new CommandLineMatcher()
.hasProlog('#!/bin/bash ./piper xsDeploy')
.hasOption('operationId', '1234'))
@@ -398,4 +398,4 @@ class XsDeployTest extends BasePiperTest {
)
)
}
}
}

View File

@@ -13,6 +13,6 @@ void call(Map parameters = [:]) {
final script = checkScript(this, parameters) ?: this
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN)
List credentials = [[type: 'usernamePassword', id: 'nexusCredentialsId', env: ['PIPER_user', 'PIPER_password']]]
List credentials = [[type: 'usernamePassword', id: 'nexusCredentialsId', env: ['PIPER_username', 'PIPER_password']]]
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
}

View File

@@ -127,7 +127,7 @@ void call(Map parameters = [:]) {
dockerExecute([script: this].plus([dockerImage: options.dockerImage, dockerPullImage: options.dockerPullImage])) {
xsDeployStdout = sh returnStdout: true, script: """#!/bin/bash
./piper xsDeploy --defaultConfig ${configFiles} --user \${USERNAME} --password \${PASSWORD} ${mtarFilePath ? '--mtaPath ' + mtarFilePath : ''} ${operationId ? '--operationId ' + operationId : ''}
./piper xsDeploy --defaultConfig ${configFiles} --username \${USERNAME} --password \${PASSWORD} ${mtarFilePath ? '--mtaPath ' + mtarFilePath : ''} ${operationId ? '--operationId ' + operationId : ''}
"""
}