summaryrefslogtreecommitdiff
path: root/pkg/auth
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2021-09-11 22:47:52 +0200
committerMiloslav Trmač <mitr@redhat.com>2021-12-10 18:16:21 +0100
commit9d56ebb611e008f5ad09048499331f7aac1ceed3 (patch)
tree597f662511ceb0a3dd16a52b4a5c1b6f47c12b63 /pkg/auth
parentda86a232851162b584a143efa3c4f3032a480413 (diff)
downloadpodman-9d56ebb611e008f5ad09048499331f7aac1ceed3.tar.gz
podman-9d56ebb611e008f5ad09048499331f7aac1ceed3.tar.bz2
podman-9d56ebb611e008f5ad09048499331f7aac1ceed3.zip
Consolidate the error handling path in GetCredentials
We'll share even more code here in the future. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'pkg/auth')
-rw-r--r--pkg/auth/auth.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go
index a95ae4764..a4d7896a8 100644
--- a/pkg/auth/auth.go
+++ b/pkg/auth/auth.go
@@ -37,20 +37,23 @@ func GetCredentials(r *http.Request) (*types.DockerAuthConfig, string, error) {
hdr := r.Header.Values(key.String())
return hdr, len(hdr) > 0
}
+ var override *types.DockerAuthConfig
+ var authFile string
+ var headerName HeaderAuthName
+ var err error
if hdr, ok := nonemptyHeaderValue(XRegistryConfigHeader); ok {
- c, f, err := getConfigCredentials(r, hdr)
- if err != nil {
- return nil, "", errors.Wrapf(err, "failed to parse %q header for %s", XRegistryConfigHeader, r.URL.String())
- }
- return c, f, nil
+ headerName = XRegistryConfigHeader
+ override, authFile, err = getConfigCredentials(r, hdr)
} else if hdr, ok := nonemptyHeaderValue(XRegistryAuthHeader); ok {
- c, f, err := getAuthCredentials(hdr)
- if err != nil {
- return nil, "", errors.Wrapf(err, "failed to parse %q header for %s", XRegistryAuthHeader, r.URL.String())
- }
- return c, f, nil
+ headerName = XRegistryAuthHeader
+ override, authFile, err = getAuthCredentials(hdr)
+ } else {
+ return nil, "", nil
+ }
+ if err != nil {
+ return nil, "", errors.Wrapf(err, "failed to parse %q header for %s", headerName, r.URL.String())
}
- return nil, "", nil
+ return override, authFile, nil
}
// getConfigCredentials extracts one or more docker.AuthConfig from a request and its