From 78dd79752044d9ccc812a9ebd5a9c708302c0f26 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 11 Sep 2021 23:13:34 +0200 Subject: Turn headerAuth into MakeXRegistryAuthHeader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... 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č --- pkg/auth/auth.go | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'pkg') 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 -- cgit v1.2.3-54-g00ecf