Skip to content

Commit

Permalink
[CLOUDTRUST-1820] add GetStatisticsUsers + GetStatisticsAuthenticators
Browse files Browse the repository at this point in the history
  • Loading branch information
bsoniam authored Nov 4, 2019
1 parent 87e0004 commit fce7232
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions statistics.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit fce7232

Please sign in to comment.