blob: bf525549c530c5d2bafa77f6bf41bf5a25261013 [file] [log] [blame]
Ash Wilson1f110512014-10-02 15:43:47 -04001package tenants
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Ash Wilson1f110512014-10-02 15:43:47 -04006)
7
8// Tenant is a grouping of users in the identity service.
9type Tenant struct {
10 // ID is a unique identifier for this tenant.
Jon Perritt3c166472016-02-25 03:07:41 -060011 ID string `json:"id"`
Ash Wilson1f110512014-10-02 15:43:47 -040012
13 // Name is a friendlier user-facing name for this tenant.
Jon Perritt3c166472016-02-25 03:07:41 -060014 Name string `json:"name"`
Ash Wilson1f110512014-10-02 15:43:47 -040015
16 // Description is a human-readable explanation of this Tenant's purpose.
Jon Perritt3c166472016-02-25 03:07:41 -060017 Description string `json:"description"`
Ash Wilson1f110512014-10-02 15:43:47 -040018
19 // Enabled indicates whether or not a tenant is active.
Jon Perritt3c166472016-02-25 03:07:41 -060020 Enabled bool `json:"enabled"`
Ash Wilson1f110512014-10-02 15:43:47 -040021}
22
23// TenantPage is a single page of Tenant results.
24type TenantPage struct {
25 pagination.LinkedPageBase
26}
27
28// IsEmpty determines whether or not a page of Tenants contains any results.
29func (page TenantPage) IsEmpty() (bool, error) {
30 tenants, err := ExtractTenants(page)
Jon Perritt3c166472016-02-25 03:07:41 -060031 return len(tenants) == 0, err
Ash Wilson1f110512014-10-02 15:43:47 -040032}
33
34// NextPageURL extracts the "next" link from the tenants_links section of the result.
35func (page TenantPage) NextPageURL() (string, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060036 var s struct {
37 Links []gophercloud.Link `json:"tenants_links"`
Ash Wilson1f110512014-10-02 15:43:47 -040038 }
Jon Perritt3c166472016-02-25 03:07:41 -060039 err := page.ExtractInto(&s)
Ash Wilson1f110512014-10-02 15:43:47 -040040 if err != nil {
41 return "", err
42 }
Jon Perritt3c166472016-02-25 03:07:41 -060043 return gophercloud.ExtractNextURL(s.Links)
Ash Wilson1f110512014-10-02 15:43:47 -040044}
45
46// ExtractTenants returns a slice of Tenants contained in a single page of results.
47func ExtractTenants(page pagination.Page) ([]Tenant, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060048 r := page.(TenantPage)
49 var s struct {
50 Tenants []Tenant `json:"tenants"`
Ash Wilson1f110512014-10-02 15:43:47 -040051 }
Jon Perritt3c166472016-02-25 03:07:41 -060052 err := r.ExtractInto(&s)
53 return s.Tenants, err
Ash Wilson1f110512014-10-02 15:43:47 -040054}