This repository has been archived by the owner on Apr 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
group.go
65 lines (53 loc) · 1.75 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
package stormpath
//Group represents a Stormpath Group
//
//See: http://docs.stormpath.com/rest/product-guide/#groups
type Group struct {
accountStoreResource
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Status string `json:"status,omitempty"`
Tenant *Tenant `json:"tenant,omitempty"`
Directory *Directory `json:"directory,omitempty"`
AccountMemberships *GroupMemberships `json:"accountMemberships,omitempty"`
}
//Groups represent a paged result of groups
type Groups struct {
collectionResource
Items []Group `json:"items,omitempty"`
}
//NewGroup creates a new Group with the given name
func NewGroup(name string) *Group {
return &Group{Name: name}
}
//GetGroup loads a group by href and criteria
func GetGroup(href string, criteria GroupCriteria) (*Group, error) {
group := &Group{}
err := client.get(
buildAbsoluteURL(href, criteria.toQueryString()),
group,
)
if err != nil {
return nil, err
}
return group, nil
}
//Refresh refreshes the resource by doing a GET to the resource href endpoint
func (group *Group) Refresh() error {
return client.get(group.Href, group)
}
//Update updates the given resource, by doing a POST to the resource Href
func (group *Group) Update() error {
return client.post(group.Href, group, group)
}
//GetGroupAccountMemberships loads the given group memeberships
func (group *Group) GetGroupAccountMemberships(criteria GroupMembershipCriteria) (*GroupMemberships, error) {
err := client.get(
buildAbsoluteURL(group.AccountMemberships.Href, criteria.toQueryString()),
group.AccountMemberships,
)
if err != nil {
return nil, err
}
return group.AccountMemberships, nil
}