Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Aug 11, 2023
1 parent c033e43 commit 0bbcc35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
27 changes: 13 additions & 14 deletions cmd/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand All @@ -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".`)
}
Expand All @@ -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)
Expand All @@ -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),
)
Expand All @@ -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)
Expand All @@ -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),
)
Expand All @@ -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
}
Expand All @@ -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),
)
Expand All @@ -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),
)
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 0bbcc35

Please sign in to comment.