Skip to content

Commit

Permalink
add GetEvents endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
RayFinney committed Jun 17, 2022
1 parent 46962f9 commit 0969292
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 9 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (g *gopherCloak) LogoutAllUserSessions(accessToken string, realm string, us
return nil
}

func (g *gopherCloak) GetEvents(accessToken string, realm, query string) ([]byte, error) {
func (g *gopherCloak) GetEvents(accessToken string, realm, query string) ([]*Event, error) {
if len(query) > 0 && string(query[0]) != "?" {
query = "?" + query
}
Expand All @@ -448,8 +448,14 @@ func (g *gopherCloak) GetEvents(accessToken string, realm, query string) ([]byte
return nil, err
}
defer response.Body.Close()
content, _ := ioutil.ReadAll(response.Body)
return content, g.checkForErrorsInResponse(response)
body, _ := ioutil.ReadAll(response.Body)
events := make([]*Event, 0)
err = json.Unmarshal(body, &events)
if err != nil {
return nil, err
}

return events, g.checkForErrorsInResponse(response)
}

// ===============
Expand Down
2 changes: 1 addition & 1 deletion gopherscloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ type GophersCloak interface {
// GetGroupMembers get a list of users of group with id in realm
GetGroupMembers(accessToken string, realm, groupID string) ([]*User, error)
// GetEvents Returns all events, or filters them based on URL query parameters listed here
GetEvents(accessToken string, realm, query string) ([]byte, error)
GetEvents(accessToken string, realm, query string) ([]*Event, error)
}
11 changes: 11 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,14 @@ type Group struct {
ClientRoles map[string][]string `json:"clientRoles,omitempty"`
RealmRoles []string `json:"realmRoles,omitempty"`
}

type Event struct {
Time int64 `json:"time"`
Type string `json:"type"`
RealmId string `json:"realmId"`
ClientId string `json:"clientId"`
UserId string `json:"userId"`
SessionId string `json:"sessionId"`
IpAddress string `json:"ipAddress"`
Details string `json:"details"`
}

0 comments on commit 0969292

Please sign in to comment.