Skip to content

Commit a4e32e5

Browse files
authored
feat: /mon/status returns details only for maintainer (#5795)
1 parent b7adeeb commit a4e32e5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

engine/api/api_routes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (api *API) InitRouter() {
129129
r.Handle("/broadcast/{id}/mark", Scope(sdk.AuthConsumerScopeProject), r.POST(api.postMarkAsReadBroadcastHandler))
130130

131131
// Overall health
132-
r.Handle("/mon/status", ScopeNone(), r.GET(api.statusHandler, service.OverrideAuth(service.NoAuthMiddleware)))
132+
r.Handle("/mon/status", ScopeNone(), r.GET(api.statusHandler, service.OverrideAuth(api.authOptionalMiddleware)))
133133
r.Handle("/mon/version", ScopeNone(), r.GET(service.VersionHandler, service.OverrideAuth(service.NoAuthMiddleware)))
134134
r.Handle("/mon/db/migrate", ScopeNone(), r.GET(api.getMonDBStatusMigrateHandler, service.OverrideAuth(api.authAdminMiddleware)))
135135
r.Handle("/mon/metrics", ScopeNone(), r.GET(service.GetPrometheustMetricsHandler(api), service.OverrideAuth(service.NoAuthMiddleware)))

engine/api/status.go

+7
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,18 @@ func (api *API) statusHandler() service.Handler {
4848
status = http.StatusServiceUnavailable
4949
}
5050

51+
// Always load services to ensure that database connection is ok.
5152
srvs, err := services.LoadAll(ctx, api.mustDB(), services.LoadOptions.WithStatus)
5253
if err != nil {
5354
return err
5455
}
5556

57+
// If there is a valid session and user is maintainer, allows to get status details.
58+
currentConsumer := getAPIConsumer(ctx)
59+
if currentConsumer == nil || !isMaintainer(ctx) {
60+
return service.WriteJSON(w, nil, status)
61+
}
62+
5663
mStatus := api.computeGlobalStatus(srvs)
5764
return service.WriteJSON(w, mStatus, status)
5865
}

0 commit comments

Comments
 (0)