blob: 3ce1e677367fa377818bf1ca5a243b85aa2c495d [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.
Jon Perritt31b66462016-02-25 22:25:30 -060029func (r TenantPage) IsEmpty() (bool, error) {
30 tenants, err := ExtractTenants(r)
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.
Jon Perritt31b66462016-02-25 22:25:30 -060035func (r 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 Perritt31b66462016-02-25 22:25:30 -060039 err := r.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.
Jon Perritt31b66462016-02-25 22:25:30 -060047func ExtractTenants(r pagination.Page) ([]Tenant, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060048 var s struct {
49 Tenants []Tenant `json:"tenants"`
Ash Wilson1f110512014-10-02 15:43:47 -040050 }
Jon Perritt31b66462016-02-25 22:25:30 -060051 err := (r.(TenantPage)).ExtractInto(&s)
Jon Perritt3c166472016-02-25 03:07:41 -060052 return s.Tenants, err
Ash Wilson1f110512014-10-02 15:43:47 -040053}