From c8bd8932a18569455e5d1fae1abfed3c1d3c1e72 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 27 Dec 2022 17:45:19 +0100 Subject: [PATCH] cli/config: use strings.Cut Signed-off-by: Sebastiaan van Stijn --- cli/config/configfile/file.go | 7 +++---- cli/config/credentials/file_store.go | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cli/config/configfile/file.go b/cli/config/configfile/file.go index 796b0a0aed..92ff69368a 100644 --- a/cli/config/configfile/file.go +++ b/cli/config/configfile/file.go @@ -241,12 +241,11 @@ func decodeAuth(authStr string) (string, string, error) { if n > decLen { return "", "", errors.Errorf("Something went wrong decoding auth config") } - arr := strings.SplitN(string(decoded), ":", 2) - if len(arr) != 2 { + userName, password, ok := strings.Cut(string(decoded), ":") + if !ok || userName == "" { return "", "", errors.Errorf("Invalid auth configuration file") } - password := strings.Trim(arr[1], "\x00") - return arr[0], password, nil + return userName, strings.Trim(password, "\x00"), nil } // GetCredentialsStore returns a new credentials store from the settings in the diff --git a/cli/config/credentials/file_store.go b/cli/config/credentials/file_store.go index e509820b73..de1c676e50 100644 --- a/cli/config/credentials/file_store.go +++ b/cli/config/credentials/file_store.go @@ -75,7 +75,6 @@ func ConvertToHostname(url string) string { stripped = strings.TrimPrefix(url, "https://") } - nameParts := strings.SplitN(stripped, "/", 2) - - return nameParts[0] + hostName, _, _ := strings.Cut(stripped, "/") + return hostName }