first compiling version

This commit is contained in:
ston1th 2023-03-15 01:51:45 +01:00
commit 3d54199faa
27 changed files with 908 additions and 243 deletions

View file

@ -11,7 +11,9 @@ import (
"syscall"
"time"
"git.giftfish.de/ston1th/keyctl/pkg/server"
"git.giftfish.de/ston1th/keyctl/pkg/api"
"git.giftfish.de/ston1th/keyctl/pkg/cli"
"git.giftfish.de/ston1th/keyctl/pkg/db"
"github.com/go-logr/logr"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
@ -35,6 +37,7 @@ func usage() {
keyctl ls - list configured keys
keyctl req - list current key requests
keyctl approve - approve a key request
keyctl reject - reject a key request
keyctl del - delete a key
keyctl help - show this usage
`, version)
@ -45,15 +48,16 @@ func main() {
if len(os.Args) == 0 {
usage()
}
switch os.Args[0] {
case "new", "get", "ls", "req", "approve", "del":
arg := os.Args[0]
switch arg {
case "new", "get", "ls", "req", "approve", "reject", "del":
//flag.StringVar(&config, "config", "/etc/keyctl/url.conf", "path to client config file")
//flag.Parse()
//cli.
cli.Run(arg) // does not return
case "server":
klog.InitFlags(nil)
flag.StringVar(&listen, "listen", ":7070", "listen ip:port")
flag.StringVar(&path, "path", "/var/keyctl/data.db", "data storage db")
flag.StringVar(&path, "path", "/var/keyctl", "db storage dir")
flag.Parse()
default:
usage()
@ -61,15 +65,15 @@ func main() {
log = klogr.New().WithName("main")
log.Info("starting keyctl", "version", version)
srv, err := server.NewServer(klogr.New().WithName("srv"), listen, path)
srv, err := api.NewServer(klogr.New().WithName("srv"), listen)
if err != nil {
klog.Fatalf("init failed: %s", err)
}
err = srv.Start(klogr.New().WithName("db"))
dbstore, err := db.New(klogr.New().WithName("db"), path)
if err != nil {
klog.Fatalf("init failed: %s", err)
}
srv.Start(dbstore)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
@ -78,6 +82,10 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
srv.Shutdown(ctx)
cancel()
err = dbstore.Close()
if err != nil {
log.Error(err, "error closing db")
}
log.Info("keyctl shutdown completed")
os.Exit(0)
}