Skip to content

Commit 038ef42

Browse files
committed
status detailed response with valid login
Signed-off-by: Jeeva Kandasamy <jkandasa@gmail.com>
1 parent da104f2 commit 038ef42

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

pkg/api/status/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ type Status struct {
5959
Language string `json:"language"`
6060
}
6161

62-
func (s *StatusAPI) get(minimal bool) Status {
62+
func (s *StatusAPI) get(isDetailed bool) Status {
6363
status := Status{
6464
DocumentationURL: types.GetEnvString(types.ENV_DOCUMENTATION_URL),
6565
}
6666
status.MetricsDBDisabled = types.GetEnvBool(types.ENV_METRIC_DB_DISABLED)
6767

68-
if !minimal {
68+
if isDetailed {
6969
hostname, err := os.Hostname()
7070
if err != nil {
7171
s.logger.Error("error on getting hostname", zap.Error(err))
@@ -96,12 +96,12 @@ func (s *StatusAPI) get(minimal bool) Status {
9696

9797
// Get returns status with all fields
9898
func (s *StatusAPI) Get() Status {
99-
return s.get(false)
99+
return s.get(true)
100100
}
101101

102102
// GetMinimal returns limited fields, can be used under status rest api (login not required)
103103
func (s *StatusAPI) GetMinimal() Status {
104-
return s.get(true)
104+
return s.get(false)
105105
}
106106

107107
// docker creates a .dockerenv file at the root of the directory tree inside the container.

pkg/http_router/routes/status.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
func (h *Routes) registerStatusRoutes() {
1313
h.router.HandleFunc("/api/version", h.versionData).Methods(http.MethodGet)
1414
h.router.HandleFunc("/api/status", h.status).Methods(http.MethodGet)
15+
h.router.HandleFunc("/api/server/status", h.statusDetailed).Methods(http.MethodGet) // provides detailed status, available with valid auth
1516
}
1617

1718
func (h *Routes) status(w http.ResponseWriter, r *http.Request) {
@@ -26,6 +27,18 @@ func (h *Routes) status(w http.ResponseWriter, r *http.Request) {
2627
handlerUtils.WriteResponse(w, od)
2728
}
2829

30+
func (h *Routes) statusDetailed(w http.ResponseWriter, r *http.Request) {
31+
w.Header().Set("Content-Type", "application/json")
32+
33+
status := h.api.Status().Get()
34+
od, err := json.Marshal(&status)
35+
if err != nil {
36+
http.Error(w, err.Error(), http.StatusInternalServerError)
37+
return
38+
}
39+
handlerUtils.WriteResponse(w, od)
40+
}
41+
2942
func (h *Routes) versionData(w http.ResponseWriter, r *http.Request) {
3043
w.Header().Set("Content-Type", "application/json")
3144
v := version.Get()

0 commit comments

Comments
 (0)