Skip to content

Commit

Permalink
Add HTTP logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hlubek committed Mar 21, 2023
1 parent 857bb39 commit 430100c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/lestrrat-go/jwx/v2 v2.0.4
github.com/mattn/go-isatty v0.0.14
github.com/networkteam/apexlogutils v0.2.0
github.com/open-policy-agent/opa v0.50.1
github.com/stretchr/testify v1.8.2
github.com/urfave/cli/v2 v2.11.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zk
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
github.com/mmcloughlin/avo v0.5.0/go.mod h1:ChHFdoV7ql95Wi7vuq2YT1bwCJqiWdZrQ1im3VujLYM=
github.com/networkteam/apexlogutils v0.2.0 h1:HHnB+GR6anJn2T0822Ac5pAY8mVL+exG+RFx+5/jy08=
github.com/networkteam/apexlogutils v0.2.0/go.mod h1:4YBjzjVa4hiL3yhEUStU3t33Cxer+57r4NHwNxuYgdk=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
Expand Down
20 changes: 18 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/transport"
gitHttp "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/networkteam/apexlogutils/httplog"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand All @@ -41,9 +42,20 @@ func NewHandler(
}

r := chi.NewRouter()
r.Use(AuthenticateRequest(authenticationProvider))

r.Post("/patch/{repo}", h.patch)
r.Use(
httpLogger,
)

r.Group(func(r chi.Router) {
r.Use(AuthenticateRequest(authenticationProvider))

r.Post("/patch/{repo}", h.patch)
})

r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})

h.mux = r

Expand Down Expand Up @@ -348,3 +360,7 @@ func convertMixedJsonValueToRNode(value any) (*yaml.RNode, error) {
}
return node, nil
}

func httpLogger(h http.Handler) http.Handler {
return httplog.New(h, httplog.ExcludePathPrefix("/healthz"))
}

0 comments on commit 430100c

Please sign in to comment.