From d68f2f5686a210666e9b669698252a28595f379d Mon Sep 17 00:00:00 2001 From: decentral1se Date: Tue, 31 Aug 2021 10:50:02 +0200 Subject: [PATCH] feat: add app secret insert --- TODO.md | 2 +- cli/app/secret.go | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index a84413030..4232e120c 100644 --- a/TODO.md +++ b/TODO.md @@ -28,7 +28,7 @@ - [ ] `rollback` - [ ] `secret` (WIP: decentral1se) - [ ] `generate` (WIP: decentral1se) - - [ ] `insert` (WIP: decentral1se) + - [x] `insert` - [x] `rm` - [x] `ls` - [x] `undeploy` diff --git a/cli/app/secret.go b/cli/app/secret.go index 6f1215ee0..a4722f1ad 100644 --- a/cli/app/secret.go +++ b/cli/app/secret.go @@ -34,9 +34,46 @@ var appSecretGenerateCommand = &cli.Command{ } var appSecretInsertCommand = &cli.Command{ - Name: "insert", - Usage: "Insert secret", + Name: "insert", + Usage: "Insert secret", + Flags: []cli.Flag{internal.PassFlag}, + ArgsUsage: " ", Action: func(c *cli.Context) error { + appName := c.Args().First() + if appName == "" { + internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided")) + } + + if c.Args().Len() != 4 { + internal.ShowSubcommandHelpAndError(c, errors.New("missing arguments?")) + } + + name := c.Args().Get(1) + version := c.Args().Get(2) + data := c.Args().Get(3) + + appFiles, err := config.LoadAppFiles("") + if err != nil { + logrus.Fatal(err) + } + + appEnv, err := config.GetApp(appFiles, appName) + if err != nil { + logrus.Fatal(err) + } + + host := appFiles[appName].Server + secretName := fmt.Sprintf("%s_%s_%s", appEnv.StackName(), name, version) + if err := client.StoreSecret(secretName, data, host); err != nil { + logrus.Fatal(err) + } + + if internal.Pass { + if err := secret.PassInsertSecret(data, name, appEnv.StackName(), host); err != nil { + logrus.Fatal(err) + } + } + return nil }, }