From 0bbcc35d7aae5c51802c1a9736338fcb29afc0ce Mon Sep 17 00:00:00 2001 From: zepatrik Date: Fri, 11 Aug 2023 12:03:36 +0200 Subject: [PATCH] minor fixes --- cmd/server/handler.go | 27 +++++++++++++-------------- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cmd/server/handler.go b/cmd/server/handler.go index ebfa68a9150..f85ef95426e 100644 --- a/cmd/server/handler.go +++ b/cmd/server/handler.go @@ -49,7 +49,7 @@ import ( var _ = &consent.Handler{} -func EnhanceMiddleware(ctx context.Context, sl *servicelocatorx.Options, d driver.Registry, n *negroni.Negroni, address string, router *httprouter.Router, enableCORS bool, iface config.ServeInterface) http.Handler { +func EnhanceMiddleware(ctx context.Context, sl *servicelocatorx.Options, d driver.Registry, n *negroni.Negroni, address string, router *httprouter.Router, iface config.ServeInterface) http.Handler { if !networkx.AddressIsUnixSocket(address) { n.UseFunc(x.RejectInsecureRequests(d, d.Config().TLS(ctx, iface))) } @@ -63,7 +63,7 @@ func EnhanceMiddleware(ctx context.Context, sl *servicelocatorx.Options, d drive return n } -func isDSNAllowed(ctx context.Context, r driver.Registry) { +func ensureNoMemoryDSN(r driver.Registry) { if r.Config().DSN() == "memory" { r.Logger().Fatalf(`When using "hydra serve admin" or "hydra serve public" the DSN can not be set to "memory".`) } @@ -74,11 +74,11 @@ func RunServeAdmin(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModifi ctx := cmd.Context() sl := servicelocatorx.NewOptions(slOpts...) - d, err := driver.New(cmd.Context(), sl, append(dOpts, driver.WithOptions(configx.WithFlags(cmd.Flags())))) + d, err := driver.New(cmd.Context(), sl, append(dOpts, driver.WithOptions(append(cOpts, configx.WithFlags(cmd.Flags()))...))) if err != nil { return err } - isDSNAllowed(ctx, d) + ensureNoMemoryDSN(d) admin, _, adminmw, _ := setup(ctx, d, cmd) d.PrometheusManager().RegisterRouter(admin.Router) @@ -92,7 +92,7 @@ func RunServeAdmin(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModifi cmd, &wg, config.AdminInterface, - EnhanceMiddleware(ctx, sl, d, adminmw, d.Config().ListenOn(config.AdminInterface), admin.Router, true, config.AdminInterface), + EnhanceMiddleware(ctx, sl, d, adminmw, d.Config().ListenOn(config.AdminInterface), admin.Router, config.AdminInterface), d.Config().ListenOn(config.AdminInterface), d.Config().SocketPermission(config.AdminInterface), ) @@ -107,11 +107,11 @@ func RunServePublic(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModif ctx := cmd.Context() sl := servicelocatorx.NewOptions(slOpts...) - d, err := driver.New(cmd.Context(), sl, append(dOpts, driver.WithOptions(configx.WithFlags(cmd.Flags())))) + d, err := driver.New(cmd.Context(), sl, append(dOpts, driver.WithOptions(append(cOpts, configx.WithFlags(cmd.Flags()))...))) if err != nil { return err } - isDSNAllowed(ctx, d) + ensureNoMemoryDSN(d) _, public, _, publicmw := setup(ctx, d, cmd) d.PrometheusManager().RegisterRouter(public.Router) @@ -125,7 +125,7 @@ func RunServePublic(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModif cmd, &wg, config.PublicInterface, - EnhanceMiddleware(ctx, sl, d, publicmw, d.Config().ListenOn(config.PublicInterface), public.Router, false, config.PublicInterface), + EnhanceMiddleware(ctx, sl, d, publicmw, d.Config().ListenOn(config.PublicInterface), public.Router, config.PublicInterface), d.Config().ListenOn(config.PublicInterface), d.Config().SocketPermission(config.PublicInterface), ) @@ -140,7 +140,7 @@ func RunServeAll(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModifier ctx := cmd.Context() sl := servicelocatorx.NewOptions(slOpts...) - d, err := driver.New(cmd.Context(), sl, append(dOpts, driver.WithOptions(configx.WithFlags(cmd.Flags())))) + d, err := driver.New(cmd.Context(), sl, append(dOpts, driver.WithOptions(append(cOpts, configx.WithFlags(cmd.Flags()))...))) if err != nil { return err } @@ -159,7 +159,7 @@ func RunServeAll(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModifier cmd, &wg, config.PublicInterface, - EnhanceMiddleware(ctx, sl, d, publicmw, d.Config().ListenOn(config.PublicInterface), public.Router, false, config.PublicInterface), + EnhanceMiddleware(ctx, sl, d, publicmw, d.Config().ListenOn(config.PublicInterface), public.Router, config.PublicInterface), d.Config().ListenOn(config.PublicInterface), d.Config().SocketPermission(config.PublicInterface), ) @@ -170,7 +170,7 @@ func RunServeAll(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModifier cmd, &wg, config.AdminInterface, - EnhanceMiddleware(ctx, sl, d, adminmw, d.Config().ListenOn(config.AdminInterface), admin.Router, true, config.AdminInterface), + EnhanceMiddleware(ctx, sl, d, adminmw, d.Config().ListenOn(config.AdminInterface), admin.Router, config.AdminInterface), d.Config().ListenOn(config.AdminInterface), d.Config().SocketPermission(config.AdminInterface), ) @@ -308,9 +308,8 @@ func serve( ) { defer wg.Done() - if cfg, enabled := d.Config().CORS(ctx, iface); enabled { - handler = cors.New(cfg).Handler(handler) - } + cfg, _ := d.Config().CORS(ctx, iface) + handler = cors.New(cfg).Handler(handler) if tracer := d.Tracer(cmd.Context()); tracer.IsLoaded() { handler = otelx.TraceHandler( diff --git a/go.mod b/go.mod index cfa65294ed6..701d00ae516 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/ory/herodot v0.10.3-0.20230626083119-d7e5192f0d88 github.com/ory/hydra-client-go/v2 v2.1.1 github.com/ory/jsonschema/v3 v3.0.8 - github.com/ory/x v0.0.578-0.20230810070303-e5477e19f134 + github.com/ory/x v0.0.580 github.com/pborman/uuid v1.2.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.13.0 diff --git a/go.sum b/go.sum index 631593f8092..a5a46fb44b3 100644 --- a/go.sum +++ b/go.sum @@ -646,8 +646,8 @@ github.com/ory/herodot v0.10.3-0.20230626083119-d7e5192f0d88 h1:J0CIFKdpUeqKbVMw github.com/ory/herodot v0.10.3-0.20230626083119-d7e5192f0d88/go.mod h1:MMNmY6MG1uB6fnXYFaHoqdV23DTWctlPsmRCeq/2+wc= github.com/ory/jsonschema/v3 v3.0.8 h1:Ssdb3eJ4lDZ/+XnGkvQS/te0p+EkolqwTsDOCxr/FmU= github.com/ory/jsonschema/v3 v3.0.8/go.mod h1:ZPzqjDkwd3QTnb2Z6PAS+OTvBE2x5i6m25wCGx54W/0= -github.com/ory/x v0.0.578-0.20230810070303-e5477e19f134 h1:UpZ9gGyAYYm+XGJXgrSkFIMSBMyxTQjj+OM+hqacn28= -github.com/ory/x v0.0.578-0.20230810070303-e5477e19f134/go.mod h1:aeJFTlvDLGYSABzPS3z5SeLcYC52Ek7uGZiuYGcTMSU= +github.com/ory/x v0.0.580 h1:2acv/ORSaAnRGe7wEtWeyrT464o7r+8HC1fZGAb8Ui8= +github.com/ory/x v0.0.580/go.mod h1:zUGmLuqZ81XQPeTBmE1Fhfvr1ygEkDJky33IxvRaioA= github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw= github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=