From 2e16fdef551c607d3dec46e80b3b617d168a2dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Tue, 7 Nov 2023 18:07:43 +0100 Subject: [PATCH] Generalize CheckAuthFile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... so that it can be used with a future --compat-auth-file option. Signed-off-by: Miloslav Trmač --- pkg/auth/auth.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index ff59e6cdf..6e001a753 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -49,14 +49,13 @@ func GetDefaultAuthFile() string { return "" } -// CheckAuthFile validates filepath given by --authfile -// used by command has --authfile flag -func CheckAuthFile(authfile string) error { - if authfile == "" { +// CheckAuthFile validates a path option, failing if the option is set but the referenced file is not accessible. +func CheckAuthFile(pathOption string) error { + if pathOption == "" { return nil } - if _, err := os.Stat(authfile); err != nil { - return fmt.Errorf("checking authfile: %w", err) + if _, err := os.Stat(pathOption); err != nil { + return fmt.Errorf("credential file is not accessible: %w", err) } return nil }