forked from jarias/stormpath-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
directory.go
78 lines (63 loc) · 2.17 KB
/
directory.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
66
67
68
69
70
71
72
73
74
75
76
77
78
package stormpath
import (
"time"
)
//Directory represents a Stormpath directory object
//
//See: http://docs.stormpath.com/rest/product-guide/#directories
type Directory struct {
accountStoreResource
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Status string `json:"status,omitempty"`
Groups *Groups `json:"groups,omitempty"`
Tenant *Tenant `json:"tenant,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
ModifiedAt time.Time `json:"modifiedAt,omitempty"`
}
//Directories represnets a paged result of directories
type Directories struct {
collectionResource
Items []Directory `json:"items"`
}
//NewDirectory creates a new directory with the given name
func NewDirectory(name string) *Directory {
return &Directory{Name: name}
}
func GetDirectory(href string, criteria Criteria) (*Directory, error) {
directory := &Directory{}
err := client.get(
buildAbsoluteURL(href, criteria.ToQueryString()),
emptyPayload(),
directory,
)
return directory, err
}
//GetGroups returns all the groups from a directory
func (dir *Directory) GetGroups(criteria Criteria) (*Groups, error) {
groups := &Groups{}
err := client.get(
buildAbsoluteURL(dir.Groups.Href, criteria.ToQueryString()),
emptyPayload(),
groups,
)
return groups, err
}
//CreateGroup creates a new group in the directory
func (dir *Directory) CreateGroup(group *Group) error {
return client.post(dir.Groups.Href, group, group)
}
//RegisterAccount registers a new account into the directory
//
//See: http://docs.stormpath.com/rest/product-guide/#directory-accounts
func (dir *Directory) RegisterAccount(account *Account) error {
return client.post(dir.Accounts.Href, account, account)
}
//RegisterSocialAccount registers a new account into the application using an external provider Google, Facebook
//
//See: http://docs.stormpath.com/rest/product-guide/#accessing-accounts-with-google-authorization-codes-or-an-access-tokens
func (dir *Directory) RegisterSocialAccount(socialAccount *SocialAccount) (*Account, error) {
account := Account{}
err := client.post(dir.Accounts.Href, socialAccount, &account)
return &account, err
}