chore: Get better logging arround keychain list initialisation.

This commit is contained in:
Romain LE JEUNE
2023-12-14 16:41:00 +01:00
parent 5c69af4418
commit 8f5bd37aee
5 changed files with 15 additions and 9 deletions

View File

@ -236,7 +236,7 @@ func run(c *cli.Context) error {
return withSingleInstance(settings, locations.GetLockFile(), version, func() error { return withSingleInstance(settings, locations.GetLockFile(), version, func() error {
// Look for available keychains // Look for available keychains
return WithKeychainList(func(keychains *keychain.List) error { return WithKeychainList(crashHandler, func(keychains *keychain.List) error {
// Unlock the encrypted vault. // Unlock the encrypted vault.
return WithVault(locations, keychains, crashHandler, func(v *vault.Vault, insecure, corrupt bool) error { return WithVault(locations, keychains, crashHandler, func(v *vault.Vault, insecure, corrupt bool) error {
if !v.Migrated() { if !v.Migrated() {
@ -482,9 +482,10 @@ func withCookieJar(vault *vault.Vault, fn func(http.CookieJar) error) error {
} }
// WithKeychainList init the list of usable keychains. // WithKeychainList init the list of usable keychains.
func WithKeychainList(fn func(*keychain.List) error) error { func WithKeychainList(panicHandler async.PanicHandler, fn func(*keychain.List) error) error {
logrus.Debug("Creating keychain list") logrus.Debug("Creating keychain list")
defer logrus.Debug("Keychain list stop") defer logrus.Debug("Keychain list stop")
defer async.HandlePanic(panicHandler)
return fn(keychain.NewList()) return fn(keychain.NewList())
} }

View File

@ -37,8 +37,9 @@ func listHelpers() (Helpers, string) {
// MacOS always provides a keychain. // MacOS always provides a keychain.
if isUsable(newMacOSHelper("")) { if isUsable(newMacOSHelper("")) {
helpers[MacOSKeychain] = newMacOSHelper helpers[MacOSKeychain] = newMacOSHelper
logrus.WithField("keychain", "MacOSKeychain").Info("Keychain is usable.")
} else { } else {
logrus.WithField("keychain", "MacOSKeychain").Warn("Keychain is not available.") logrus.WithField("keychain", "MacOSKeychain").Debug("Keychain is not available.")
} }
// Use MacOSKeychain by default. // Use MacOSKeychain by default.

View File

@ -36,20 +36,23 @@ func listHelpers() (Helpers, string) {
if isUsable(newDBusHelper("")) { if isUsable(newDBusHelper("")) {
helpers[SecretServiceDBus] = newDBusHelper helpers[SecretServiceDBus] = newDBusHelper
logrus.WithField("keychain", "SecretServiceDBus").Info("Keychain is usable.")
} else { } else {
logrus.WithField("keychain", "SecretServiceDBus").Warn("Keychain is not available.") logrus.WithField("keychain", "SecretServiceDBus").Debug("Keychain is not available.")
} }
if _, err := execabs.LookPath("gnome-keyring"); err == nil && isUsable(newSecretServiceHelper("")) { if _, err := execabs.LookPath("gnome-keyring"); err == nil && isUsable(newSecretServiceHelper("")) {
helpers[SecretService] = newSecretServiceHelper helpers[SecretService] = newSecretServiceHelper
logrus.WithField("keychain", "SecretService").Info("Keychain is usable.")
} else { } else {
logrus.WithField("keychain", "SecretService").Warn("Keychain is not available.") logrus.WithField("keychain", "SecretService").Debug("Keychain is not available.")
} }
if _, err := execabs.LookPath("pass"); err == nil && isUsable(newPassHelper("")) { if _, err := execabs.LookPath("pass"); err == nil && isUsable(newPassHelper("")) {
helpers[Pass] = newPassHelper helpers[Pass] = newPassHelper
logrus.WithField("keychain", "Pass").Info("Keychain is usable.")
} else { } else {
logrus.WithField("keychain", "Pass").Warn("Keychain is not available.") logrus.WithField("keychain", "Pass").Debug("Keychain is not available.")
} }
defaultHelper := SecretServiceDBus defaultHelper := SecretServiceDBus

View File

@ -30,8 +30,9 @@ func listHelpers() (Helpers, string) {
// Windows always provides a keychain. // Windows always provides a keychain.
if isUsable(newWinCredHelper("")) { if isUsable(newWinCredHelper("")) {
helpers[WindowsCredentials] = newWinCredHelper helpers[WindowsCredentials] = newWinCredHelper
logrus.WithField("keychain", "WindowsCredentials").Info("Keychain is usable.")
} else { } else {
logrus.WithField("keychain", "WindowsCredentials").Warn("Keychain is not available.") logrus.WithField("keychain", "WindowsCredentials").Debug("Keychain is not available.")
} }
// Use WindowsCredentials by default. // Use WindowsCredentials by default.
return helpers, WindowsCredentials return helpers, WindowsCredentials

View File

@ -51,7 +51,7 @@ func main() {
func readAction(c *cli.Context) error { func readAction(c *cli.Context) error {
return app.WithLocations(func(locations *locations.Locations) error { return app.WithLocations(func(locations *locations.Locations) error {
return app.WithKeychainList(func(keychains *keychain.List) error { return app.WithKeychainList(async.NoopPanicHandler{}, func(keychains *keychain.List) error {
return app.WithVault(locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, insecure, corrupt bool) error { return app.WithVault(locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, insecure, corrupt bool) error {
if _, err := os.Stdout.Write(vault.ExportJSON()); err != nil { if _, err := os.Stdout.Write(vault.ExportJSON()); err != nil {
return fmt.Errorf("failed to write vault: %w", err) return fmt.Errorf("failed to write vault: %w", err)
@ -65,7 +65,7 @@ func readAction(c *cli.Context) error {
func writeAction(c *cli.Context) error { func writeAction(c *cli.Context) error {
return app.WithLocations(func(locations *locations.Locations) error { return app.WithLocations(func(locations *locations.Locations) error {
return app.WithKeychainList(func(keychains *keychain.List) error { return app.WithKeychainList(async.NoopPanicHandler{}, func(keychains *keychain.List) error {
return app.WithVault(locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, insecure, corrupt bool) error { return app.WithVault(locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, insecure, corrupt bool) error {
b, err := io.ReadAll(os.Stdin) b, err := io.ReadAll(os.Stdin)
if err != nil { if err != nil {