From 159e1cee7dc59a08911e7e4f16bae8030963d745 Mon Sep 17 00:00:00 2001 From: Romain Le Jeune Date: Mon, 13 Nov 2023 13:58:03 +0000 Subject: [PATCH] fix(GODT-2277): Fix keychains initialisation in vault-editor. --- internal/app/app.go | 6 +++--- utils/vault-editor/main.go | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index e87f22b3..f4e36035 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -236,7 +236,7 @@ func run(c *cli.Context) error { return withSingleInstance(settings, locations.GetLockFile(), version, func() error { // Look for available keychains - return withKeychainList(func(keychains *keychain.List) error { + return WithKeychainList(func(keychains *keychain.List) error { // Unlock the encrypted vault. return WithVault(locations, keychains, crashHandler, func(v *vault.Vault, insecure, corrupt bool) error { if !v.Migrated() { @@ -484,8 +484,8 @@ func withCookieJar(vault *vault.Vault, fn func(http.CookieJar) error) error { return fn(persister) } -// List usable keychains. -func withKeychainList(fn func(*keychain.List) error) error { +// WithKeychainList init the list of usable keychains. +func WithKeychainList(fn func(*keychain.List) error) error { logrus.Debug("Creating keychain list") defer logrus.Debug("Keychain list stop") return fn(keychain.NewList()) diff --git a/utils/vault-editor/main.go b/utils/vault-editor/main.go index 475ecad9..e2156b1e 100644 --- a/utils/vault-editor/main.go +++ b/utils/vault-editor/main.go @@ -28,6 +28,7 @@ import ( "github.com/ProtonMail/proton-bridge/v3/internal/app" "github.com/ProtonMail/proton-bridge/v3/internal/locations" "github.com/ProtonMail/proton-bridge/v3/internal/vault" + "github.com/ProtonMail/proton-bridge/v3/pkg/keychain" "github.com/urfave/cli/v2" ) @@ -50,12 +51,14 @@ func main() { func readAction(c *cli.Context) error { return app.WithLocations(func(locations *locations.Locations) error { - return app.WithVault(locations, nil, async.NoopPanicHandler{}, func(vault *vault.Vault, insecure, corrupt bool) error { - if _, err := os.Stdout.Write(vault.ExportJSON()); err != nil { - return fmt.Errorf("failed to write vault: %w", err) - } + return app.WithKeychainList(func(keychains *keychain.List) 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 { + return fmt.Errorf("failed to write vault: %w", err) + } - return nil + return nil + }) }) }) }