From 71ba0cd9b988813da1b5c7101f8bf5918df0f795 Mon Sep 17 00:00:00 2001 From: Max Resnick Date: Sat, 24 Aug 2024 17:09:03 -0700 Subject: chore: add env var for log level, fix bug, cleanup push target --- cmd/main.go | 6 +++++- internal/admin/service.go | 1 + internal/authz/middleware.go | 2 ++ justfile | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index c6b9854..96c3e93 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -87,8 +87,12 @@ func main() { } func init() { + logLevel, ok := os.LookupEnv("GO_GIT_SERVER_LOG_LEVEL") + if !ok { + logLevel = "INFO" + } flag.StringVar(&backendCommand, "c", "git http-backend", "CGI binary to execute") - flag.StringVar(&loggingLevel, "e", "INFO", "set log level") + flag.StringVar(&loggingLevel, "e", logLevel, "set log level") flag.StringVar(&addr, "l", ":8080", "Address/port to listen on") flag.StringVar(&modelPath, "m", "./auth_model.ini", "casbin authentication model") flag.StringVar(&policyPath, "p", "./policy.csv", "casbin auth policy") diff --git a/internal/admin/service.go b/internal/admin/service.go index 4f955da..d60a072 100644 --- a/internal/admin/service.go +++ b/internal/admin/service.go @@ -65,6 +65,7 @@ func (s *Servicer) InitServer() error { return fmt.Errorf("cloudn't load policy %w", err) } slog.Info("policy loaded") + slog.Debug("init server", "repoDir", s.reposDir) if err := s.Conf.ConfigureRepos(); err != nil { return fmt.Errorf("couldn't configure repos %w", err) } diff --git a/internal/authz/middleware.go b/internal/authz/middleware.go index 3ba95ad..31f7bf3 100644 --- a/internal/authz/middleware.go +++ b/internal/authz/middleware.go @@ -27,6 +27,7 @@ func Authentication(authMap TokenMap, next http.Handler) http.Handler { u = "anon" ctx := context.WithValue(req.Context(), AuthzUrnKey, u) next.ServeHTTP(rw, req.WithContext(ctx)) + return } urn := fmt.Sprintf("uid:%s", u) hash, ok := authMap[urn] @@ -76,6 +77,7 @@ func Authorization(adminSvc *admin.Servicer, next http.Handler) http.Handler { slog.Info("Not Authorized", "urn", urn, "repo", repo) http.Error(rw, "Access denied", http.StatusForbidden) return + } slog.Debug("Access Attempt", "action", action, "repo", repo) next.ServeHTTP(rw, req.WithContext(ctx)) diff --git a/justfile b/justfile index c673c6a..2c7b066 100644 --- a/justfile +++ b/justfile @@ -76,7 +76,8 @@ build version: test builddir push: new_ver=$(cat {{ NEW_VERSION }}); \ - just docker-push git-push $new_ver + just docker-push $new_ver; \ + just git-push $new_ver @echo "pushed to all endpoints" docker-push tag="latest" registry="public.ecr.aws/s0f9o2k5": -- cgit v1.2.3