Skip to content

Commit

Permalink
Merge pull request #187 from ivanilves/ISSUE-174
Browse files Browse the repository at this point in the history
ISSUE-174 Fix _json_key GCR authentication
  • Loading branch information
ivanilves authored Jun 28, 2019
2 parents 8c56358 + 510dc61 commit 06a0623
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ script:
- make lint
- make vet
- if [[ "${TRAVIS_PULL_REQUEST}" != "false" ]]; then make semantic RANGE=$(scripts/travis_range.sh); fi
- make stress-test-async CONCURRENT_REQUESTS=256
- make coverage
- make blackbox-integration-test
- make docker-image DOCKER_TAG=release
- make stress-test-wait TIME=60 MODE=silent

after_script:
- sudo killall -v dockerd
Expand Down
30 changes: 25 additions & 5 deletions docker/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,44 @@ func (c *Config) IsEmpty() bool {
// GetCredentials gets per-registry credentials from loaded Docker config
func (c *Config) GetCredentials(registry string) (string, string, bool) {
if _, defined := c.usernames[registry]; !defined {
username, password, _ := credhelper.GetCredentials(registry, c.CredsStore, c.CredHelpers)
username, password, err := credhelper.GetCredentials(
registry,
c.CredsStore,
c.CredHelpers,
)

return username, password, false
if err != nil {
return "", "", false
}

return username, password, true
}

return c.usernames[registry], c.passwords[registry], true
}

func getAuthJSONString(username, password string) string {
if username == "_json_key" {
return fmt.Sprintf("%s:%s", username, password)
}

return fmt.Sprintf(
`{ "username": "%s", "password": "%s" }`,
username,
password,
)
}

// GetRegistryAuth gets per-registry base64 authentication string
func (c *Config) GetRegistryAuth(registry string) string {
username, password, defined := c.GetCredentials(registry)
if !defined {
return ""
}

jsonString := fmt.Sprintf(`{ "username": "%s", "password": "%s" }`, username, password)

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

// Load loads a Config object from Docker JSON configuration file specified
Expand Down

0 comments on commit 06a0623

Please sign in to comment.