forked from jarias/stormpath-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtenant.go
More file actions
67 lines (52 loc) · 2.35 KB
/
Copy pathtenant.go
File metadata and controls
67 lines (52 loc) · 2.35 KB
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
package stormpath
import "net/url"
//Tenant represents a Stormpath tennat see http://docs.stormpath.com/rest/product-guide/#tenants
type Tenant struct {
customDataAwareResource
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
Applications *Applications `json:"applications,omitempty"`
Directories *Directories `json:"directories,omitempty"`
Groups *Groups `json:"groups,omitempty"`
Organizations *Organizations `json:"organizations,omitempty"`
}
//CurrentTenant returns the current tenant see http://docs.stormpath.com/rest/product-guide/#retrieve-the-current-tenant
func CurrentTenant() (*Tenant, error) {
tenant := &Tenant{}
err := client.get(buildRelativeURL("tenants", "current"), tenant)
return tenant, err
}
//CreateApplication creates a new application for the given tenant
//
//See: http://docs.stormpath.com/rest/product-guide/#tenant-applications
func (tenant *Tenant) CreateApplication(app *Application) error {
var extraParams = url.Values{}
extraParams.Add("createDirectory", "true")
return client.post(buildRelativeURL("applications", requestParams(extraParams)), app, app)
}
//CreateDirectory creates a new directory for the given tenant
//
//See: http://docs.stormpath.com/rest/product-guide/#tenant-directories
func (tenant *Tenant) CreateDirectory(dir *Directory) error {
return client.post(buildRelativeURL("directories"), dir, dir)
}
//CreateOrganization creates new organization for the given tenant
func (tenant *Tenant) CreateOrganization(org *Organization) error {
return client.post(buildRelativeURL("organizations"), org, org)
}
//GetApplications returns all the applications for the given tenant
//
//See: http://docs.stormpath.com/rest/product-guide/#tenant-applications
func (tenant *Tenant) GetApplications(criteria Criteria) (*Applications, error) {
apps := &Applications{}
err := client.get(buildAbsoluteURL(tenant.Applications.Href, criteria.ToQueryString()), apps)
return apps, err
}
//GetDirectories returns all the directories for the given tenant
//
//See: http://docs.stormpath.com/rest/product-guide/#tenant-directories
func (tenant *Tenant) GetDirectories(criteria Criteria) (*Directories, error) {
directories := &Directories{}
err := client.get(buildAbsoluteURL(tenant.Directories.Href, criteria.ToQueryString()), directories)
return directories, err
}