summaryrefslogtreecommitdiff
path: root/pkg/auth/auth.go
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2021-09-11 22:20:26 +0200
committerMiloslav Trmač <mitr@redhat.com>2021-12-10 18:16:18 +0100
commit7674f2f76b07058aa3bbf44675b7c2482c61811a (patch)
tree04b2e0e22ff805f1a610589fe51f462df64338ed /pkg/auth/auth.go
parent2aeb690d370de9fee15fc7c47b66fb04a30c41d8 (diff)
downloadpodman-7674f2f76b07058aa3bbf44675b7c2482c61811a.tar.gz
podman-7674f2f76b07058aa3bbf44675b7c2482c61811a.tar.bz2
podman-7674f2f76b07058aa3bbf44675b7c2482c61811a.zip
Simplify the interface of parseSingleAuthHeader
Don't create a single-element map only for the only caller to laboriously extract an element of that map; just return a single entry. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'pkg/auth/auth.go')
-rw-r--r--pkg/auth/auth.go18
1 files changed, 5 insertions, 13 deletions
diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go
index c0606cf1d..c19151c91 100644
--- a/pkg/auth/auth.go
+++ b/pkg/auth/auth.go
@@ -121,17 +121,11 @@ func getAuthCredentials(r *http.Request) (*types.DockerAuthConfig, string, error
}
// Fallback to looking for a single-auth header (i.e., one config).
- authConfigs, err = parseSingleAuthHeader(r)
+ authConfig, err := parseSingleAuthHeader(r)
if err != nil {
return nil, "", err
}
- var conf *types.DockerAuthConfig
- for k := range authConfigs {
- c := authConfigs[k]
- conf = &c
- break
- }
- return conf, "", nil
+ return &authConfig, "", nil
}
// Header builds the requested Authentication Header
@@ -321,7 +315,7 @@ func imageAuthToDockerAuth(authConfig types.DockerAuthConfig) dockerAPITypes.Aut
// parseSingleAuthHeader extracts a DockerAuthConfig from the request's header.
// The header content is a single DockerAuthConfig.
-func parseSingleAuthHeader(r *http.Request) (map[string]types.DockerAuthConfig, error) {
+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.
@@ -329,12 +323,10 @@ func parseSingleAuthHeader(r *http.Request) (map[string]types.DockerAuthConfig,
if len(authHeader) > 0 && authHeader != "null" {
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authHeader))
if err := json.NewDecoder(authJSON).Decode(&authConfig); err != nil {
- return nil, err
+ return types.DockerAuthConfig{}, err
}
}
- authConfigs := make(map[string]types.DockerAuthConfig)
- authConfigs["0"] = dockerAuthToImageAuth(authConfig)
- return authConfigs, nil
+ return dockerAuthToImageAuth(authConfig), nil
}
// parseMultiAuthHeader extracts a DockerAuthConfig from the request's header.