github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/api4/cluster.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package api4
     5  
     6  import (
     7  	"net/http"
     8  
     9  	"github.com/masterhung0112/hk_server/v5/model"
    10  )
    11  
    12  func (api *API) InitCluster() {
    13  	api.BaseRoutes.Cluster.Handle("/status", api.ApiSessionRequired(getClusterStatus)).Methods("GET")
    14  }
    15  
    16  func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
    17  	if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PERMISSION_SYSCONSOLE_READ_ENVIRONMENT_HIGH_AVAILABILITY) {
    18  		c.SetPermissionError(model.PERMISSION_SYSCONSOLE_READ_ENVIRONMENT_HIGH_AVAILABILITY)
    19  		return
    20  	}
    21  
    22  	if *c.App.Config().ExperimentalSettings.RestrictSystemAdmin {
    23  		c.Err = model.NewAppError("getClusterStatus", "api.restricted_system_admin", nil, "", http.StatusForbidden)
    24  		return
    25  	}
    26  
    27  	infos := c.App.GetClusterStatus()
    28  	w.Write([]byte(model.ClusterInfosToJson(infos)))
    29  }