Skip to content

Commit

Permalink
Merge pull request #29 from OpenCHAMI/update-routers
Browse files Browse the repository at this point in the history
Added OpenCHAMI middleware to router.NewRouter()
  • Loading branch information
davidallendj authored Aug 12, 2024
2 parents cdac4f1 + 49ddbed commit 3fd1090
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 99 deletions.
2 changes: 1 addition & 1 deletion cmd/smd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ import (
"github.com/Cray-HPE/hms-certs/pkg/hms_certs"
compcreds "github.com/Cray-HPE/hms-compcredentials"
sstorage "github.com/Cray-HPE/hms-securestorage"
jwtauth "github.com/OpenCHAMI/jwtauth/v5"
"github.com/OpenCHAMI/smd/v2/internal/hbtdapi"
"github.com/OpenCHAMI/smd/v2/internal/hmsds"
"github.com/OpenCHAMI/smd/v2/internal/pgmigrate"
"github.com/OpenCHAMI/smd/v2/internal/slsapi"
"github.com/OpenCHAMI/smd/v2/pkg/rf"
"github.com/OpenCHAMI/smd/v2/pkg/sm"
"github.com/go-chi/chi/v5"
jwtauth "github.com/OpenCHAMI/jwtauth/v5"
"github.com/hashicorp/go-retryablehttp"
"github.com/sirupsen/logrus"
)
Expand Down
11 changes: 10 additions & 1 deletion cmd/smd/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/gorilla/handlers"
openchami_authenticator "github.com/openchami/chi-middleware/auth"
openchami_logger "github.com/openchami/chi-middleware/log"
"github.com/rs/zerolog"
zlog "github.com/rs/zerolog/log"
)

type Route struct {
Expand All @@ -44,13 +48,18 @@ type Route struct {
type Routes []Route

func (s *SmD) NewRouter(publicRoutes []Route, protectedRoutes []Route) *chi.Mux {
// Setup logger
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
logger := zlog.Output(zerolog.ConsoleWriter{Out: os.Stderr})

// create router and use recommended middleware
router := chi.NewRouter()
router.Use(middleware.RequestID)
router.Use(middleware.RealIP)
router.Use(middleware.Logger)
router.Use(middleware.Recoverer)
router.Use(middleware.StripSlashes)
router.Use(openchami_logger.OpenCHAMILogger(logger))
router.NotFound(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
s.Logger(http.NotFoundHandler(), "NotFoundHandler")
}))
Expand All @@ -60,7 +69,7 @@ func (s *SmD) NewRouter(publicRoutes []Route, protectedRoutes []Route) *chi.Mux
router.Group(func(r chi.Router) {
r.Use(
jwtauth.Verifier(s.tokenAuth),
jwtauth.Authenticator(s.tokenAuth),
openchami_authenticator.AuthenticatorWithRequiredClaims(s.tokenAuth, []string{"sub", "iss", "aud"}),
)

// Register protected routes
Expand Down
51 changes: 28 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,66 @@ require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/Masterminds/squirrel v1.5.4
github.com/OpenCHAMI/jwtauth/v5 v5.0.0-20240321222802-e6cb468a2a18
github.com/go-chi/chi/v5 v5.0.11
github.com/golang-migrate/migrate/v4 v4.16.2
github.com/google/uuid v1.3.0
github.com/go-chi/chi/v5 v5.1.0
github.com/golang-migrate/migrate/v4 v4.17.1
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/lestrrat-go/jwx/v2 v2.0.20
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/lestrrat-go/jwx v1.2.30
github.com/lestrrat-go/jwx/v2 v2.1.1
github.com/lib/pq v1.10.9
github.com/openchami/chi-middleware/auth v0.0.0-20240812224658-b16b83c70700
github.com/openchami/chi-middleware/log v0.0.0-20240812224658-b16b83c70700
github.com/rs/zerolog v1.33.0
github.com/sirupsen/logrus v1.9.3
)

require (
github.com/confluentinc/confluent-kafka-go v1.7.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-chi/jwtauth/v5 v5.3.1 // indirect
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.4 // indirect
github.com/lestrrat-go/httprc v1.0.6 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/segmentio/asm v1.2.0 // indirect
)

require (
github.com/Cray-HPE/hms-msgbus v1.11.0
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/docker v23.0.4+incompatible // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-test/deep v1.1.0 // indirect
github.com/gorilla/handlers v1.5.1
github.com/gorilla/handlers v1.5.2
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.4.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.6 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/hashicorp/vault/api v1.9.2 // indirect
github.com/hashicorp/vault/api v1.14.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.6.0 // indirect
)
Loading

0 comments on commit 3fd1090

Please sign in to comment.