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
/
tenant.go
66 lines (52 loc) · 2.1 KB
/
tenant.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
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"`
Key string `json:"key"`
Applications Applications `json:"applications"`
Directories Directories `json:"directories"`
}
//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.doWithResult(
client.newRequest(
"GET",
buildRelativeURL("tenants", "current"),
emptyPayload(),
ApplicationJSON,
), 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)
}
//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()), emptyPayload(), 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()), emptyPayload(), directories)
return directories, err
}