Compare commits

..

3 Commits

Author SHA1 Message Date
7cb3636328 ppass use new logger 2024-10-10 10:31:44 +02:00
f2e25cb402 rpc use new logger 2024-10-10 10:26:33 +02:00
528faedfb4 crypto use new logger 2024-10-10 10:18:14 +02:00
3 changed files with 44 additions and 42 deletions

View File

@@ -2,13 +2,13 @@ package main
import (
"flag"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/k4lipso/pentapass/rpc"
"github.com/k4lipso/pentapass/crypto"
. "github.com/k4lipso/pentapass/internal/log"
)
var (
@@ -32,7 +32,7 @@ var listCmd = &cobra.Command{
client, err := rpc.Receive(dbPath)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
@@ -41,11 +41,11 @@ var listCmd = &cobra.Command{
err = client.Call("Query.GetAllNames", &namespace, &names)
if err != nil {
fmt.Println(err)
Logger.Error(err)
}
for _, name := range names {
fmt.Println(name)
Logger.Info(name)
}
},
@@ -60,7 +60,7 @@ var generateCmd = &cobra.Command{
client, err := rpc.Receive(dbPath)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
@@ -71,10 +71,10 @@ var generateCmd = &cobra.Command{
err = client.Call("Query.Generate", &np, &password)
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)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
@@ -98,11 +98,11 @@ var showCmd = &cobra.Command{
err = client.Call("Query.Get", &np, &password)
if err != nil {
fmt.Println(err)
Logger.Error(err)
return
}
fmt.Println(password.Password)
Logger.Info(password.Password)
},
}
@@ -120,7 +120,7 @@ var addNamespaceCmd = &cobra.Command{
client, err := rpc.Receive(dbPath)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
@@ -130,11 +130,11 @@ var addNamespaceCmd = &cobra.Command{
err = client.Call("Query.AddNamespace", &namespace, &placeholder)
if err != nil {
fmt.Println(err)
Logger.Error(err)
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)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
@@ -157,11 +157,11 @@ var deleteNamespaceCmd = &cobra.Command{
err = client.Call("Query.DeleteNamespace", &namespace, &placeholder)
if err != nil {
fmt.Println(err)
Logger.Error(err)
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)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
@@ -181,13 +181,13 @@ var listNamespacesCmd = &cobra.Command{
err = client.Call("Query.ListNamespaces", 0, &reply)
if err != nil {
fmt.Println(err)
Logger.Error(err)
return
}
fmt.Printf("Namespaces:\n")
Logger.Info("Namespaces:")
for _, ns := range reply {
fmt.Println(ns)
Logger.Info(ns)
}
},
}
@@ -206,13 +206,13 @@ var infoCmd = &cobra.Command{
client, err := rpc.Receive(dbPath)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
var result *string
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)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
@@ -246,11 +246,11 @@ var addPeerCmd = &cobra.Command{
err = client.Call("Query.AddPeer", &np, &success)
if err != nil {
fmt.Println(err)
Logger.Error(err)
return
}
fmt.Println(*success)
Logger.Info(*success)
},
}
@@ -263,7 +263,7 @@ var removePeerCmd = &cobra.Command{
client, err := rpc.Receive(dbPath)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
@@ -283,11 +283,11 @@ var removePeerCmd = &cobra.Command{
err = client.Call("Query.DeletePeer", &np, &success)
if err != nil {
fmt.Println(err)
Logger.Error(err)
return
}
fmt.Println(*success)
Logger.Info(*success)
},
}
@@ -300,7 +300,7 @@ var deleteCmd = &cobra.Command{
client, err := rpc.Receive(dbPath)
if err != nil {
fmt.Printf("dialing: %s\n", err)
Logger.Errorf("dialing: %s\n", err)
return
}
@@ -320,16 +320,15 @@ var deleteCmd = &cobra.Command{
err = client.Call("Query.Delete", &np, &success)
if err != nil {
fmt.Println(err)
Logger.Error(err)
}
fmt.Println(*success)
Logger.Info(*success)
},
}
func init() {
//listCmd.Flags().BoolP("all", "a", false, "List all items")
rootCmd.PersistentFlags().String("db", "", "db path")
rootCmd.MarkPersistentFlagRequired("db")
@@ -350,8 +349,9 @@ func init() {
}
func main() {
InitLogger(true)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Logger.Error(err)
os.Exit(1)
}
}

View File

@@ -8,6 +8,8 @@ import (
"errors"
"filippo.io/age"
. "github.com/k4lipso/pentapass/internal/log"
)
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)
}
fmt.Printf("Private key saved to %s\n", filename)
Logger.Infof("Private key saved to %s\n", filename)
return identity, nil
}
@@ -53,7 +55,7 @@ func LoadAgeKey(filename string) (*age.X25519Identity, error) {
func LoadOrGenerateKeys(filename string) (*age.X25519Identity, error) {
_, err := os.Open(filename)
if errors.Is(err, os.ErrNotExist) {
fmt.Println("Not Exists - Generate Keys")
Logger.Info("No Key found. Generating Key")
return GenerateAgeKey(filename)
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/k4lipso/pentapass/storage"
"github.com/k4lipso/pentapass/crypto"
"github.com/k4lipso/pentapass/crypto/age"
. "github.com/k4lipso/pentapass/internal/log"
)
var StorageHandler *storage.StorageHandler
@@ -95,7 +96,7 @@ func (t *Query) AddPeer(np *NamespacePeer, success *bool) error {
peer, err := storage.PeerFromString(np.Peer)
if err != nil {
fmt.Printf("Error parsing peer string: %s\n", err)
Logger.Infof("Error parsing peer string: %s\n", err)
*success = false
return err
}
@@ -117,7 +118,7 @@ func (t *Query) DeletePeer(np *NamespacePeer, success *bool) error {
peer, err := storage.PeerFromString(np.Peer)
if err != nil {
fmt.Printf("Error parsing peer string: %s\n", err)
Logger.Infof("Error parsing peer string: %s\n", err)
*success = false
return err
}
@@ -162,8 +163,7 @@ func (t *Query) ListNamespaces(_ *int, reply *[]string) error {
}
func (t *Query) GetAllNames(namespace *string, reply *[]string) error {
fmt.Println("RPC Request: Query::LoadedTriggers")
fmt.Printf("Listing content of %s", *namespace)
Logger.Infof("Listing content of %s", *namespace)
val, ok := StorageHandler.Namespaces[*namespace]
@@ -182,7 +182,7 @@ func Serve(path string) {
l, err := net.Listen("unix", path + "/rpc_test.socket")
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)
@@ -191,7 +191,7 @@ func Serve(path string) {
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
func(ln net.Listener, c chan os.Signal) {
sig := <-c
fmt.Printf("Caught signal %s: shutting down.\n", sig)
Logger.Infof("Caught signal %s: shutting down.\n", sig)
ln.Close()
os.Exit(0)
}(l, sigc)
@@ -201,7 +201,7 @@ func Receive(path string) (*rpc.Client, error) {
client, err := rpc.DialHTTP("unix", path + "/rpc_test.socket")
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