diff --git a/cmd/ugitd/args.go b/cmd/ugitd/args.go index 32f682cb7eea8595baac966014d69e5b9c36863d..a1a0e46ffecc4167880a9d9a77c26d8338d56d4f 100644 --- a/cmd/ugitd/args.go +++ b/cmd/ugitd/args.go @@ -5,18 +5,17 @@ "flag" "fmt" "strings" - "github.com/charmbracelet/log" "github.com/peterbourgon/ff/v3" "github.com/peterbourgon/ff/v3/ffyaml" ) type cliArgs struct { + Debug bool RepoDir string SSH sshArgs HTTP httpArgs Meta metaArgs Profile profileArgs - Log logArgs } type sshArgs struct { @@ -47,11 +46,6 @@ Name string URL string } -type logArgs struct { - Level log.Level - JSON bool -} - func parseArgs(args []string) (c cliArgs, e error) { fs := flag.NewFlagSet("ugitd", flag.ContinueOnError) fs.String("config", "ugit.yaml", "Path to config file") @@ -71,21 +65,10 @@ }, Meta: metaArgs{ Title: "ugit", Description: "Minimal git server", - }, - Log: logArgs{ - Level: log.InfoLevel, }, } - fs.Func("log.level", "Logging level", func(s string) error { - lvl, err := log.ParseLevel(s) - if err != nil { - return err - } - c.Log.Level = lvl - return nil - }) - fs.BoolVar(&c.Log.JSON, "log.json", c.Log.JSON, "Print logs in JSON(L) format") + fs.BoolVar(&c.Debug, "debug", c.Debug, "Debug logging") fs.StringVar(&c.RepoDir, "repo-dir", c.RepoDir, "Path to directory containing repositories") fs.StringVar(&c.SSH.AuthorizedKeys, "ssh.authorized-keys", c.SSH.AuthorizedKeys, "Path to authorized_keys") fs.StringVar(&c.SSH.CloneURL, "ssh.clone-url", c.SSH.CloneURL, "SSH clone URL base") diff --git a/cmd/ugitd/main.go b/cmd/ugitd/main.go index a46daf2b43116b59954cd699e9284ba8f1905634..e7fab794e4e55915ced861e8b15647ca0bcf36e5 100644 --- a/cmd/ugitd/main.go +++ b/cmd/ugitd/main.go @@ -4,21 +4,21 @@ import ( "errors" "flag" "fmt" - "log/slog" "os" "os/signal" "path/filepath" "strconv" "strings" - "github.com/charmbracelet/log" - "github.com/go-chi/chi/v5/middleware" - "github.com/go-chi/httplog/v2" "github.com/go-git/go-git/v5/plumbing/protocol/packp" - "github.com/go-git/go-git/v5/utils/trace" "go.jolheiser.com/ugit/internal/git" + "go.jolheiser.com/ugit/internal/http" "go.jolheiser.com/ugit/internal/ssh" + + "github.com/charmbracelet/log" + "github.com/go-chi/chi/v5/middleware" + "github.com/go-git/go-git/v5/utils/trace" ) func main() { @@ -39,24 +39,14 @@ if err != nil { panic(err) } - log.SetLevel(args.Log.Level) - middleware.DefaultLogger = httplog.RequestLogger(httplog.NewLogger("ugit", httplog.Options{ - JSON: args.Log.JSON, - LogLevel: slog.Level(args.Log.Level), - Concise: args.Log.Level != log.DebugLevel, - })) - - if args.Log.Level == log.DebugLevel { + if args.Debug { trace.SetTarget(trace.Packet) + log.SetLevel(log.DebugLevel) } else { middleware.DefaultLogger = http.NoopLogger ssh.DefaultLogger = ssh.NoopLogger } - if args.Log.JSON { - log.SetFormatter(log.JSONFormatter) - } - if err := requiredFS(args.RepoDir); err != nil { panic(err) } @@ -73,7 +63,7 @@ if err != nil { panic(err) } go func() { - log.Debugf("SSH listening on ssh://localhost:%d\n", sshSettings.Port) + fmt.Printf("SSH listening on ssh://localhost:%d\n", sshSettings.Port) if err := sshSrv.ListenAndServe(); err != nil { panic(err) } @@ -98,7 +88,7 @@ }) } httpSrv := http.New(httpSettings) go func() { - log.Debugf("HTTP listening on http://localhost:%d\n", httpSettings.Port) + fmt.Printf("HTTP listening on http://localhost:%d\n", httpSettings.Port) if err := httpSrv.ListenAndServe(); err != nil { panic(err) } diff --git a/flake.nix b/flake.nix index bf67a0f284186c24abc2176f46d84a9553f74779..e93f15e7047370e1fb817580d6f8c52f4ebba421 100644 --- a/flake.nix +++ b/flake.nix @@ -128,6 +128,11 @@ default = "ugit"; description = "Group account under which ugit runs"; }; + debug = mkOption { + type = types.bool; + default = false; + }; + openFirewall = mkOption { type = types.bool; default = false; @@ -155,7 +160,7 @@ authorizedKeysPath = if (builtins.length cfg.authorizedKeys) > 0 then authorizedKeysFile else cfg.authorizedKeysFile; - args = ["--config=${configFile}" "--repo-dir=${cfg.repoDir}" "--ssh.authorized-keys=${authorizedKeysPath}" "--ssh.host-key=${cfg.hostKeyFile}"]; + args = ["--config=${configFile}" "--repo-dir=${cfg.repoDir}" "--ssh.authorized-keys=${authorizedKeysPath}" "--ssh.host-key=${cfg.hostKeyFile}"] ++ lib.optionals cfg.debug ["--debug"]; in "${cfg.package}/bin/ugitd ${builtins.concatStringsSep " " args}"; wantedBy = ["multi-user.target"]; after = ["network.target"]; diff --git a/go.mod b/go.mod index 2d22bd7def304664216b9226fcf95620ee3a6e3d..20c78ab22603fea524ea9c10b31ed9b14c723493 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ github.com/charmbracelet/ssh v0.0.0-20240201134204-3f297de25560 github.com/charmbracelet/wish v1.3.0 github.com/dustin/go-humanize v1.0.1 github.com/go-chi/chi/v5 v5.0.11 - github.com/go-chi/httplog/v2 v2.1.1 github.com/go-git/go-billy/v5 v5.5.0 github.com/go-git/go-git/v5 v5.11.0 github.com/peterbourgon/ff/v3 v3.4.0 diff --git a/go.sum b/go.sum index 511fb70ed83802d0d2361d3ecdbba3030aef4b2d..82a129f69bbf9c217f1a5d7f38c11254a4411958 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,6 @@ github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4= github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA= github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= -github.com/go-chi/httplog/v2 v2.1.1 h1:ojojiu4PIaoeJ/qAO4GWUxJqvYUTobeo7zmuHQJAxRk= -github.com/go-chi/httplog/v2 v2.1.1/go.mod h1:/XXdxicJsp4BA5fapgIC3VuTD+z0Z/VzukoB3VDc1YE= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=