WIP implement pass functs
This commit is contained in:
@@ -100,16 +100,10 @@ func main() {
|
|||||||
Config: Cfg,
|
Config: Cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
Namespaces := make(map[string]*storage.Namespace)
|
storageHandler.InitNamespaces()
|
||||||
for _, nsCfg := range Cfg {
|
|
||||||
ns1, err := storage.CreateNamespace(nsCfg.Id, storageHandler)
|
|
||||||
|
|
||||||
if err != nil {
|
for _, val := range storageHandler.Namespaces {
|
||||||
logger.Fatal(err)
|
defer val.Close()
|
||||||
}
|
|
||||||
|
|
||||||
Namespaces[nsCfg.Name] = ns1
|
|
||||||
defer ns1.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf(`
|
fmt.Printf(`
|
||||||
@@ -191,7 +185,7 @@ Commands:
|
|||||||
case "list":
|
case "list":
|
||||||
if len(fields) < 2 {
|
if len(fields) < 2 {
|
||||||
fmt.Printf("Available Namespaces:\n")
|
fmt.Printf("Available Namespaces:\n")
|
||||||
for k := range Namespaces {
|
for k := range storageHandler.Namespaces {
|
||||||
fmt.Printf("%s\n", k)
|
fmt.Printf("%s\n", k)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@@ -201,7 +195,7 @@ Commands:
|
|||||||
|
|
||||||
fmt.Printf("Listing content of %s", namespace)
|
fmt.Printf("Listing content of %s", namespace)
|
||||||
|
|
||||||
val, ok := Namespaces[namespace]
|
val, ok := storageHandler.Namespaces[namespace]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Println("Namespace does not exist")
|
fmt.Println("Namespace does not exist")
|
||||||
@@ -218,7 +212,7 @@ Commands:
|
|||||||
|
|
||||||
namespace := fields[1]
|
namespace := fields[1]
|
||||||
|
|
||||||
val, ok := Namespaces[namespace]
|
val, ok := storageHandler.Namespaces[namespace]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Println("Namespace does not exist")
|
fmt.Println("Namespace does not exist")
|
||||||
@@ -242,7 +236,7 @@ Commands:
|
|||||||
|
|
||||||
namespace := fields[1]
|
namespace := fields[1]
|
||||||
|
|
||||||
val, ok := Namespaces[namespace]
|
val, ok := storageHandler.Namespaces[namespace]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Println("Namespace does not exist")
|
fmt.Println("Namespace does not exist")
|
||||||
@@ -279,7 +273,7 @@ Commands:
|
|||||||
|
|
||||||
namespace := fields[1]
|
namespace := fields[1]
|
||||||
|
|
||||||
val, ok := Namespaces[namespace]
|
val, ok := storageHandler.Namespaces[namespace]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Println("Namespace does not exist")
|
fmt.Println("Namespace does not exist")
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import (
|
|||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
|
|
||||||
agelib "filippo.io/age"
|
agelib "filippo.io/age"
|
||||||
|
password "github.com/k4lipso/pentapass/crypto"
|
||||||
"github.com/k4lipso/pentapass/crypto/age"
|
"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() {
|
func (n *Namespace) Close() {
|
||||||
n.Datastore.Close()
|
n.Datastore.Close()
|
||||||
n.CancelFunc()
|
n.CancelFunc()
|
||||||
@@ -263,6 +300,26 @@ type StorageHandler struct {
|
|||||||
PubSub *pubsub.PubSub
|
PubSub *pubsub.PubSub
|
||||||
Key *agelib.X25519Identity
|
Key *agelib.X25519Identity
|
||||||
Config []NamespaceConfig
|
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 {
|
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) {
|
func printErr(err error) {
|
||||||
fmt.Println("error:", err)
|
fmt.Println("error:", err)
|
||||||
fmt.Println("> ")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConnectedPeers(h host.Host) []*peer.AddrInfo {
|
func ConnectedPeers(h host.Host) []*peer.AddrInfo {
|
||||||
|
|||||||
Reference in New Issue
Block a user