aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2021-09-11 22:22:21 +0200
committerMiloslav Trmač <mitr@redhat.com>2021-12-10 18:16:19 +0100
commit6f1a26b04f9a35a649f80c07be2e3372bc65d60a (patch)
treeca9dfbdbb36a569853ffe136753b8381eab3067e
parent7674f2f76b07058aa3bbf44675b7c2482c61811a (diff)
downloadpodman-6f1a26b04f9a35a649f80c07be2e3372bc65d60a.tar.gz
podman-6f1a26b04f9a35a649f80c07be2e3372bc65d60a.tar.bz2
podman-6f1a26b04f9a35a649f80c07be2e3372bc65d60a.zip
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>
-rw-r--r--pkg/auth/auth.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go
index c19151c91..b3fd71184 100644
--- a/pkg/auth/auth.go
+++ b/pkg/auth/auth.go
@@ -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
}