Skip to content

Commit 1c76741

Browse files
committed
Merge branch 'release/0.18.1'
2 parents faa42a2 + c1f5daa commit 1c76741

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

service/initialise.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import (
1515

1616
// ExternalServiceList holds the initialiser and initialisation state of external services.
1717
type ExternalServiceList struct {
18-
HealthCheck bool
19-
Init Initialiser
20-
MongoDB bool
18+
AuthorisationMiddleware bool
19+
HealthCheck bool
20+
Init Initialiser
21+
MongoDB bool
2122
}
2223

2324
// NewServiceList creates a new service list with the provided initialiser
@@ -91,5 +92,6 @@ func (e *Init) DoGetAuthorisationMiddleware(ctx context.Context, authorisationCo
9192

9293
// GetAuthorisationMiddleware creates a new instance of authorisation.Middlware
9394
func (e *ExternalServiceList) GetAuthorisationMiddleware(ctx context.Context, authorisationConfig *authorisation.Config) (authorisation.Middleware, error) {
95+
e.AuthorisationMiddleware = true
9496
return e.Init.DoGetAuthorisationMiddleware(ctx, authorisationConfig)
9597
}

service/service.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import (
1616

1717
// Service contains all the configs, server and clients to run the dp-topic-api API
1818
type Service struct {
19-
Config *config.Config
20-
Server HTTPServer
21-
Router *mux.Router
22-
api *api.API
23-
ServiceList *ExternalServiceList
24-
HealthCheck HealthChecker
25-
MongoDB PermissionsStore
19+
Config *config.Config
20+
Server HTTPServer
21+
Router *mux.Router
22+
api *api.API
23+
ServiceList *ExternalServiceList
24+
HealthCheck HealthChecker
25+
MongoDB PermissionsStore
2626
AuthorisationMiddleware authorisation.Middleware
2727
}
2828

@@ -78,13 +78,13 @@ func Run(ctx context.Context, cfg *config.Config, serviceList *ExternalServiceLi
7878
}()
7979

8080
return &Service{
81-
Config: cfg,
82-
Router: r,
83-
api: a,
84-
HealthCheck: hc,
85-
ServiceList: serviceList,
86-
Server: s,
87-
MongoDB: mongoDB,
81+
Config: cfg,
82+
Router: r,
83+
api: a,
84+
HealthCheck: hc,
85+
ServiceList: serviceList,
86+
Server: s,
87+
MongoDB: mongoDB,
8888
AuthorisationMiddleware: authorisationMiddleware,
8989
}, nil
9090
}
@@ -119,9 +119,11 @@ func (svc *Service) Close(ctx context.Context) error {
119119
}
120120
}
121121

122-
if err := svc.AuthorisationMiddleware.Close(ctx); err != nil {
123-
log.Error(ctx, "failed to close authorisation middleware", err)
124-
hasShutdownError = true
122+
if svc.ServiceList.AuthorisationMiddleware {
123+
if err := svc.AuthorisationMiddleware.Close(ctx); err != nil {
124+
log.Error(ctx, "failed to close authorisation middleware", err)
125+
hasShutdownError = true
126+
}
125127
}
126128
}()
127129

service/service_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ func TestRun(t *testing.T) {
101101

102102
Convey("Given that initialising mongoDB returns an error", func() {
103103
initMock := &mock.InitialiserMock{
104-
DoGetHTTPServerFunc: funcDoGetHTTPServerNil,
105-
DoGetMongoDBFunc: funcDoGetMongoDbErr,
106-
DoGetHealthCheckFunc: funcDoGetHealthcheckOk,
104+
DoGetHTTPServerFunc: funcDoGetHTTPServerNil,
105+
DoGetMongoDBFunc: funcDoGetMongoDbErr,
106+
DoGetHealthCheckFunc: funcDoGetHealthcheckOk,
107107
DoGetAuthorisationMiddlewareFunc: funcDoGetAuthorisationMiddleware,
108108
}
109109
svcErrors := make(chan error, 1)
@@ -121,9 +121,9 @@ func TestRun(t *testing.T) {
121121

122122
// setup (run before each `Convey` at this scope / indentation):
123123
initMock := &mock.InitialiserMock{
124-
DoGetHTTPServerFunc: funcDoGetHTTPServerNil,
125-
DoGetHealthCheckFunc: funcDoGetHealthcheckErr,
126-
DoGetMongoDBFunc: funcDoGetMongoDbOk,
124+
DoGetHTTPServerFunc: funcDoGetHTTPServerNil,
125+
DoGetHealthCheckFunc: funcDoGetHealthcheckErr,
126+
DoGetMongoDBFunc: funcDoGetMongoDbOk,
127127
DoGetAuthorisationMiddlewareFunc: funcDoGetAuthorisationMiddleware,
128128
}
129129
svcErrors := make(chan error, 1)
@@ -145,9 +145,9 @@ func TestRun(t *testing.T) {
145145

146146
// setup (run before each `Convey` at this scope / indentation):
147147
initMock := &mock.InitialiserMock{
148-
DoGetHTTPServerFunc: funcDoGetHTTPServer,
149-
DoGetHealthCheckFunc: funcDoGetHealthcheckOk,
150-
DoGetMongoDBFunc: funcDoGetMongoDbOk,
148+
DoGetHTTPServerFunc: funcDoGetHTTPServer,
149+
DoGetHealthCheckFunc: funcDoGetHealthcheckOk,
150+
DoGetMongoDBFunc: funcDoGetMongoDbOk,
151151
DoGetAuthorisationMiddlewareFunc: funcDoGetAuthorisationMiddleware,
152152
}
153153
svcErrors := make(chan error, 1)
@@ -193,7 +193,7 @@ func TestRun(t *testing.T) {
193193
DoGetHealthCheckFunc: func(cfg *config.Config, buildTime string, gitCommit string, version string) (service.HealthChecker, error) {
194194
return hcMockAddFail, nil
195195
},
196-
DoGetMongoDBFunc: funcDoGetMongoDbOk,
196+
DoGetMongoDBFunc: funcDoGetMongoDbOk,
197197
DoGetAuthorisationMiddlewareFunc: funcDoGetAuthorisationMiddleware,
198198
// ADD CODE: add the checkers that you want to register here
199199
}
@@ -217,9 +217,9 @@ func TestRun(t *testing.T) {
217217

218218
// setup (run before each `Convey` at this scope / indentation):
219219
initMock := &mock.InitialiserMock{
220-
DoGetHealthCheckFunc: funcDoGetHealthcheckOk,
221-
DoGetHTTPServerFunc: funcDoGetFailingHTTPServer,
222-
DoGetMongoDBFunc: funcDoGetMongoDbOk,
220+
DoGetHealthCheckFunc: funcDoGetHealthcheckOk,
221+
DoGetHTTPServerFunc: funcDoGetFailingHTTPServer,
222+
DoGetMongoDBFunc: funcDoGetMongoDbOk,
223223
DoGetAuthorisationMiddlewareFunc: funcDoGetAuthorisationMiddleware,
224224
}
225225
svcErrors := make(chan error, 1)

0 commit comments

Comments
 (0)