Files
abra/pkg/secret/pass.go
decentral1se a31ec51c24
Some checks failed
continuous-integration/drone/push Build is failing
WIP: feat: translation support
See #483
2025-08-20 13:39:45 +02:00

55 lines
1.3 KiB
Go

package secret
import (
"errors"
"fmt"
"os/exec"
"coopcloud.tech/abra/pkg/log"
"github.com/leonelquinteros/gotext"
)
// PassInsertSecret inserts a secret into a pass store.
func PassInsertSecret(secretValue, secretName, appName, server string) error {
if _, err := exec.LookPath("pass"); err != nil {
return errors.New(gotext.Get("pass command not found on $PATH, is it installed?"))
}
cmd := fmt.Sprintf(
"echo %s | pass insert hosts/%s/%s/%s -m",
secretValue, server, appName, secretName,
)
log.Debug(gotext.Get("attempting to run %s", cmd))
if err := exec.Command("bash", "-c", cmd).Run(); err != nil {
return err
}
log.Infof(gotext.Get("%s inserted into pass store", secretName))
return nil
}
// PassRmSecret deletes a secret from a pass store.
func PassRmSecret(secretName, appName, server string) error {
if _, err := exec.LookPath("pass"); err != nil {
return errors.New(gotext.Get("pass command not found on $PATH, is it installed?"))
}
cmd := fmt.Sprintf(
"pass rm --force hosts/%s/%s/%s",
server, appName, secretName,
)
log.Debug(gotext.Get("attempting to run %s", cmd))
if err := exec.Command("bash", "-c", cmd).Run(); err != nil {
return err
}
log.Infof(gotext.Get("%s removed from pass store", secretName))
return nil
}