summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2021-09-11 23:13:34 +0200
committerMiloslav Trmač <mitr@redhat.com>2021-12-10 18:16:23 +0100
commit78dd79752044d9ccc812a9ebd5a9c708302c0f26 (patch)
tree7ae16c0714d12ef2051560fdf5e5ab999f72bd04 /pkg
parentd073b1275d30b6e7d7b67f71204093dbb283b2de (diff)
downloadpodman-78dd79752044d9ccc812a9ebd5a9c708302c0f26.tar.gz
podman-78dd79752044d9ccc812a9ebd5a9c708302c0f26.tar.bz2
podman-78dd79752044d9ccc812a9ebd5a9c708302c0f26.zip
Turn headerAuth into MakeXRegistryAuthHeader
... which can be called independently. For now, there are no new callers, to test that the behavior has not changed. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/auth/auth.go34
1 files changed, 15 insertions, 19 deletions
diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go
index d4f356f3d..84b2f8ce6 100644
--- a/pkg/auth/auth.go
+++ b/pkg/auth/auth.go
@@ -145,26 +145,14 @@ func getAuthCredentials(headers []string) (*types.DockerAuthConfig, map[string]t
// Header builds the requested Authentication Header
func Header(sys *types.SystemContext, headerName HeaderAuthName, authfile, username, password string) (map[string]string, error) {
- var (
- content string
- err error
- )
switch headerName {
case XRegistryAuthHeader:
- content, err = headerAuth(sys, authfile, username, password)
+ return MakeXRegistryAuthHeader(sys, authfile, username, password)
case XRegistryConfigHeader:
return MakeXRegistryConfigHeader(sys, authfile, username, password)
default:
- err = fmt.Errorf("unsupported authentication header: %q", headerName)
+ return nil, fmt.Errorf("unsupported authentication header: %q", headerName)
}
- if err != nil {
- return nil, err
- }
-
- if len(content) > 0 {
- return map[string]string{string(headerName): content}, nil
- }
- return nil, nil
}
// MakeXRegistryConfigHeader returns a map with the XRegistryConfigHeader set which can
@@ -198,11 +186,15 @@ func MakeXRegistryConfigHeader(sys *types.SystemContext, authfile, username, pas
return map[string]string{XRegistryConfigHeader.String(): content}, nil
}
-// headerAuth returns a base64 encoded map with the XRegistryAuthHeader set which can
+// MakeXRegistryAuthHeader returns a map with the XRegistryAuthHeader set which can
// conveniently be used in the http stack.
-func headerAuth(sys *types.SystemContext, authfile, username, password string) (string, error) {
+func MakeXRegistryAuthHeader(sys *types.SystemContext, authfile, username, password string) (map[string]string, error) {
if username != "" {
- return encodeSingleAuthConfig(types.DockerAuthConfig{Username: username, Password: password})
+ content, err := encodeSingleAuthConfig(types.DockerAuthConfig{Username: username, Password: password})
+ if err != nil {
+ return nil, err
+ }
+ return map[string]string{XRegistryAuthHeader.String(): content}, nil
}
if sys == nil {
@@ -213,9 +205,13 @@ func headerAuth(sys *types.SystemContext, authfile, username, password string) (
}
authConfigs, err := imageAuth.GetAllCredentials(sys)
if err != nil {
- return "", err
+ return nil, err
+ }
+ content, err := encodeMultiAuthConfigs(authConfigs)
+ if err != nil {
+ return nil, err
}
- return encodeMultiAuthConfigs(authConfigs)
+ return map[string]string{XRegistryAuthHeader.String(): content}, nil
}
// RemoveAuthfile is a convenience function that is meant to be called in a