mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(apigateway): add auth/stats api to retrieve system info (#10181)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -88,6 +88,7 @@ func (h *AuthHandlers) AddMethods() {
|
||||
// auth middleware handler
|
||||
h.AddByMethod(GET, FetchAuthToken,
|
||||
NewHP(h.getUser, "user"),
|
||||
NewHP(h.getStats, "stats"),
|
||||
NewHP(h.getPermissionDetails, "permissions"),
|
||||
NewHP(h.getAdminResources, "admin_resources"),
|
||||
NewHP(h.getResources, "scoped_resources"),
|
||||
@@ -210,6 +211,42 @@ func (h *AuthHandlers) getUser(ctx context.Context, w http.ResponseWriter, req *
|
||||
appsrv.SendJSON(w, body)
|
||||
}
|
||||
|
||||
func getStatsInfo(ctx context.Context, req *http.Request) (jsonutils.JSONObject, error) {
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req), "")
|
||||
params, _ := jsonutils.ParseQueryString(req.URL.RawQuery)
|
||||
|
||||
if params == nil {
|
||||
params = jsonutils.NewDict()
|
||||
}
|
||||
params.(*jsonutils.JSONDict).Add(jsonutils.NewInt(1), "limit")
|
||||
|
||||
ret := struct {
|
||||
Cloudaccounts int
|
||||
}{}
|
||||
|
||||
accounts, err := modules.Cloudaccounts.List(s, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.Cloudaccounts = accounts.Total
|
||||
|
||||
return jsonutils.Marshal(ret), nil
|
||||
}
|
||||
|
||||
func (h *AuthHandlers) getStats(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
data, err := getStatsInfo(ctx, req)
|
||||
if err != nil {
|
||||
httperrors.NotFoundError(ctx, w, err.Error())
|
||||
return
|
||||
}
|
||||
body := jsonutils.NewDict()
|
||||
body.Add(data, "data")
|
||||
|
||||
appsrv.SendJSON(w, body)
|
||||
}
|
||||
|
||||
func (h *AuthHandlers) initTotpSecrets(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
initTotpSecrets(ctx, w, req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user