From 238647a987a7dc007805f9adb9876c978d179d60 Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Mon, 25 Aug 2025 17:16:50 -0400 Subject: [PATCH 1/3] Prompt for secrets if not provided on CLI Re #646 --- cli/app/secret.go | 39 +++++++++++++++++++++++++------ tests/integration/app_secret.bats | 3 +++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/cli/app/secret.go b/cli/app/secret.go index 550714b2..22014354 100644 --- a/cli/app/secret.go +++ b/cli/app/secret.go @@ -15,6 +15,7 @@ import ( "coopcloud.tech/abra/pkg/i18n" "coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/secret" + "github.com/AlecAivazis/survey/v2" "github.com/docker/docker/api/types" dockerClient "github.com/docker/docker/client" "github.com/spf13/cobra" @@ -28,7 +29,8 @@ var AppSecretGenerateCommand = &cobra.Command{ ValidArgsFunction: func( cmd *cobra.Command, args []string, - toComplete string) ([]string, cobra.ShellCompDirective) { + toComplete string, + ) ([]string, cobra.ShellCompDirective) { switch l := len(args); l { case 0: return autocomplete.AppNameComplete() @@ -140,7 +142,7 @@ var AppSecretGenerateCommand = &cobra.Command{ } var AppSecretInsertCommand = &cobra.Command{ - Use: i18n.G("insert [flags]"), + Use: i18n.G("insert [] [flags]"), Aliases: []string{i18n.G("i")}, Short: i18n.G("Insert secret"), Long: i18n.G(`This command inserts a secret into an app environment. @@ -156,11 +158,12 @@ environment. Typically, you can let Abra generate them for you on app creation # insert secret as file abra app secret insert 1312.net my_secret v1 secret.txt -f`), - Args: cobra.MinimumNArgs(4), + Args: cobra.MinimumNArgs(3), ValidArgsFunction: func( cmd *cobra.Command, args []string, - toComplete string) ([]string, cobra.ShellCompDirective) { + toComplete string, + ) ([]string, cobra.ShellCompDirective) { switch l := len(args); l { case 0: return autocomplete.AppNameComplete() @@ -188,7 +191,13 @@ environment. Typically, you can let Abra generate them for you on app creation name := args[1] version := args[2] - data := args[3] + data := "" + + if len(args) > 3 { + data = args[3] + } else if internal.NoInput { + log.Fatal("Must provide argument if --no-input is passed") + } composeFiles, err := app.Recipe.GetComposeFiles(app.Env) if err != nil { @@ -210,6 +219,20 @@ environment. Typically, you can let Abra generate them for you on app creation log.Fatal(i18n.G("no secret %s available for recipe %s?", name, app.Recipe.Name)) } + if data == "" && !internal.NoInput { + log.Debug("Secret data not provided on command-line, prompting") + message := "Specify secret value" + if insertFromFile { + message = "Specify secret file" + } + prompt := &survey.Input{ + Message: i18n.G(message), + } + if err := survey.AskOne(prompt, &data); err != nil { + log.Fatal(err) + } + } + if insertFromFile { raw, err := os.ReadFile(data) if err != nil { @@ -269,7 +292,8 @@ match those configured in the recipe beforehand.`), ValidArgsFunction: func( cmd *cobra.Command, args []string, - toComplete string) ([]string, cobra.ShellCompDirective) { + toComplete string, + ) ([]string, cobra.ShellCompDirective) { switch l := len(args); l { case 0: return autocomplete.AppNameComplete() @@ -376,7 +400,8 @@ var AppSecretLsCommand = &cobra.Command{ ValidArgsFunction: func( cmd *cobra.Command, args []string, - toComplete string) ([]string, cobra.ShellCompDirective) { + toComplete string, + ) ([]string, cobra.ShellCompDirective) { return autocomplete.AppNameComplete() }, Run: func(cmd *cobra.Command, args []string) { diff --git a/tests/integration/app_secret.bats b/tests/integration/app_secret.bats index 11151c9a..ce4a0cd7 100644 --- a/tests/integration/app_secret.bats +++ b/tests/integration/app_secret.bats @@ -208,6 +208,9 @@ teardown(){ run $ABRA app secret insert "$TEST_APP_DOMAIN" bar baz assert_failure + + run $ABRA app secret insert "$TEST_APP_DOMAIN" test_pass_one v1 -n + assert_failure } @test "insert: cannot insert unknown secret" { -- 2.49.0 From 7b7477062fed950bc2860fd96995c56bd2affdec Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Mon, 25 Aug 2025 18:12:15 -0400 Subject: [PATCH 2/3] Implement PR feedback --- cli/app/secret.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cli/app/secret.go b/cli/app/secret.go index 22014354..a5e8422d 100644 --- a/cli/app/secret.go +++ b/cli/app/secret.go @@ -196,7 +196,7 @@ environment. Typically, you can let Abra generate them for you on app creation if len(args) > 3 { data = args[3] } else if internal.NoInput { - log.Fatal("Must provide argument if --no-input is passed") + log.Fatal(i18n.G("must provide argument if --no-input is passed")) } composeFiles, err := app.Recipe.GetComposeFiles(app.Env) @@ -221,12 +221,15 @@ environment. Typically, you can let Abra generate them for you on app creation if data == "" && !internal.NoInput { log.Debug("Secret data not provided on command-line, prompting") - message := "Specify secret value" - if insertFromFile { - message = "Specify secret file" - } - prompt := &survey.Input{ - Message: i18n.G(message), + var prompt survey.Prompt + if !insertFromFile { + prompt = &survey.Password{ + Message: i18n.G("Specify secret value"), + } + } else { + prompt = &survey.Input{ + Message: i18n.G("Specify secret file"), + } } if err := survey.AskOne(prompt, &data); err != nil { log.Fatal(err) -- 2.49.0 From 7dd7f763f4fc6418109069d6c163a4016102fdff Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Tue, 26 Aug 2025 13:15:06 -0400 Subject: [PATCH 3/3] Moar PR feedback --- cli/app/secret.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/app/secret.go b/cli/app/secret.go index a5e8422d..5653c9e9 100644 --- a/cli/app/secret.go +++ b/cli/app/secret.go @@ -220,15 +220,15 @@ environment. Typically, you can let Abra generate them for you on app creation } if data == "" && !internal.NoInput { - log.Debug("Secret data not provided on command-line, prompting") + log.Debug(i18n.G("secret data not provided on command-line, prompting")) var prompt survey.Prompt if !insertFromFile { prompt = &survey.Password{ - Message: i18n.G("Specify secret value"), + Message: i18n.G("specify secret value"), } } else { prompt = &survey.Input{ - Message: i18n.G("Specify secret file"), + Message: i18n.G("specify secret file"), } } if err := survey.AskOne(prompt, &data); err != nil { -- 2.49.0