Skip to content

Commit

Permalink
Merge pull request #227 from cablespaghetti/feature/fix-docker-auth
Browse files Browse the repository at this point in the history
Fix incorrectly hardcoded Docker Authentication username
  • Loading branch information
ivanilves authored Oct 4, 2020
2 parents f6bd6d5 + fac7f6c commit 0c09910
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions docker/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"

log "github.com/sirupsen/logrus"
"github.com/ivanilves/lstags/docker/config/credhelper"
"github.com/moby/moby/api/types"

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

func getAuthJSONString(username, password string) string {
b, err := json.Marshal(types.AuthConfig{
Username: "_json_key",
Username: username,
Password: password,
})

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

return base64.StdEncoding.EncodeToString(
[]byte(getAuthJSONString(username, password)),
[]byte(authJSONString),
)
}

Expand Down
4 changes: 2 additions & 2 deletions docker/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var configFile = "../../fixtures/docker/config.json"

func TestGetRegistryAuth(t *testing.T) {
examples := map[string]string{
"registry.company.io": "eyJ1c2VybmFtZSI6Il9qc29uX2tleSIsInBhc3N3b3JkIjoicGFzczEifQ==",
"registry.hub.docker.com": "eyJ1c2VybmFtZSI6Il9qc29uX2tleSIsInBhc3N3b3JkIjoicGFzczIifQ==",
"registry.company.io": "eyJ1c2VybmFtZSI6InVzZXIxIiwicGFzc3dvcmQiOiJwYXNzMSJ9",
"registry.hub.docker.com": "eyJ1c2VybmFtZSI6InVzZXIyIiwicGFzc3dvcmQiOiJwYXNzMiJ9",
"registry.mindundi.org": "",
}

Expand Down

0 comments on commit 0c09910

Please sign in to comment.