Skip to content

Commit

Permalink
fix(docker/config): GCR _json_key authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Jun 28, 2019
1 parent 8c56358 commit 005c3ac
Showing 1 changed file with 25 additions and 5 deletions.
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 005c3ac

Please sign in to comment.