forked from toolshed/abra
@ -15,6 +15,7 @@ import (
|
|||||||
"coopcloud.tech/abra/pkg/i18n"
|
"coopcloud.tech/abra/pkg/i18n"
|
||||||
"coopcloud.tech/abra/pkg/log"
|
"coopcloud.tech/abra/pkg/log"
|
||||||
"coopcloud.tech/abra/pkg/secret"
|
"coopcloud.tech/abra/pkg/secret"
|
||||||
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
dockerClient "github.com/docker/docker/client"
|
dockerClient "github.com/docker/docker/client"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -28,7 +29,8 @@ var AppSecretGenerateCommand = &cobra.Command{
|
|||||||
ValidArgsFunction: func(
|
ValidArgsFunction: func(
|
||||||
cmd *cobra.Command,
|
cmd *cobra.Command,
|
||||||
args []string,
|
args []string,
|
||||||
toComplete string) ([]string, cobra.ShellCompDirective) {
|
toComplete string,
|
||||||
|
) ([]string, cobra.ShellCompDirective) {
|
||||||
switch l := len(args); l {
|
switch l := len(args); l {
|
||||||
case 0:
|
case 0:
|
||||||
return autocomplete.AppNameComplete()
|
return autocomplete.AppNameComplete()
|
||||||
@ -140,7 +142,7 @@ var AppSecretGenerateCommand = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var AppSecretInsertCommand = &cobra.Command{
|
var AppSecretInsertCommand = &cobra.Command{
|
||||||
Use: i18n.G("insert <domain> <secret> <version> <data> [flags]"),
|
Use: i18n.G("insert <domain> <secret> <version> [<data>] [flags]"),
|
||||||
Aliases: []string{i18n.G("i")},
|
Aliases: []string{i18n.G("i")},
|
||||||
Short: i18n.G("Insert secret"),
|
Short: i18n.G("Insert secret"),
|
||||||
Long: i18n.G(`This command inserts a secret into an app environment.
|
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
|
# insert secret as file
|
||||||
abra app secret insert 1312.net my_secret v1 secret.txt -f`),
|
abra app secret insert 1312.net my_secret v1 secret.txt -f`),
|
||||||
Args: cobra.MinimumNArgs(4),
|
Args: cobra.MinimumNArgs(3),
|
||||||
ValidArgsFunction: func(
|
ValidArgsFunction: func(
|
||||||
cmd *cobra.Command,
|
cmd *cobra.Command,
|
||||||
args []string,
|
args []string,
|
||||||
toComplete string) ([]string, cobra.ShellCompDirective) {
|
toComplete string,
|
||||||
|
) ([]string, cobra.ShellCompDirective) {
|
||||||
switch l := len(args); l {
|
switch l := len(args); l {
|
||||||
case 0:
|
case 0:
|
||||||
return autocomplete.AppNameComplete()
|
return autocomplete.AppNameComplete()
|
||||||
@ -188,7 +191,13 @@ environment. Typically, you can let Abra generate them for you on app creation
|
|||||||
|
|
||||||
name := args[1]
|
name := args[1]
|
||||||
version := args[2]
|
version := args[2]
|
||||||
data := args[3]
|
data := ""
|
||||||
|
|
||||||
|
if len(args) > 3 {
|
||||||
|
data = args[3]
|
||||||
|
} else if internal.NoInput {
|
||||||
|
log.Fatal("Must provide <data> argument if --no-input is passed")
|
||||||
|
}
|
||||||
|
|
||||||
composeFiles, err := app.Recipe.GetComposeFiles(app.Env)
|
composeFiles, err := app.Recipe.GetComposeFiles(app.Env)
|
||||||
if err != nil {
|
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))
|
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 {
|
if insertFromFile {
|
||||||
raw, err := os.ReadFile(data)
|
raw, err := os.ReadFile(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -269,7 +292,8 @@ match those configured in the recipe beforehand.`),
|
|||||||
ValidArgsFunction: func(
|
ValidArgsFunction: func(
|
||||||
cmd *cobra.Command,
|
cmd *cobra.Command,
|
||||||
args []string,
|
args []string,
|
||||||
toComplete string) ([]string, cobra.ShellCompDirective) {
|
toComplete string,
|
||||||
|
) ([]string, cobra.ShellCompDirective) {
|
||||||
switch l := len(args); l {
|
switch l := len(args); l {
|
||||||
case 0:
|
case 0:
|
||||||
return autocomplete.AppNameComplete()
|
return autocomplete.AppNameComplete()
|
||||||
@ -376,7 +400,8 @@ var AppSecretLsCommand = &cobra.Command{
|
|||||||
ValidArgsFunction: func(
|
ValidArgsFunction: func(
|
||||||
cmd *cobra.Command,
|
cmd *cobra.Command,
|
||||||
args []string,
|
args []string,
|
||||||
toComplete string) ([]string, cobra.ShellCompDirective) {
|
toComplete string,
|
||||||
|
) ([]string, cobra.ShellCompDirective) {
|
||||||
return autocomplete.AppNameComplete()
|
return autocomplete.AppNameComplete()
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
@ -208,6 +208,9 @@ teardown(){
|
|||||||
|
|
||||||
run $ABRA app secret insert "$TEST_APP_DOMAIN" bar baz
|
run $ABRA app secret insert "$TEST_APP_DOMAIN" bar baz
|
||||||
assert_failure
|
assert_failure
|
||||||
|
|
||||||
|
run $ABRA app secret insert "$TEST_APP_DOMAIN" test_pass_one v1 -n
|
||||||
|
assert_failure
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "insert: cannot insert unknown secret" {
|
@test "insert: cannot insert unknown secret" {
|
||||||
|
Reference in New Issue
Block a user