WIP implement pass functs

This commit is contained in:
2024-08-14 19:43:39 +02:00
parent 6502bb1e12
commit 582c90c32a
2 changed files with 65 additions and 15 deletions

View File

@@ -33,6 +33,7 @@ import (
logging "github.com/ipfs/go-log/v2"
agelib "filippo.io/age"
password "github.com/k4lipso/pentapass/crypto"
"github.com/k4lipso/pentapass/crypto/age"
)
@@ -250,6 +251,42 @@ func (n *Namespace) List() {
}
}
func (n *Namespace) GetAllPasswords() ([]password.Password, error) {
q := query.Query{}
results, err := n.Datastore.Query(n.ctx, q)
if err != nil {
return nil, fmt.Errorf("Error during GetAllPasswords: %s", err)
}
var result []password.Password
for r := range results.Next() {
if r.Error != nil {
printErr(err)
continue
}
val, err := age.Decrypt(r.Value, n.Key)
if err != nil {
printErr(err)
continue
}
pw, err := password.GetPasswordFromJson(val)
if err != nil {
printErr(err)
continue
}
result = append(result, pw)
}
return result, nil
}
func (n *Namespace) Close() {
n.Datastore.Close()
n.CancelFunc()
@@ -263,6 +300,26 @@ type StorageHandler struct {
PubSub *pubsub.PubSub
Key *agelib.X25519Identity
Config []NamespaceConfig
Namespaces map[string]*Namespace
}
func (s *StorageHandler) GetDefaultNamespace(Name string) *Namespace {
return s.Namespaces["root"]
}
func (s *StorageHandler) InitNamespaces() {
NamespaceMap := make(map[string]*Namespace)
for _, nsCfg := range s.Config {
ns1, err := CreateNamespace(nsCfg.Id, *s)
if err != nil {
logger.Fatal(err)
}
NamespaceMap[nsCfg.Name] = ns1
}
s.Namespaces = NamespaceMap
}
func IsTrustedPeer(ctx context.Context, id peer.ID, namespace string, config []NamespaceConfig) bool {
@@ -431,7 +488,6 @@ func DiscoverPeers(ctx context.Context, h host.Host, dht *dht.IpfsDHT) {
func printErr(err error) {
fmt.Println("error:", err)
fmt.Println("> ")
}
func ConnectedPeers(h host.Host) []*peer.AddrInfo {