blob: c828ff85f93a00e038416bdb7c5b81fc3141903b [file] [log] [blame]
Joe Topjianf61691c2016-11-05 12:34:59 -06001package projects
2
3import (
Joe Topjian1c236d32017-01-09 15:33:32 -07004 "github.com/gophercloud/gophercloud"
Joe Topjianf61691c2016-11-05 12:34:59 -06005 "github.com/gophercloud/gophercloud/pagination"
6)
7
Joe Topjian1c236d32017-01-09 15:33:32 -07008type projectResult struct {
9 gophercloud.Result
10}
11
12// GetResult temporarily contains the response from the Get call.
13type GetResult struct {
14 projectResult
15}
16
Joe Topjian8ad602c2017-01-11 21:01:47 -070017// CreateResult temporarily contains the reponse from the Create call.
18type CreateResult struct {
19 projectResult
20}
21
Joe Topjianf61691c2016-11-05 12:34:59 -060022// Project is a base unit of ownership.
23type Project struct {
24 // IsDomain indicates whether the project is a domain.
25 IsDomain bool `json:"is_domain"`
26
27 // Description is the description of the project.
28 Description string `json:"description"`
29
30 // DomainID is the domain ID the project belongs to.
31 DomainID string `json:"domain_id"`
32
33 // Enabled is whether or not the project is enabled.
34 Enabled bool `json:"enabled"`
35
36 // ID is the unique ID of the project.
37 ID string `json:"id"`
38
39 // Name is the name of the project.
40 Name string `json:"name"`
41
42 // ParentID is the parent_id of the project.
43 ParentID string `json:"parent_id"`
44}
45
46// ProjectPage is a single page of Project results.
47type ProjectPage struct {
48 pagination.LinkedPageBase
49}
50
51// IsEmpty determines whether or not a page of Projects contains any results.
52func (r ProjectPage) IsEmpty() (bool, error) {
53 projects, err := ExtractProjects(r)
54 return len(projects) == 0, err
55}
56
57// NextPageURL extracts the "next" link from the links section of the result.
58func (r ProjectPage) NextPageURL() (string, error) {
59 var s struct {
60 Links struct {
61 Next string `json:"next"`
62 Previous string `json:"previous"`
63 } `json:"links"`
64 }
65 err := r.ExtractInto(&s)
66 if err != nil {
67 return "", err
68 }
69 return s.Links.Next, err
70}
71
72// ExtractProjects returns a slice of Projects contained in a single page of results.
73func ExtractProjects(r pagination.Page) ([]Project, error) {
74 var s struct {
75 Projects []Project `json:"projects"`
76 }
77 err := (r.(ProjectPage)).ExtractInto(&s)
78 return s.Projects, err
79}
Joe Topjian1c236d32017-01-09 15:33:32 -070080
81// Extract interprets any projectResults as a Project.
82func (r projectResult) Extract() (*Project, error) {
83 var s struct {
84 Project *Project `json:"project"`
85 }
86 err := r.ExtractInto(&s)
87 return s.Project, err
88}