Skip to content

Commit e33026b

Browse files
authored
Merge pull request #78 from wunderio/feature/docker-login-quotes-fix
Quote only username
2 parents f52bdb2 + 22aeb53 commit e33026b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

cmd/ciImageLogin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ Available flags and environment variables:
117117
protocol = "http://"
118118
}
119119
// User && pass login
120-
command = fmt.Sprintf("echo '%s' | docker login --username '%s' --password-stdin '%s%s'", imageRepoPass, imageRepoUser, protocol, imageRepoHost)
120+
command = fmt.Sprintf("echo %q | docker login --username '%s' --password-stdin %s%s", imageRepoPass, imageRepoUser, protocol, imageRepoHost)
121121

122122
} else if gcpKeyJson != "" {
123123
// GCR login
124124
if !strings.Contains(imageRepoHost, "://") {
125125
imageRepoHost = "https://" + imageRepoHost
126126
}
127-
command = fmt.Sprintf("echo '%s' | docker login --username '%s' --password-stdin '%s'", gcpKeyJson, "_json_key", imageRepoHost)
127+
command = fmt.Sprintf("echo %q | docker login --username '%s' --password-stdin %s", gcpKeyJson, "_json_key", imageRepoHost)
128128

129129
} else if awsSecretAccessKey != "" {
130130
//Get AWS Account ID
@@ -137,11 +137,11 @@ Available flags and environment variables:
137137
// ECR login
138138
command = fmt.Sprintf("aws ecr get-login-password --region %s | docker login --username AWS --password-stdin %s.dkr.ecr.%s.amazonaws.com", awsRegion, awsAccountId, awsRegion)
139139
// TODO: use aws cli v2
140-
// command = fmt.Sprintf("echo '%s' | docker login --username AWS --password-stdin %s", awsSecretAccessKey, imageRepoHost)
140+
// command = fmt.Sprintf("echo %q | docker login --username AWS --password-stdin %s", awsSecretAccessKey, imageRepoHost)
141141

142142
} else if aksSPPass != "" {
143143
// ACR Login
144-
command = fmt.Sprintf("echo '%s' | docker login --username '%s' --password-stdin '%s'", aksSPPass, aksSPAppID, imageRepoHost)
144+
command = fmt.Sprintf("echo %q | docker login --username '%s' --password-stdin %s", aksSPPass, aksSPAppID, imageRepoHost)
145145
}
146146

147147
if command != "" {

tests/image_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestImageLoginCmd(t *testing.T) {
1717
"IMAGE_REPO_HOST=foo.bar",
1818
"GCLOUD_KEY_JSON=baz",
1919
}
20-
testString := `echo 'baz' | docker login --username '_json_key' --password-stdin 'https://foo.bar`
20+
testString := `echo "baz" | docker login --username '_json_key' --password-stdin https://foo.bar`
2121
CliExecTest(t, command, environment, testString, false)
2222

2323
// Test all env
@@ -43,7 +43,7 @@ AWS_REGION: 555
4343
AKS_TENANT_ID: 666
4444
AKS_SP_APP_ID: 777
4545
AKS_SP_PASSWORD: 888
46-
Command (not executed): echo '222' | docker login --username '111' --password-stdin 'https://foo.bar'`
46+
Command (not executed): echo "222" | docker login --username '111' --password-stdin https://foo.bar`
4747

4848
CliExecTest(t, command, environment, testString, false)
4949

@@ -56,7 +56,7 @@ Command (not executed): echo '222' | docker login --username '111' --password-st
5656
// Test args
5757
command = "ci image login --image-repo-host foo.bar --gcp-key-json baz --debug"
5858
environment = []string{}
59-
testString = `echo 'baz' | docker login --username '_json_key' --password-stdin 'https://foo.bar'`
59+
testString = `echo "baz" | docker login --username '_json_key' --password-stdin https://foo.bar`
6060
CliExecTest(t, command, environment, testString, false)
6161

6262
// Test all args
@@ -83,7 +83,7 @@ AWS_REGION: 555
8383
AKS_TENANT_ID: 666
8484
AKS_SP_APP_ID: 777
8585
AKS_SP_PASSWORD: 888
86-
Command (not executed): echo '222' | docker login --username '111' --password-stdin 'https://foo.bar'`
86+
Command (not executed): echo "222" | docker login --username '111' --password-stdin https://foo.bar`
8787
CliExecTest(t, command, environment, testString, false)
8888

8989
// Test args+env merge
@@ -92,7 +92,7 @@ Command (not executed): echo '222' | docker login --username '111' --password-st
9292
"IMAGE_REPO_HOST=bar.bar",
9393
"GCLOUD_KEY_JSON=baz",
9494
}
95-
testString = `echo 'baz' | docker login --username '_json_key' --password-stdin 'https://foo.bar'`
95+
testString = `echo "baz" | docker login --username '_json_key' --password-stdin https://foo.bar`
9696
CliExecTest(t, command, environment, testString, false)
9797

9898
// Change dir back to previous

0 commit comments

Comments
 (0)