forked from toolshed/abra
.gitea
cli
cmd
pkg
app
autocomplete
catalogue
client
compose
config
container
context
dns
envfile
formatter
git
integration
jsontable
limit
lint
log
recipe
secret
testdir
pass.go
secret.go
secret_test.go
server
service
ssh
test
upstream
web
scripts
tests
.dockerignore
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package secret
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// 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("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,
|
|
)
|
|
|
|
logrus.Debugf("attempting to run %s", cmd)
|
|
|
|
if err := exec.Command("bash", "-c", cmd).Run(); err != nil {
|
|
return err
|
|
}
|
|
|
|
logrus.Infof("%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("pass command not found on $PATH, is it installed?")
|
|
}
|
|
|
|
cmd := fmt.Sprintf(
|
|
"pass rm --force hosts/%s/%s/%s",
|
|
server, appName, secretName,
|
|
)
|
|
|
|
logrus.Debugf("attempting to run %s", cmd)
|
|
|
|
if err := exec.Command("bash", "-c", cmd).Run(); err != nil {
|
|
return err
|
|
}
|
|
|
|
logrus.Infof("%s removed from pass store", secretName)
|
|
|
|
return nil
|
|
}
|