Skip to content

Commit 3961ec2

Browse files
fix: Hardcoded username for registry authentication
1 parent 8706a12 commit 3961ec2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

docker/config/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"strings"
99

10+
log "github.com/sirupsen/logrus"
1011
"github.com/ivanilves/lstags/docker/config/credhelper"
1112
"github.com/moby/moby/api/types"
1213

@@ -56,7 +57,7 @@ func (c *Config) GetCredentials(registry string) (string, string, bool) {
5657

5758
func getAuthJSONString(username, password string) string {
5859
b, err := json.Marshal(types.AuthConfig{
59-
Username: "_json_key",
60+
Username: username,
6061
Password: password,
6162
})
6263

@@ -76,9 +77,11 @@ func (c *Config) GetRegistryAuth(registry string) string {
7677
if !defined {
7778
return ""
7879
}
80+
authJSONString := getAuthJSONString(username, password)
81+
log.Debugf("JSON Auth String: %s", authJSONString)
7982

8083
return base64.StdEncoding.EncodeToString(
81-
[]byte(getAuthJSONString(username, password)),
84+
[]byte(authJSONString),
8285
)
8386
}
8487

docker/config/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ var configFile = "../../fixtures/docker/config.json"
1010

1111
func TestGetRegistryAuth(t *testing.T) {
1212
examples := map[string]string{
13-
"registry.company.io": "eyJ1c2VybmFtZSI6Il9qc29uX2tleSIsInBhc3N3b3JkIjoicGFzczEifQ==",
14-
"registry.hub.docker.com": "eyJ1c2VybmFtZSI6Il9qc29uX2tleSIsInBhc3N3b3JkIjoicGFzczIifQ==",
13+
"registry.company.io": "eyJ1c2VybmFtZSI6InVzZXIxIiwicGFzc3dvcmQiOiJwYXNzMSJ9",
14+
"registry.hub.docker.com": "eyJ1c2VybmFtZSI6InVzZXIyIiwicGFzc3dvcmQiOiJwYXNzMiJ9",
1515
"registry.mindundi.org": "",
1616
}
1717

0 commit comments

Comments
 (0)