Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: admin events #338

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4090,6 +4090,28 @@ func (g *GoCloak) GetEvents(ctx context.Context, token string, realm string, par
return result, nil
}

// GetAdminEvents returns admin events
func (g *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 := g.GetRequestWithBearerAuth(ctx, token).
SetResult(&result).
SetQueryParams(queryParams).
Get(g.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 (g *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
34 changes: 34 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,40 @@
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"`

Check warning on line 1365 in models.go

View workflow job for this annotation

GitHub Actions / tests

var-naming: struct field AuthIpAddress should be AuthIPAddress (revive)
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
Loading