split into daemon and cli interface

This commit is contained in:
2024-10-07 14:11:49 +02:00
parent 582c90c32a
commit fcdad8c2a3
5 changed files with 539 additions and 265 deletions

View File

@@ -216,6 +216,42 @@ func (n *Namespace) Put(k string, v string) error {
return err
}
func (n *Namespace) Delete(k string) error {
key := ds.NewKey(k)
err := n.Datastore.Delete(n.ctx, key)
if err != nil {
printErr(err)
}
return err
}
func (n *Namespace) GetPassword(k string) (password.Password, error) {
v, err := n.Datastore.Get(n.ctx, ds.NewKey(k))
if err != nil {
printErr(err)
return password.Password{}, err
}
val, err := age.Decrypt(v, n.Key)
if err != nil {
printErr(err)
return password.Password{}, err
}
pw, err := password.GetPasswordFromJson(val)
if err != nil {
printErr(err)
return password.Password{}, err
}
return pw, nil
}
func (n *Namespace) Get(k string) (string, error) {
v, err := n.Datastore.Get(n.ctx, ds.NewKey(k))
if err != nil {
@@ -226,6 +262,27 @@ func (n *Namespace) Get(k string) (string, error) {
return string(v), nil
}
func (n *Namespace) GetAllNames() []string {
q := query.Query{}
results, err := n.Datastore.Query(n.ctx, q)
if err != nil {
printErr(err)
}
var result []string
for r := range results.Next() {
if r.Error != nil {
printErr(err)
continue
}
result = append(result, r.Key)
}
return result
}
func (n *Namespace) List() {
q := query.Query{}
results, err := n.Datastore.Query(n.ctx, q)