From 8155fb5658a3a282550b39b2c3a6cd80bc9653d1 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 11 Sep 2021 23:00:02 +0200 Subject: Turn headerConfig into MakeXRegistryConfigHeader 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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'pkg/auth') diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index a17297c7d..d4f356f3d 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -153,7 +153,7 @@ func Header(sys *types.SystemContext, headerName HeaderAuthName, authfile, usern case XRegistryAuthHeader: content, err = headerAuth(sys, authfile, username, password) case XRegistryConfigHeader: - content, err = headerConfig(sys, authfile, username, password) + return MakeXRegistryConfigHeader(sys, authfile, username, password) default: err = fmt.Errorf("unsupported authentication header: %q", headerName) } @@ -167,9 +167,9 @@ func Header(sys *types.SystemContext, headerName HeaderAuthName, authfile, usern return nil, nil } -// headerConfig returns a map with the XRegistryConfigHeader set which can +// MakeXRegistryConfigHeader returns a map with the XRegistryConfigHeader set which can // conveniently be used in the http stack. -func headerConfig(sys *types.SystemContext, authfile, username, password string) (string, error) { +func MakeXRegistryConfigHeader(sys *types.SystemContext, authfile, username, password string) (map[string]string, error) { if sys == nil { sys = &types.SystemContext{} } @@ -178,7 +178,7 @@ func headerConfig(sys *types.SystemContext, authfile, username, password string) } authConfigs, err := imageAuth.GetAllCredentials(sys) if err != nil { - return "", err + return nil, err } if username != "" { @@ -189,9 +189,13 @@ func headerConfig(sys *types.SystemContext, authfile, username, password string) } if len(authConfigs) == 0 { - return "", nil + return nil, nil } - return encodeMultiAuthConfigs(authConfigs) + content, err := encodeMultiAuthConfigs(authConfigs) + if err != nil { + return nil, err + } + return map[string]string{XRegistryConfigHeader.String(): content}, nil } // headerAuth returns a base64 encoded map with the XRegistryAuthHeader set which can -- cgit v1.2.3-54-g00ecf