zrok/zrokdir/identity.go

37 lines
920 B
Go
Raw Normal View History

2023-01-09 17:08:22 +01:00
package zrokdir
import (
"github.com/pkg/errors"
"os"
"path/filepath"
)
func ZitiIdentityFile(name string) (string, error) {
2023-01-09 20:16:08 +01:00
return identityFile(name)
2023-01-09 17:08:22 +01:00
}
func SaveZitiIdentity(name, data string) error {
zif, err := ZitiIdentityFile(name)
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Dir(zif), os.FileMode(0700)); err != nil {
return errors.Wrapf(err, "error creating zrokdir path '%v'", filepath.Dir(zif))
}
if err := os.WriteFile(zif, []byte(data), os.FileMode(0600)); err != nil {
return errors.Wrapf(err, "error writing ziti identity file '%v'", zif)
}
return nil
}
func DeleteZitiIdentity(name string) error {
zif, err := ZitiIdentityFile(name)
if err != nil {
return errors.Wrapf(err, "error getting ziti identity file path for '%v'", name)
}
if err := os.Remove(zif); err != nil {
return errors.Wrapf(err, "error removing ziti identity file '%v'", zif)
}
return nil
}