aboutsummaryrefslogtreecommitdiff
path: root/pkg/auth
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2021-10-21 21:31:22 +0200
committerMiloslav Trmač <mitr@redhat.com>2021-12-10 18:16:27 +0100
commit3cfefa1248feb9de8041b9fc67987b508d4c3fcb (patch)
tree3d426ef42c91b6d32c5f2607a1dadf9929ec3c5d /pkg/auth
parentd79414c54ff89c3deea84e2ac600525744fc75c5 (diff)
downloadpodman-3cfefa1248feb9de8041b9fc67987b508d4c3fcb.tar.gz
podman-3cfefa1248feb9de8041b9fc67987b508d4c3fcb.tar.bz2
podman-3cfefa1248feb9de8041b9fc67987b508d4c3fcb.zip
Remove the authfile parameter of MakeXRegistryAuthHeader
Having a parameter that modifies the provides types.SystemContext seems rather unexpected and risky to have around - and the only user of that is actually a no-op, others only provide a nil SystemContext; so, remove that option and simplify (well, somewhat; many callers now have extra &types.SystemContext{AuthFilePath} boilerplate; at least that's consistent with that code carrying a TODO to create a larger-scope SystemContext). Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'pkg/auth')
-rw-r--r--pkg/auth/auth.go5
-rw-r--r--pkg/auth/auth_test.go28
2 files changed, 15 insertions, 18 deletions
diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go
index 006572b09..2124b5302 100644
--- a/pkg/auth/auth.go
+++ b/pkg/auth/auth.go
@@ -172,7 +172,7 @@ func MakeXRegistryConfigHeader(sys *types.SystemContext, username, password stri
// MakeXRegistryAuthHeader returns a map with the XRegistryAuthHeader set which can
// conveniently be used in the http stack.
-func MakeXRegistryAuthHeader(sys *types.SystemContext, authfile, username, password string) (map[string]string, error) {
+func MakeXRegistryAuthHeader(sys *types.SystemContext, username, password string) (map[string]string, error) {
if username != "" {
content, err := encodeSingleAuthConfig(types.DockerAuthConfig{Username: username, Password: password})
if err != nil {
@@ -184,9 +184,6 @@ func MakeXRegistryAuthHeader(sys *types.SystemContext, authfile, username, passw
if sys == nil {
sys = &types.SystemContext{}
}
- if authfile != "" {
- sys.AuthFilePath = authfile
- }
authConfigs, err := imageAuth.GetAllCredentials(sys)
if err != nil {
return nil, err
diff --git a/pkg/auth/auth_test.go b/pkg/auth/auth_test.go
index a727a9d50..bce488a91 100644
--- a/pkg/auth/auth_test.go
+++ b/pkg/auth/auth_test.go
@@ -29,12 +29,12 @@ var largeAuthFileValues = map[string]types.DockerAuthConfig{
"quay.io": {Username: "quay", Password: "top"},
}
-// tempAuthFilePath returns a non-empty path pointing
-// to a temporary file with fileContents, or "" if fileContents is empty; and a cleanup
-// function the caller must arrange to call.
-func tempAuthFilePath(t *testing.T, fileContents string) (string, func()) {
+// systemContextForAuthFile returns a types.SystemContext with AuthFilePath pointing
+// to a temporary file with fileContents, or nil if fileContents is empty; and a cleanup
+// function the calle rmust arrange to call.
+func systemContextForAuthFile(t *testing.T, fileContents string) (*types.SystemContext, func()) {
if fileContents == "" {
- return "", func() {}
+ return nil, func() {}
}
f, err := ioutil.TempFile("", "auth.json")
@@ -42,7 +42,7 @@ func tempAuthFilePath(t *testing.T, fileContents string) (string, func()) {
path := f.Name()
err = ioutil.WriteFile(path, []byte(fileContents), 0700)
require.NoError(t, err)
- return path, func() { os.Remove(path) }
+ return &types.SystemContext{AuthFilePath: path}, func() { os.Remove(path) }
}
// Test that GetCredentials() correctly parses what MakeXRegistryConfigHeader() produces
@@ -79,9 +79,9 @@ func TestMakeXRegistryConfigHeaderGetCredentialsRoundtrip(t *testing.T) {
expectedFileValues: largeAuthFileValues,
},
} {
- inputAuthFile, cleanup := tempAuthFilePath(t, tc.fileContents)
+ sys, cleanup := systemContextForAuthFile(t, tc.fileContents)
defer cleanup()
- headers, err := MakeXRegistryConfigHeader(&types.SystemContext{AuthFilePath: inputAuthFile}, tc.username, tc.password)
+ headers, err := MakeXRegistryConfigHeader(sys, tc.username, tc.password)
require.NoError(t, err)
req, err := http.NewRequest(http.MethodPost, "/", nil)
require.NoError(t, err, tc.name)
@@ -131,9 +131,9 @@ func TestMakeXRegistryAuthHeaderGetCredentialsRoundtrip(t *testing.T) {
expectedFileValues: largeAuthFileValues,
},
} {
- inputAuthFile, cleanup := tempAuthFilePath(t, tc.fileContents)
+ sys, cleanup := systemContextForAuthFile(t, tc.fileContents)
defer cleanup()
- headers, err := MakeXRegistryAuthHeader(nil, inputAuthFile, tc.username, tc.password)
+ headers, err := MakeXRegistryAuthHeader(sys, tc.username, tc.password)
require.NoError(t, err)
req, err := http.NewRequest(http.MethodPost, "/", nil)
require.NoError(t, err, tc.name)
@@ -206,9 +206,9 @@ func TestMakeXRegistryConfigHeader(t *testing.T) {
}`,
},
} {
- authFile, cleanup := tempAuthFilePath(t, tc.fileContents)
+ sys, cleanup := systemContextForAuthFile(t, tc.fileContents)
defer cleanup()
- res, err := MakeXRegistryConfigHeader(&types.SystemContext{AuthFilePath: authFile}, tc.username, tc.password)
+ res, err := MakeXRegistryConfigHeader(sys, tc.username, tc.password)
if tc.shouldErr {
assert.Error(t, err, tc.name)
} else {
@@ -269,9 +269,9 @@ func TestMakeXRegistryAuthHeader(t *testing.T) {
}`,
},
} {
- authFile, cleanup := tempAuthFilePath(t, tc.fileContents)
+ sys, cleanup := systemContextForAuthFile(t, tc.fileContents)
defer cleanup()
- res, err := MakeXRegistryAuthHeader(nil, authFile, tc.username, tc.password)
+ res, err := MakeXRegistryAuthHeader(sys, tc.username, tc.password)
if tc.shouldErr {
assert.Error(t, err, tc.name)
} else {