remove dependencies
This commit is contained in:
parent
b808ce30cb
commit
1656b91e3b
107 changed files with 567 additions and 7772 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
|
|
@ -17,8 +18,6 @@ import (
|
|||
"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"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -49,7 +48,7 @@ func usage() {
|
|||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
usage()
|
||||
usage() // does not return
|
||||
}
|
||||
arg := os.Args[1]
|
||||
switch arg {
|
||||
|
|
@ -62,29 +61,46 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func fatal(msg string, err error) {
|
||||
log.Error(err, msg)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func trimPath(_ []string, a slog.Attr) slog.Attr {
|
||||
if a.Key == slog.SourceKey {
|
||||
s := a.Value.Any().(*slog.Source)
|
||||
s.File = filepath.Base(s.File)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func server() {
|
||||
fs := flag.NewFlagSet("", flag.ExitOnError)
|
||||
klog.InitFlags(fs)
|
||||
fs.StringVar(&listen, "listen", ":7070", "listen ip:port")
|
||||
fs.StringVar(&socket, "socket", "keyctl.sock", "listen unix domain socket")
|
||||
fs.StringVar(&path, "path", "/var/keyctl", "db storage dir")
|
||||
fs.Parse(os.Args[2:])
|
||||
|
||||
log = klogr.New().WithName("main")
|
||||
h := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
|
||||
AddSource: true,
|
||||
ReplaceAttr: trimPath,
|
||||
})
|
||||
l := logr.FromSlogHandler(h)
|
||||
log = l.WithName("main")
|
||||
log.Info("starting keyctl", "version", version)
|
||||
err := godrop.PledgePromises("stdio rpath wpath cpath inet fattr flock unix unveil")
|
||||
if err != nil {
|
||||
klog.Fatalf("init failed: %s", err)
|
||||
fatal("init failed", err)
|
||||
}
|
||||
|
||||
dbstore, err := db.New(klogr.New().WithName("db"), path)
|
||||
dbstore, err := db.New(l.WithName("db"), path)
|
||||
if err != nil {
|
||||
klog.Fatalf("init failed: %s", err)
|
||||
fatal("init failed", err)
|
||||
}
|
||||
|
||||
srv, err := api.NewServer(klogr.New().WithName("srv"), listen, filepath.Join(path, socket), dbstore)
|
||||
srv, err := api.NewServer(l.WithName("srv"), listen, filepath.Join(path, socket), dbstore)
|
||||
if err != nil {
|
||||
klog.Fatalf("init failed: %s", err)
|
||||
fatal("init failed", err)
|
||||
}
|
||||
|
||||
sigs := make(chan os.Signal, 1)
|
||||
|
|
@ -95,9 +111,11 @@ func server() {
|
|||
srv.Shutdown(ctx)
|
||||
cancel()
|
||||
err = dbstore.Close()
|
||||
exit := 0
|
||||
if err != nil {
|
||||
log.Error(err, "error closing db")
|
||||
exit = 1
|
||||
}
|
||||
log.Info("keyctl shutdown completed")
|
||||
os.Exit(0)
|
||||
os.Exit(exit)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue