@@ -29,13 +29,15 @@ type (
29
29
metrics * gmetric.Service
30
30
mainRouter * Router
31
31
cancelFn context.CancelFunc
32
- JWTSigner * signer.Service
33
32
mux sync.RWMutex
34
33
statusHandler http.Handler
35
- authorizer Authorizer
36
34
}
37
35
)
38
36
37
+ func (r * Service ) JWTSigner () * signer.Service {
38
+ return r .repository .JWTSigner ()
39
+ }
40
+
39
41
func (r * Service ) ServeHTTP (writer http.ResponseWriter , request * http.Request ) {
40
42
aRouter , writer , ok := r .router (writer )
41
43
if ! ok {
@@ -56,7 +58,7 @@ func (r *Service) router(writer http.ResponseWriter) (*Router, http.ResponseWrit
56
58
}
57
59
58
60
func (r * Service ) Router () (* Router , bool ) {
59
- if err := r .syncChanges (context .Background (), r .metrics , r .statusHandler , r . authorizer , false ); err != nil {
61
+ if err := r .syncChanges (context .Background (), r .metrics , r .statusHandler , false ); err != nil {
60
62
fmt .Printf ("[ERROR] failed to sync changes: %v\n " , err )
61
63
}
62
64
mainRouter := r .mainRouter
@@ -89,20 +91,27 @@ func New(ctx context.Context, opts ...Option) (*Service, error) {
89
91
}
90
92
componentRepository := options .repository
91
93
if componentRepository == nil {
94
+
92
95
componentRepository , err = repository .New (ctx , repository .WithComponentURL (aConfig .RouteURL ),
93
96
repository .WithResourceURL (aConfig .DependencyURL ),
94
97
repository .WithPluginURL (aConfig .PluginsURL ),
95
98
repository .WithApiPrefix (aConfig .APIPrefix ),
96
99
repository .WithExtensions (options .extensions ),
97
100
repository .WithMetrics (options .metrics ),
101
+ repository .WithJWTSigner (aConfig .JwtSigner ),
102
+ repository .WithJWTVerifier (aConfig .JWTValidator ),
103
+ repository .WithCognitoAuth (aConfig .Cognito ),
104
+ repository .WithFirebaseAuth (aConfig .Firebase ),
105
+ repository .WithCustomAuth (aConfig .Custom ),
106
+ repository .WithDependencyURL (aConfig .DependencyURL ),
98
107
repository .WithRefreshFrequency (aConfig .SyncFrequency ()),
99
108
repository .WithDispatcher (dispatcher .New ),
100
109
)
101
110
if err != nil {
102
111
return nil , fmt .Errorf ("failed to initialise component service: %w" , err )
103
112
}
104
113
}
105
- mainRouter , err := NewRouter (ctx , componentRepository , aConfig , options .metrics , options .statusHandler , options . authorizer )
114
+ mainRouter , err := NewRouter (ctx , componentRepository , aConfig , options .metrics , options .statusHandler )
106
115
if err != nil {
107
116
return nil , err
108
117
}
@@ -113,15 +122,8 @@ func New(ctx context.Context, opts ...Option) (*Service, error) {
113
122
mux : sync.RWMutex {},
114
123
fs : fs ,
115
124
statusHandler : options .statusHandler ,
116
- authorizer : options .authorizer ,
117
125
mainRouter : mainRouter ,
118
126
}
119
- if aConfig .JwtSigner != nil {
120
- srv .JWTSigner = signer .New (aConfig .JwtSigner )
121
- if err = srv .JWTSigner .Init (context .Background ()); err != nil {
122
- return nil , err
123
- }
124
- }
125
127
go srv .watchAsyncJob (context .Background ())
126
128
fmt .Printf ("[INFO]: started gatweay after: %s\n " , time .Since (start ))
127
129
return srv , err
@@ -189,7 +191,7 @@ func CommonURL(URLs ...string) (string, error) {
189
191
return base , nil
190
192
}
191
193
192
- func (r * Service ) syncChanges (ctx context.Context , metrics * gmetric.Service , statusHandler http.Handler , authorizer Authorizer , isFirst bool ) error {
194
+ func (r * Service ) syncChanges (ctx context.Context , metrics * gmetric.Service , statusHandler http.Handler , isFirst bool ) error {
193
195
changed , err := r .repository .SyncChanges (ctx )
194
196
if err != nil {
195
197
return err
@@ -199,7 +201,7 @@ func (r *Service) syncChanges(ctx context.Context, metrics *gmetric.Service, sta
199
201
}
200
202
start := time .Now ()
201
203
fmt .Printf ("[INFO] detected resources changes, rebuilding routers\n " )
202
- mainRouter , err := NewRouter (ctx , r .repository , r .Config , metrics , statusHandler , authorizer )
204
+ mainRouter , err := NewRouter (ctx , r .repository , r .Config , metrics , statusHandler )
203
205
if err != nil {
204
206
return err
205
207
}
0 commit comments