-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.go
52 lines (41 loc) · 1019 Bytes
/
group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package onelogin
import "golang.org/x/net/context"
// GroupService deals with OneLogin groups.
type GroupService struct {
*service
}
// Group contains the ID (immutable) and name (mutable) of a group.
type Group struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
// GetGroups returns all the OneLogin groups.
func (s *GroupService) GetGroups(ctx context.Context) ([]*Group, error) {
u := "/api/1/groups"
var groups []*Group
var afterCursor string
for {
uu, err := addOptions(u, &urlQuery{AfterCursor: afterCursor})
if err != nil {
return nil, err
}
req, err := s.client.NewRequest("GET", uu, nil)
if err != nil {
return nil, err
}
if err := s.client.AddAuthorization(ctx, req); err != nil {
return nil, err
}
var gs []*Group
resp, err := s.client.Do(ctx, req, &gs)
if err != nil {
return nil, err
}
groups = append(groups, gs...)
if resp.PaginationAfterCursor == nil {
break
}
afterCursor = *resp.PaginationAfterCursor
}
return groups, nil
}