aboutsummaryrefslogtreecommitdiff
path: root/pkg/auth
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2021-09-11 22:15:23 +0200
committerMiloslav Trmač <mitr@redhat.com>2021-12-10 18:16:18 +0100
commit2aeb690d370de9fee15fc7c47b66fb04a30c41d8 (patch)
tree4335e8b649f5a4e5ed53b430fea613e7fe199c59 /pkg/auth
parent491951d66e1829ad8e847f3049a557dd9d55db68 (diff)
downloadpodman-2aeb690d370de9fee15fc7c47b66fb04a30c41d8.tar.gz
podman-2aeb690d370de9fee15fc7c47b66fb04a30c41d8.tar.bz2
podman-2aeb690d370de9fee15fc7c47b66fb04a30c41d8.zip
Don't return a header name from auth.GetCredentials
Almost every caller is using it only to wrap an error in exactly the same way, so move that error context into GetCredentials and simplify the users. (The one other caller, build, was even wrapping the error incorrectly talking about query parameters; so let it use the same text as the others.) Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'pkg/auth')
-rw-r--r--pkg/auth/auth.go14
-rw-r--r--pkg/auth/auth_test.go8
2 files changed, 11 insertions, 11 deletions
diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go
index 7cde6ef5e..c0606cf1d 100644
--- a/pkg/auth/auth.go
+++ b/pkg/auth/auth.go
@@ -32,17 +32,23 @@ const XRegistryConfigHeader HeaderAuthName = "X-Registry-Config"
// GetCredentials queries the http.Request for X-Registry-.* headers and extracts
// the necessary authentication information for libpod operations
-func GetCredentials(r *http.Request) (*types.DockerAuthConfig, string, HeaderAuthName, error) {
+func GetCredentials(r *http.Request) (*types.DockerAuthConfig, string, error) {
has := func(key HeaderAuthName) bool { hdr, found := r.Header[string(key)]; return found && len(hdr) > 0 }
switch {
case has(XRegistryConfigHeader):
c, f, err := getConfigCredentials(r)
- return c, f, XRegistryConfigHeader, err
+ if err != nil {
+ return nil, "", errors.Wrapf(err, "failed to parse %q header for %s", XRegistryConfigHeader, r.URL.String())
+ }
+ return c, f, nil
case has(XRegistryAuthHeader):
c, f, err := getAuthCredentials(r)
- return c, f, XRegistryAuthHeader, err
+ if err != nil {
+ return nil, "", errors.Wrapf(err, "failed to parse %q header for %s", XRegistryAuthHeader, r.URL.String())
+ }
+ return c, f, nil
}
- return nil, "", "", nil
+ return nil, "", nil
}
// getConfigCredentials extracts one or more docker.AuthConfig from the request's
diff --git a/pkg/auth/auth_test.go b/pkg/auth/auth_test.go
index be86a9cbd..634215acf 100644
--- a/pkg/auth/auth_test.go
+++ b/pkg/auth/auth_test.go
@@ -104,7 +104,7 @@ func TestHeaderGetCredentialsRoundtrip(t *testing.T) {
req.Header.Set(k, v)
}
- override, resPath, parsedHeader, err := GetCredentials(req)
+ override, resPath, err := GetCredentials(req)
require.NoError(t, err, name)
defer RemoveAuthfile(resPath)
if tc.expectedOverride == nil {
@@ -118,12 +118,6 @@ func TestHeaderGetCredentialsRoundtrip(t *testing.T) {
require.NoError(t, err, name)
assert.Equal(t, expectedAuth, auth, "%s, key %s", name, key)
}
- if len(headers) != 0 {
- assert.Len(t, headers, 1)
- assert.Equal(t, tc.headerName, parsedHeader)
- } else {
- assert.Equal(t, HeaderAuthName(""), parsedHeader)
- }
}
}