From cfae8523a18bdc89ad7de3fb5368fbd4408adeae Mon Sep 17 00:00:00 2001 From: tigattack <10629864+tigattack@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:22:08 +0000 Subject: [PATCH] [cli] Don't perform CLI secret initialisation when not needed Calling `GetOrCreateClISecret()` can cause issues in some unattended scenarios. --- cli/main.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cli/main.go b/cli/main.go index 7b0312485e..79c8500dc3 100644 --- a/cli/main.go +++ b/cli/main.go @@ -49,14 +49,28 @@ func main() { panic(err) } } + + // Define a set of commands that do not require KeyHolder initialisation. + skipKeyHolderCommands := map[string]struct{}{"version": {}, "docs": {}, "help": {}} + + var keyHolder *secrets.KeyHolder + + // Only initialise KeyHolder if the command isn't in the skip list. + if len(os.Args) > 1 { + if _, skip := skipKeyHolderCommands[os.Args[1]]; !skip { + keyHolder = secrets.NewKeyHolder(secrets.GetOrCreateClISecret()) + } + } + ctrl := pkg.ClICtrl{ Client: api.NewClient(api.Params{ Debug: viper.GetBool("log.http"), Host: viper.GetString("endpoint.api"), }), DB: db, - KeyHolder: secrets.NewKeyHolder(secrets.GetOrCreateClISecret()), + KeyHolder: keyHolder, } + err = ctrl.Init() if err != nil { panic(err)