Compare commits
3 Commits
0419af16b0
...
7cb3636328
| Author | SHA1 | Date | |
|---|---|---|---|
| 7cb3636328 | |||
| f2e25cb402 | |||
| 528faedfb4 |
@@ -2,13 +2,13 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/k4lipso/pentapass/rpc"
|
"github.com/k4lipso/pentapass/rpc"
|
||||||
"github.com/k4lipso/pentapass/crypto"
|
"github.com/k4lipso/pentapass/crypto"
|
||||||
|
. "github.com/k4lipso/pentapass/internal/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -32,7 +32,7 @@ var listCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,11 +41,11 @@ var listCmd = &cobra.Command{
|
|||||||
err = client.Call("Query.GetAllNames", &namespace, &names)
|
err = client.Call("Query.GetAllNames", &namespace, &names)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
fmt.Println(name)
|
Logger.Info(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -60,7 +60,7 @@ var generateCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,10 +71,10 @@ var generateCmd = &cobra.Command{
|
|||||||
err = client.Call("Query.Generate", &np, &password)
|
err = client.Call("Query.Generate", &np, &password)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(*password)
|
Logger.Info(*password)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ var showCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,11 +98,11 @@ var showCmd = &cobra.Command{
|
|||||||
err = client.Call("Query.Get", &np, &password)
|
err = client.Call("Query.Get", &np, &password)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(password.Password)
|
Logger.Info(password.Password)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ var addNamespaceCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,11 +130,11 @@ var addNamespaceCmd = &cobra.Command{
|
|||||||
err = client.Call("Query.AddNamespace", &namespace, &placeholder)
|
err = client.Call("Query.AddNamespace", &namespace, &placeholder)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Namespace %s was added\n", namespace)
|
Logger.Infof("Namespace %s was added\n", namespace)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ var deleteNamespaceCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,11 +157,11 @@ var deleteNamespaceCmd = &cobra.Command{
|
|||||||
err = client.Call("Query.DeleteNamespace", &namespace, &placeholder)
|
err = client.Call("Query.DeleteNamespace", &namespace, &placeholder)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Namespace %s was deleted\n", namespace)
|
Logger.Infof("Namespace %s was deleted\n", namespace)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ var listNamespacesCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,13 +181,13 @@ var listNamespacesCmd = &cobra.Command{
|
|||||||
err = client.Call("Query.ListNamespaces", 0, &reply)
|
err = client.Call("Query.ListNamespaces", 0, &reply)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Namespaces:\n")
|
Logger.Info("Namespaces:")
|
||||||
for _, ns := range reply {
|
for _, ns := range reply {
|
||||||
fmt.Println(ns)
|
Logger.Info(ns)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -206,13 +206,13 @@ var infoCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var result *string
|
var result *string
|
||||||
err = client.Call("Query.GetPeerString", 0, &result)
|
err = client.Call("Query.GetPeerString", 0, &result)
|
||||||
fmt.Println(*result)
|
Logger.Info(*result)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ var addPeerCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,11 +246,11 @@ var addPeerCmd = &cobra.Command{
|
|||||||
err = client.Call("Query.AddPeer", &np, &success)
|
err = client.Call("Query.AddPeer", &np, &success)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(*success)
|
Logger.Info(*success)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ var removePeerCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,11 +283,11 @@ var removePeerCmd = &cobra.Command{
|
|||||||
err = client.Call("Query.DeletePeer", &np, &success)
|
err = client.Call("Query.DeletePeer", &np, &success)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(*success)
|
Logger.Info(*success)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +300,7 @@ var deleteCmd = &cobra.Command{
|
|||||||
client, err := rpc.Receive(dbPath)
|
client, err := rpc.Receive(dbPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("dialing: %s\n", err)
|
Logger.Errorf("dialing: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,16 +320,15 @@ var deleteCmd = &cobra.Command{
|
|||||||
err = client.Call("Query.Delete", &np, &success)
|
err = client.Call("Query.Delete", &np, &success)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(*success)
|
Logger.Info(*success)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//listCmd.Flags().BoolP("all", "a", false, "List all items")
|
|
||||||
rootCmd.PersistentFlags().String("db", "", "db path")
|
rootCmd.PersistentFlags().String("db", "", "db path")
|
||||||
rootCmd.MarkPersistentFlagRequired("db")
|
rootCmd.MarkPersistentFlagRequired("db")
|
||||||
|
|
||||||
@@ -350,8 +349,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
InitLogger(true)
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
fmt.Println(err)
|
Logger.Error(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"filippo.io/age"
|
"filippo.io/age"
|
||||||
|
|
||||||
|
. "github.com/k4lipso/pentapass/internal/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -30,7 +32,7 @@ func GenerateAgeKey(filename string) (*age.X25519Identity, error) {
|
|||||||
return nil, fmt.Errorf("failed to save private key to file: %w", err)
|
return nil, fmt.Errorf("failed to save private key to file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Private key saved to %s\n", filename)
|
Logger.Infof("Private key saved to %s\n", filename)
|
||||||
return identity, nil
|
return identity, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +55,7 @@ func LoadAgeKey(filename string) (*age.X25519Identity, error) {
|
|||||||
func LoadOrGenerateKeys(filename string) (*age.X25519Identity, error) {
|
func LoadOrGenerateKeys(filename string) (*age.X25519Identity, error) {
|
||||||
_, err := os.Open(filename)
|
_, err := os.Open(filename)
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
fmt.Println("Not Exists - Generate Keys")
|
Logger.Info("No Key found. Generating Key")
|
||||||
return GenerateAgeKey(filename)
|
return GenerateAgeKey(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
rpc/rpc.go
14
rpc/rpc.go
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/k4lipso/pentapass/storage"
|
"github.com/k4lipso/pentapass/storage"
|
||||||
"github.com/k4lipso/pentapass/crypto"
|
"github.com/k4lipso/pentapass/crypto"
|
||||||
"github.com/k4lipso/pentapass/crypto/age"
|
"github.com/k4lipso/pentapass/crypto/age"
|
||||||
|
. "github.com/k4lipso/pentapass/internal/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var StorageHandler *storage.StorageHandler
|
var StorageHandler *storage.StorageHandler
|
||||||
@@ -95,7 +96,7 @@ func (t *Query) AddPeer(np *NamespacePeer, success *bool) error {
|
|||||||
peer, err := storage.PeerFromString(np.Peer)
|
peer, err := storage.PeerFromString(np.Peer)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error parsing peer string: %s\n", err)
|
Logger.Infof("Error parsing peer string: %s\n", err)
|
||||||
*success = false
|
*success = false
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -117,7 +118,7 @@ func (t *Query) DeletePeer(np *NamespacePeer, success *bool) error {
|
|||||||
peer, err := storage.PeerFromString(np.Peer)
|
peer, err := storage.PeerFromString(np.Peer)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error parsing peer string: %s\n", err)
|
Logger.Infof("Error parsing peer string: %s\n", err)
|
||||||
*success = false
|
*success = false
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -162,8 +163,7 @@ func (t *Query) ListNamespaces(_ *int, reply *[]string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Query) GetAllNames(namespace *string, reply *[]string) error {
|
func (t *Query) GetAllNames(namespace *string, reply *[]string) error {
|
||||||
fmt.Println("RPC Request: Query::LoadedTriggers")
|
Logger.Infof("Listing content of %s", *namespace)
|
||||||
fmt.Printf("Listing content of %s", *namespace)
|
|
||||||
|
|
||||||
val, ok := StorageHandler.Namespaces[*namespace]
|
val, ok := StorageHandler.Namespaces[*namespace]
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ func Serve(path string) {
|
|||||||
l, err := net.Listen("unix", path + "/rpc_test.socket")
|
l, err := net.Listen("unix", path + "/rpc_test.socket")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error while listening on unix socket: %s\n", err)
|
Logger.Errorf("Error while listening on unix socket: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go http.Serve(l, nil)
|
go http.Serve(l, nil)
|
||||||
@@ -191,7 +191,7 @@ func Serve(path string) {
|
|||||||
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
|
||||||
func(ln net.Listener, c chan os.Signal) {
|
func(ln net.Listener, c chan os.Signal) {
|
||||||
sig := <-c
|
sig := <-c
|
||||||
fmt.Printf("Caught signal %s: shutting down.\n", sig)
|
Logger.Infof("Caught signal %s: shutting down.\n", sig)
|
||||||
ln.Close()
|
ln.Close()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}(l, sigc)
|
}(l, sigc)
|
||||||
@@ -201,7 +201,7 @@ func Receive(path string) (*rpc.Client, error) {
|
|||||||
client, err := rpc.DialHTTP("unix", path + "/rpc_test.socket")
|
client, err := rpc.DialHTTP("unix", path + "/rpc_test.socket")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Cant connect to RPC server: %s\n", err)
|
Logger.Errorf("Cant connect to RPC server: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return client, err
|
return client, err
|
||||||
|
|||||||
Reference in New Issue
Block a user