feat: add app secret rm

This commit is contained in:
2021-08-31 10:31:54 +02:00
parent 15651822f1
commit f9ae9c9a56
3 changed files with 91 additions and 4 deletions

View File

@ -65,6 +65,13 @@ func ParseSecretEnvVarName(secretEnvVar string) string {
return strings.ToLower(withoutSuffix)
}
func ParseGeneratedSecretName(secret string, appEnv config.App) string {
name := fmt.Sprintf("%s_", appEnv.StackName())
withoutAppName := strings.TrimPrefix(secret, name)
idx := strings.LastIndex(withoutAppName, "_")
return withoutAppName[:idx]
}
func ParseSecretEnvVarValue(secretValue string) (SecretValue, error) {
values := strings.Split(secretValue, "#")
if len(values) == 0 {
@ -150,3 +157,21 @@ func PassInsertSecret(secretValue, secretName, appName, server string) error {
return nil
}
func PassRmSecret(secretName, appName, server string) error {
_, err := exec.LookPath("pass")
if err != nil {
return errors.New("pass cannot be found on your $PATH, is it installed?")
}
cmd := fmt.Sprintf(
"pass rm --force hosts/%s/%s/%s",
server, appName, secretName,
)
if err := exec.Command("bash", "-c", cmd).Run(); err != nil {
return err
}
return nil
}