-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry.go
130 lines (106 loc) · 3.3 KB
/
registry.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package driver
import (
"context"
"net/http"
"go.opentelemetry.io/otel/trace"
"github.com/ory/x/httprouterx"
"github.com/ory/hydra/v2/aead"
"github.com/ory/hydra/v2/hsm"
"github.com/ory/x/contextx"
"github.com/ory/hydra/v2/oauth2/trust"
"github.com/pkg/errors"
"github.com/ory/x/errorsx"
"github.com/ory/fosite"
foauth2 "github.com/ory/fosite/handler/oauth2"
"github.com/ory/x/logrusx"
"github.com/ory/hydra/v2/persistence"
prometheus "github.com/ory/x/prometheusx"
"github.com/ory/x/dbal"
"github.com/ory/x/healthx"
"github.com/ory/hydra/v2/client"
"github.com/ory/hydra/v2/consent"
"github.com/ory/hydra/v2/driver/config"
"github.com/ory/hydra/v2/jwk"
"github.com/ory/hydra/v2/oauth2"
"github.com/ory/hydra/v2/x"
)
type Registry interface {
dbal.Driver
Init(ctx context.Context, skipNetworkInit bool, migrate bool, ctxer contextx.Contextualizer) error
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
x.HTTPClientProvider
GetJWKSFetcherStrategy() fosite.JWKSFetcherStrategy
contextx.Provider
config.Provider
persistence.Provider
x.RegistryLogger
x.RegistryWriter
x.RegistryCookieStore
client.Registry
consent.Registry
jwk.Registry
trust.Registry
oauth2.Registry
PrometheusManager() *prometheus.MetricsManager
x.TracingProvider
FlowCipher() *aead.XChaCha20Poly1305
RegisterRoutes(ctx context.Context, admin *httprouterx.RouterAdmin, public *httprouterx.RouterPublic)
ClientHandler() *client.Handler
KeyHandler() *jwk.Handler
ConsentHandler() *consent.Handler
OAuth2Handler() *oauth2.Handler
HealthHandler() *healthx.Handler
OAuth2AwareMiddleware() func(h http.Handler) http.Handler
OAuth2HMACStrategy() *foauth2.HMACSHAStrategy
WithOAuth2Provider(f fosite.OAuth2Provider)
WithConsentStrategy(c consent.Strategy)
WithHsmContext(h hsm.Context)
}
func NewRegistryFromDSN(ctx context.Context, c *config.DefaultProvider, l *logrusx.Logger, skipNetworkInit bool, migrate bool, ctxer contextx.Contextualizer) (Registry, error) {
registry, err := NewRegistryWithoutInit(c, l)
if err != nil {
return nil, err
}
if err := registry.Init(ctx, skipNetworkInit, migrate, ctxer); err != nil {
return nil, err
}
return registry, nil
}
func NewRegistryWithoutInit(c *config.DefaultProvider, l *logrusx.Logger) (Registry, error) {
driver, err := dbal.GetDriverFor(c.DSN())
if err != nil {
return nil, errorsx.WithStack(err)
}
registry, ok := driver.(Registry)
if !ok {
return nil, errors.Errorf("driver of type %T does not implement interface Registry", driver)
}
registry = registry.WithLogger(l).WithConfig(c).WithBuildInfo(config.Version, config.Commit, config.Date)
return registry, nil
}
func CallRegistry(ctx context.Context, r Registry) {
r.ClientValidator()
r.ClientManager()
r.ClientHasher()
r.ConsentManager()
r.ConsentStrategy()
r.SubjectIdentifierAlgorithm(ctx)
r.KeyManager()
r.KeyCipher()
r.FlowCipher()
r.OAuth2Storage()
r.OAuth2Provider()
r.AudienceStrategy()
r.AccessTokenJWTStrategy()
r.OpenIDJWTStrategy()
r.OpenIDConnectRequestValidator()
r.PrometheusManager()
r.Tracer(ctx)
}