-
Notifications
You must be signed in to change notification settings - Fork 0
/
di.go
70 lines (61 loc) · 1.85 KB
/
di.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
}
}