Simplify parseSingleAuthHeader

In the "no input" case, return a constant instead of
continuing with the decode/convert path, converting empty data.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač
2021-09-11 22:22:21 +02:00
parent 7674f2f76b
commit 6f1a26b04f

View File

@ -317,14 +317,16 @@ func imageAuthToDockerAuth(authConfig types.DockerAuthConfig) dockerAPITypes.Aut
// The header content is a single DockerAuthConfig.
func parseSingleAuthHeader(r *http.Request) (types.DockerAuthConfig, error) {
authHeader := r.Header.Get(string(XRegistryAuthHeader))
authConfig := dockerAPITypes.AuthConfig{}
// Accept "null" and handle it as empty value for compatibility reason with Docker.
// Some java docker clients pass this value, e.g. this one used in Eclipse.
if len(authHeader) > 0 && authHeader != "null" {
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authHeader))
if err := json.NewDecoder(authJSON).Decode(&authConfig); err != nil {
return types.DockerAuthConfig{}, err
}
if len(authHeader) == 0 || authHeader == "null" {
return types.DockerAuthConfig{}, nil
}
authConfig := dockerAPITypes.AuthConfig{}
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authHeader))
if err := json.NewDecoder(authJSON).Decode(&authConfig); err != nil {
return types.DockerAuthConfig{}, err
}
return dockerAuthToImageAuth(authConfig), nil
}