Skip to content

Commit

Permalink
add GetAdminEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenard committed Jun 9, 2022
1 parent 9556250 commit b95ca62
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
22 changes: 22 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3708,6 +3708,28 @@ func (client *gocloak) GetEvents(ctx context.Context, token string, realm string
return result, nil
}

// GetAdminEvents returns admin events
func (client *gocloak) GetAdminEvents(ctx context.Context, token string, realm string, params GetAdminEventsParams) ([]*AdminEventRepresentation, error) {
const errMessage = "could not get admin events"

queryParams, err := GetQueryParams(params)
if err != nil {
return nil, errors.Wrap(err, errMessage)
}

var result []*AdminEventRepresentation
resp, err := client.getRequestWithBearerAuth(ctx, token).
SetResult(&result).
SetQueryParams(queryParams).
Get(client.getAdminRealmURL(realm, "admin-events"))

if err := checkForError(resp, err, errMessage); err != nil {
return nil, err
}

return result, nil
}

// GetClientScopesScopeMappingsRealmRolesAvailable returns realm-level roles that are available to attach to this client scope
func (client *gocloak) GetClientScopesScopeMappingsRealmRolesAvailable(ctx context.Context, token, realm, clientScopeID string) ([]*Role, error) {
const errMessage = "could not get available realm-level roles with the client-scope"
Expand Down
2 changes: 2 additions & 0 deletions gocloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ type GoCloak interface {

// GetEvents returns events
GetEvents(ctx context.Context, token string, realm string, params GetEventsParams) ([]*EventRepresentation, error)
// GetAdminEvents returns admin events
GetAdminEvents(ctx context.Context, token string, realm string, params GetAdminEventsParams) ([]*AdminEventRepresentation, error)

// -------------------
// RequiredActions API
Expand Down
34 changes: 34 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,40 @@ type EventRepresentation struct {
Details map[string]string `json:"details,omitempty"`
}

// GetAdminEventsParams represents the optional parameters for getting events
type GetAdminEventsParams struct {
AuthClient *string `json:"authClient,omitempty"`
AuthIpAddress *string `json:"authIpAddress,omitempty"`
AuthRealm *string `json:"authRealm,omitempty"`
AuthUser *string `json:"authUser,omitempty"`
DateFrom *string `json:"dateFrom,omitempty"`
DateTo *string `json:"dateTo,omitempty"`
First *int32 `json:"first,omitempty"`
Max *int32 `json:"max,omitempty"`
OperationTypes []string `json:"operationTypes,omitempty"`
ResourcePath *string `json:"resourcePath,omitempty"`
ResourceTypes []string `json:"resourceTypes,omitempty"`
}

// AdminEventRepresentation is a representation of an Admin Event
type AdminEventRepresentation struct {
Time int64 `json:"time,omitempty"`
OperationType *string `json:"operationType,omitempty"`
RealmID *string `json:"realmId,omitempty"`
ResourceType *string `json:"resourceType,omitempty"`
ResourcePath *string `json:"resourcePath,omitempty"`
AuthDetails *AdminEventAuthDetailsRepresentation `json:"authDetails,omitempty"`
Representation *string `json:"representation,omitempty"`
}

// AdminEventAuthDetailsRepresentation is a representation of an Admin Event Details
type AdminEventAuthDetailsRepresentation struct {
RealmID *string `json:"realmId,omitempty"`
ClientID *string `json:"clientId,omitempty"`
UserID *string `json:"userId,omitempty"`
IPAddress *string `json:"ipAddress,omitempty"`
}

// CredentialRepresentation is a representations of the credentials
// v7: https://www.keycloak.org/docs-api/7.0/rest-api/index.html#_credentialrepresentation
// v8: https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_credentialrepresentation
Expand Down

0 comments on commit b95ca62

Please sign in to comment.