-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: reduce registry code bloat and improve DI (#3794)
- Loading branch information
Showing
17 changed files
with
1,178 additions
and
804 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package driver | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"go.opentelemetry.io/otel/trace" | ||
|
||
"github.com/ory/fosite" | ||
"github.com/ory/fosite/handler/oauth2" | ||
"github.com/ory/hydra/v2/consent" | ||
"github.com/ory/hydra/v2/driver/config" | ||
"github.com/ory/hydra/v2/fositex" | ||
"github.com/ory/hydra/v2/hsm" | ||
"github.com/ory/hydra/v2/internal/kratos" | ||
"github.com/ory/x/contextx" | ||
"github.com/ory/x/logrusx" | ||
) | ||
|
||
// WritableRegistry is a deprecated interface that should not be used anymore. | ||
// | ||
// Deprecate this at some point. | ||
type WritableRegistry interface { | ||
// WithBuildInfo(v, h, d string) Registry | ||
|
||
WithConfig(c *config.DefaultProvider) Registry | ||
WithContextualizer(ctxer contextx.Contextualizer) Registry | ||
WithLogger(l *logrusx.Logger) Registry | ||
WithTracer(t trace.Tracer) Registry | ||
WithTracerWrapper(TracerWrapper) Registry | ||
WithKratos(k kratos.Client) Registry | ||
WithExtraFositeFactories(f []fositex.Factory) Registry | ||
ExtraFositeFactories() []fositex.Factory | ||
WithOAuth2Provider(f fosite.OAuth2Provider) | ||
WithConsentStrategy(c consent.Strategy) | ||
WithHsmContext(h hsm.Context) | ||
} | ||
|
||
type RegistryModifier func(r Registry) error | ||
|
||
func WithRegistryModifiers(f ...RegistryModifier) OptionsModifier { | ||
return func(o *Options) { | ||
o.registryModifiers = f | ||
} | ||
} | ||
|
||
func RegistryWithHMACSHAStrategy(s func(r Registry) oauth2.CoreStrategy) RegistryModifier { | ||
return func(r Registry) error { | ||
switch rt := r.(type) { | ||
case *RegistrySQL: | ||
rt.hmacs = s(r) | ||
default: | ||
return errors.Errorf("unable to set HMAC strategy on registry of type %T", r) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func RegistryWithHsmContext(h hsm.Context) RegistryModifier { | ||
return func(r Registry) error { | ||
switch rt := r.(type) { | ||
case *RegistrySQL: | ||
rt.hsm = h | ||
default: | ||
return errors.Errorf("unable to set HMAC strategy on registry of type %T", r) | ||
} | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.