From fce72329de8a0e0da7adef7838c602bce9aa6c2a Mon Sep 17 00:00:00 2001 From: Sonia <31467983+bsoniam@users.noreply.github.com> Date: Mon, 4 Nov 2019 17:35:37 +0100 Subject: [PATCH] [CLOUDTRUST-1820] add GetStatisticsUsers + GetStatisticsAuthenticators --- statistics.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 statistics.go diff --git a/statistics.go b/statistics.go new file mode 100644 index 0000000..7919f1f --- /dev/null +++ b/statistics.go @@ -0,0 +1,32 @@ +package keycloak + +import ( + "gopkg.in/h2non/gentleman.v2/plugins/url" +) + +const ( + statisticsPath = "/auth/realms/master/api/admin/realms/:realm/statistics" + statisticsUsers = statisticsPath + "/users" + statisticsCredentials = statisticsPath + "/credentials" +) + +// StatisticsUsersRepresentation elements returned by GetStatisticsUsers +type StatisticsUsersRepresentation struct { + Total int64 `json:"total,omitempty"` + Disabled int64 `json:"disabled,omitempty"` + Inactive int64 `json:"inactive,omitempty"` +} + +// GetStatisticsUsers returns statisctics on the total number of users and on their status +func (c *Client) GetStatisticsUsers(accessToken string, realmName string) (StatisticsUsersRepresentation, error) { + var resp = StatisticsUsersRepresentation{} + var err = c.get(accessToken, &resp, url.Path(statisticsUsers), url.Param("realm", realmName)) + return resp, err +} + +// GetStatisticsAuthenticators returns statistics on the authenticators used by the users on a certain realm +func (c *Client) GetStatisticsAuthenticators(accessToken string, realmName string) (map[string]int64, error) { + var resp = make(map[string]int64) + var err = c.get(accessToken, &resp, url.Path(statisticsCredentials), url.Param("realm", realmName)) + return resp, err +}