Skip to content

Commit

Permalink
Added OpenCHAMI middleware and updated go deps
Browse files Browse the repository at this point in the history
  • Loading branch information
davidallendj committed Aug 12, 2024
1 parent ffeb72e commit 740ef05
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 30 deletions.
12 changes: 11 additions & 1 deletion cmd/boot-script-service/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ import (
"log"
"net/http"
net_url "net/url"
"os"
"time"

base "github.com/Cray-HPE/hms-base"
"github.com/OpenCHAMI/jwtauth/v5"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/chi/v5"
"github.com/hashicorp/go-retryablehttp"
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"
)

const (
Expand All @@ -63,18 +68,23 @@ var (
)

func initHandlers() *chi.Mux {
// Setup logger
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
logger := zlog.Output(zerolog.ConsoleWriter{Out: os.Stderr})

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.Use(middleware.Timeout(60 * time.Second))
if jwksURL != "" {
router.Group(func(r chi.Router) {
r.Use(
jwtauth.Verifier(tokenAuth),
jwtauth.Authenticator(tokenAuth),
openchami_authenticator.AuthenticatorWithRequiredClaims(tokenAuth, []string{"sub", "iss", "aud"}),
)

// protected routes if using auth
Expand Down
28 changes: 18 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/OpenCHAMI/bss

go 1.20
go 1.21

toolchain go1.21.5

replace google.golang.org/grpc => google.golang.org/grpc v1.29.1

Expand All @@ -10,7 +12,7 @@ require (
github.com/Cray-HPE/hms-s3 v1.9.2
github.com/docker/distribution v2.8.2+incompatible
github.com/evanphx/json-patch v4.9.0+incompatible
github.com/google/uuid v1.3.0
github.com/google/uuid v1.6.0
github.com/jmoiron/sqlx v1.2.0
github.com/lib/pq v1.10.9
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -21,10 +23,13 @@ require (
github.com/OpenCHAMI/jwtauth/v5 v5.0.0-20240321222802-e6cb468a2a18
github.com/OpenCHAMI/smd/v2 v2.12.15
github.com/go-chi/chi v1.5.1
github.com/go-chi/chi/v5 v5.0.11
github.com/go-chi/chi/v5 v5.1.0
github.com/golang-migrate/migrate/v4 v4.16.2
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/lestrrat-go/jwx v1.2.28
github.com/openchami/chi-middleware/auth v0.0.0-20240812202845-ef09f8f5a7d0
github.com/openchami/chi-middleware/log v0.0.0-20240812202845-ef09f8f5a7d0
github.com/rs/zerolog v1.33.0
)

require (
Expand All @@ -33,10 +38,11 @@ require (
github.com/aws/aws-sdk-go v1.34.0 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/coreos/etcd v3.3.13+incompatible // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-chi/jwtauth/v5 v5.3.1 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand All @@ -52,10 +58,12 @@ require (
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/jwx/v2 v2.0.20 // indirect
github.com/lestrrat-go/jwx/v2 v2.1.1 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.13 // 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/pkg/errors v0.9.1 // indirect
Expand All @@ -64,10 +72,10 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
go.etcd.io/etcd v3.3.13+incompatible // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/crypto v0.25.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/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.51.0 // indirect
Expand Down
Loading

0 comments on commit 740ef05

Please sign in to comment.