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
/
account_store_mapping.go
111 lines (94 loc) · 4.6 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
100
101
102
103
104
105
106
107
108
109
110
111
package stormpath
import "strings"
//ApplicationAccountStoreMapping represents an Stormpath account store mapping
//
//See: https://docs.stormpath.com/rest/product-guide/latest/reference.html#account-store-mapping
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"`
}
//OrganizationAccountStoreMapping represents an Stormpath account store mapping for an Organization resource
//
//See: https://docs.stormpath.com/rest/product-guide/latest/reference.html?organization-account-store-mapping-operations
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"`
}
//OrganizationAccountStoreMappings represents a collection of OrganizationAccountStoreMapping
type OrganizationAccountStoreMappings struct {
collectionResource
Items []OrganizationAccountStoreMapping `json:"items,omitempty"`
}
//NewApplicationAccountStoreMapping creates a new account store mapping for the Application resource
func NewApplicationAccountStoreMapping(applicationHref string, accountStoreHref string) *ApplicationAccountStoreMapping {
app := Application{}
app.Href = applicationHref
return &ApplicationAccountStoreMapping{
Application: &app,
AccountStore: &resource{Href: accountStoreHref},
}
}
//NewOrganizationAccountStoreMapping creates a new account mapping for the Organization resource
func NewOrganizationAccountStoreMapping(organizationHref string, accountStoreHref string) *OrganizationAccountStoreMapping {
org := Organization{}
org.Href = organizationHref
return &OrganizationAccountStoreMapping{
Organization: &org,
AccountStore: &resource{Href: accountStoreHref},
}
}
//Save saves the given ApplicationAccountStoreMapping
func (mapping *ApplicationAccountStoreMapping) Save() error {
url := buildRelativeURL("accountStoreMappings")
if mapping.Href != "" {
url = mapping.Href
}
return client.post(url, mapping, mapping)
}
//Save saves the given OrganizationAccountStoreMapping
func (mapping *OrganizationAccountStoreMapping) Save() error {
url := buildRelativeURL("organizationAccountStoreMappings")
if mapping.Href != "" {
url = mapping.Href
}
return client.post(url, mapping, mapping)
}
//IsAccountStoreDirectory checks if a given ApplicationAccountStoreMapping maps an Application to a Directory
func (mapping *ApplicationAccountStoreMapping) IsAccountStoreDirectory() bool {
return strings.Contains(mapping.AccountStore.Href, "/directories/")
}
//IsAccountStoreGroup checks if a given ApplicationAccountStoreMapping maps an Application to a Group
func (mapping *ApplicationAccountStoreMapping) IsAccountStoreGroup() bool {
return strings.Contains(mapping.AccountStore.Href, "/groups/")
}
//IsAccountStoreOrganization checks if a given ApplicationAccountStoreMapping maps an Application to an Organization
func (mapping *ApplicationAccountStoreMapping) IsAccountStoreOrganization() bool {
return strings.Contains(mapping.AccountStore.Href, "/organizations/")
}
//IsAccountStoreDirectory checks if a given OrganizationAccountStoreMapping maps an Application to a Directory
func (mapping *OrganizationAccountStoreMapping) IsAccountStoreDirectory() bool {
return strings.Contains(mapping.AccountStore.Href, "/directories/")
}
//IsAccountStoreGroup checks if a given OrganizationAccountStoreMapping maps an Application to a Directory
func (mapping *OrganizationAccountStoreMapping) IsAccountStoreGroup() bool {
return strings.Contains(mapping.AccountStore.Href, "/groups/")
}
//IsAccountStoreOrganization checks if a given ApplicationAccountStoreMapping maps an Application to an Organization
func (mapping *OrganizationAccountStoreMapping) IsAccountStoreOrganization() bool {
return strings.Contains(mapping.AccountStore.Href, "/organizations/")
}