Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / github.com / gophercloud / gophercloud / openstack / identity / v2 / tenants / results.go
1 package tenants
2
3 import (
4         "github.com/gophercloud/gophercloud"
5         "github.com/gophercloud/gophercloud/pagination"
6 )
7
8 // Tenant is a grouping of users in the identity service.
9 type Tenant struct {
10         // ID is a unique identifier for this tenant.
11         ID string `json:"id"`
12
13         // Name is a friendlier user-facing name for this tenant.
14         Name string `json:"name"`
15
16         // Description is a human-readable explanation of this Tenant's purpose.
17         Description string `json:"description"`
18
19         // Enabled indicates whether or not a tenant is active.
20         Enabled bool `json:"enabled"`
21 }
22
23 // TenantPage is a single page of Tenant results.
24 type TenantPage struct {
25         pagination.LinkedPageBase
26 }
27
28 // IsEmpty determines whether or not a page of Tenants contains any results.
29 func (r TenantPage) IsEmpty() (bool, error) {
30         tenants, err := ExtractTenants(r)
31         return len(tenants) == 0, err
32 }
33
34 // NextPageURL extracts the "next" link from the tenants_links section of the result.
35 func (r TenantPage) NextPageURL() (string, error) {
36         var s struct {
37                 Links []gophercloud.Link `json:"tenants_links"`
38         }
39         err := r.ExtractInto(&s)
40         if err != nil {
41                 return "", err
42         }
43         return gophercloud.ExtractNextURL(s.Links)
44 }
45
46 // ExtractTenants returns a slice of Tenants contained in a single page of
47 // results.
48 func ExtractTenants(r pagination.Page) ([]Tenant, error) {
49         var s struct {
50                 Tenants []Tenant `json:"tenants"`
51         }
52         err := (r.(TenantPage)).ExtractInto(&s)
53         return s.Tenants, err
54 }
55
56 type tenantResult struct {
57         gophercloud.Result
58 }
59
60 // Extract interprets any tenantResults as a Tenant.
61 func (r tenantResult) Extract() (*Tenant, error) {
62         var s struct {
63                 Tenant *Tenant `json:"tenant"`
64         }
65         err := r.ExtractInto(&s)
66         return s.Tenant, err
67 }
68
69 // GetResult is the response from a Get request. Call its Extract method to
70 // interpret it as a Tenant.
71 type GetResult struct {
72         tenantResult
73 }
74
75 // CreateResult is the response from a Create request. Call its Extract method
76 // to interpret it as a Tenant.
77 type CreateResult struct {
78         tenantResult
79 }
80
81 // DeleteResult is the response from a Get request. Call its ExtractErr method
82 // to determine if the call succeeded or failed.
83 type DeleteResult struct {
84         gophercloud.ErrResult
85 }
86
87 // UpdateResult is the response from a Update request. Call its Extract method
88 // to interpret it as a Tenant.
89 type UpdateResult struct {
90         tenantResult
91 }