feat: add app secret insert

This commit is contained in:
decentral1se 2021-08-31 10:50:02 +02:00
parent f9ae9c9a56
commit d68f2f5686
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 40 additions and 3 deletions

View File

@ -28,7 +28,7 @@
- [ ] `rollback`
- [ ] `secret` (WIP: decentral1se)
- [ ] `generate` (WIP: decentral1se)
- [ ] `insert` (WIP: decentral1se)
- [x] `insert`
- [x] `rm`
- [x] `ls`
- [x] `undeploy`

View File

@ -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: "<secret> <version> <data>",
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
},
}