forked from jarias/stormpath-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_store_mapping.go
99 lines (82 loc) · 3.41 KB
/
account_store_mapping.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package stormpath
import "strings"
//ApplicationAccountStoreMapping represents an Stormpath account store mapping
//
//See: http://docs.stormpath.com/rest/product-guide/#account-store-mappings
type ApplicationAccountStoreMapping struct {
resource
ListIndex *int `json:"collectionResourceIndex,omitempty"`
IsDefaultAccountStore bool `json:"isDefaultAccountStore"`
IsDefaultGroupStore bool `json:"isDefaultGroupStore"`
Application *Application `json:"application,omitempty"`
AccountStore *resource `json:"accountStore,omitempty"`
}
type OrganizationAccountStoreMapping struct {
resource
ListIndex *int `json:"collectionResourceIndex,omitempty"`
IsDefaultAccountStore bool `json:"isDefaultAccountStore"`
IsDefaultGroupStore bool `json:"isDefaultGroupStore"`
Organization *Organization `json:"organization,omitempty"`
AccountStore *resource `json:"accountStore,omitempty"`
}
//ApplicationAccountStoreMappings represents a pages result of account store mappings
//
//See: http://docs.stormpath.com/rest/product-guide/#collectionResource-account-store-mappings
type ApplicationAccountStoreMappings struct {
collectionResource
Items []ApplicationAccountStoreMapping `json:"items,omitempty"`
}
type OrganizationAccountStoreMappings struct {
collectionResource
Items []OrganizationAccountStoreMapping `json:"items,omitempty"`
}
//NewAccountStoreMapping creates a new account store mappings
func NewApplicationAccountStoreMapping(applicationHref string, accountStoreHref string) *ApplicationAccountStoreMapping {
app := Application{}
app.Href = applicationHref
return &ApplicationAccountStoreMapping{
Application: &app,
AccountStore: &resource{Href: accountStoreHref},
}
}
func NewOrganizationAccountStoreMapping(organizationHref string, accountStoreHref string) *OrganizationAccountStoreMapping {
org := Organization{}
org.Href = organizationHref
return &OrganizationAccountStoreMapping{
Organization: &org,
AccountStore: &resource{Href: accountStoreHref},
}
}
//Save saves the given account store mapping
func (mapping *ApplicationAccountStoreMapping) Save() error {
url := buildRelativeURL("accountStoreMappings")
if mapping.Href != "" {
url = mapping.Href
}
return client.post(url, mapping, mapping)
}
func (mapping *OrganizationAccountStoreMapping) Save() error {
url := buildRelativeURL("organizationAccountStoreMappings")
if mapping.Href != "" {
url = mapping.Href
}
return client.post(url, mapping, mapping)
}
func (mapping *ApplicationAccountStoreMapping) IsAccountStoreDirectory() bool {
return strings.Contains(mapping.AccountStore.Href, "/directories/")
}
func (mapping *ApplicationAccountStoreMapping) IsAccountStoreGroup() bool {
return strings.Contains(mapping.AccountStore.Href, "/groups/")
}
func (mapping *ApplicationAccountStoreMapping) IsAccountStoreOrganization() bool {
return strings.Contains(mapping.AccountStore.Href, "/organizations/")
}
func (mapping *OrganizationAccountStoreMapping) IsAccountStoreDirectory() bool {
return strings.Contains(mapping.AccountStore.Href, "/directories/")
}
func (mapping *OrganizationAccountStoreMapping) IsAccountStoreGroup() bool {
return strings.Contains(mapping.AccountStore.Href, "/groups/")
}
func (mapping *OrganizationAccountStoreMapping) IsAccountStoreOrganization() bool {
return strings.Contains(mapping.AccountStore.Href, "/organizations/")
}