cli/config/credentials: skip unneeded exec.LookPath()

defaultCredentialsStore() on Linux does an exec.LookPath() for "pass", but
if a custom credential-store is passed to DetectDefaultStore, the result
of that won't be used.

This patch changes the logic to return early if a custom credential-store
is passed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-05-05 21:10:18 +02:00
parent b403a49207
commit ce11b28d83
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 11 additions and 8 deletions

View File

@ -5,17 +5,20 @@ import (
) )
// DetectDefaultStore return the default credentials store for the platform if // DetectDefaultStore return the default credentials store for the platform if
// the store executable is available. // no user-defined store is passed, and the store executable is available.
func DetectDefaultStore(store string) string { func DetectDefaultStore(store string) string {
platformDefault := defaultCredentialsStore() if store != "" {
// use user-defined
// user defined or no default for platform
if store != "" || platformDefault == "" {
return store return store
} }
if _, err := exec.LookPath(remoteCredentialsPrefix + platformDefault); err == nil { platformDefault := defaultCredentialsStore()
return platformDefault if platformDefault == "" {
return ""
} }
return ""
if _, err := exec.LookPath(remoteCredentialsPrefix + platformDefault); err != nil {
return ""
}
return platformDefault
} }