blob: a441e7f0f113354de6390392a1509abd35b4c8d4 [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 Topjiand131fb82017-01-11 21:41:44 -070022// DeleteResult temporarily contains the response from the Delete call.
23type DeleteResult struct {
24 gophercloud.ErrResult
25}
26
Joe Topjian8baf47a2017-01-11 21:50:24 -070027// UpdateResult temporarily contains the response from the Update call.
28type UpdateResult struct {
29 projectResult
30}
31
Joe Topjianf61691c2016-11-05 12:34:59 -060032// Project is a base unit of ownership.
33type Project struct {
34 // IsDomain indicates whether the project is a domain.
35 IsDomain bool `json:"is_domain"`
36
37 // Description is the description of the project.
38 Description string `json:"description"`
39
40 // DomainID is the domain ID the project belongs to.
41 DomainID string `json:"domain_id"`
42
43 // Enabled is whether or not the project is enabled.
44 Enabled bool `json:"enabled"`
45
46 // ID is the unique ID of the project.
47 ID string `json:"id"`
48
49 // Name is the name of the project.
50 Name string `json:"name"`
51
52 // ParentID is the parent_id of the project.
53 ParentID string `json:"parent_id"`
54}
55
56// ProjectPage is a single page of Project results.
57type ProjectPage struct {
58 pagination.LinkedPageBase
59}
60
61// IsEmpty determines whether or not a page of Projects contains any results.
62func (r ProjectPage) IsEmpty() (bool, error) {
63 projects, err := ExtractProjects(r)
64 return len(projects) == 0, err
65}
66
67// NextPageURL extracts the "next" link from the links section of the result.
68func (r ProjectPage) NextPageURL() (string, error) {
69 var s struct {
70 Links struct {
71 Next string `json:"next"`
72 Previous string `json:"previous"`
73 } `json:"links"`
74 }
75 err := r.ExtractInto(&s)
76 if err != nil {
77 return "", err
78 }
79 return s.Links.Next, err
80}
81
82// ExtractProjects returns a slice of Projects contained in a single page of results.
83func ExtractProjects(r pagination.Page) ([]Project, error) {
84 var s struct {
85 Projects []Project `json:"projects"`
86 }
87 err := (r.(ProjectPage)).ExtractInto(&s)
88 return s.Projects, err
89}
Joe Topjian1c236d32017-01-09 15:33:32 -070090
91// Extract interprets any projectResults as a Project.
92func (r projectResult) Extract() (*Project, error) {
93 var s struct {
94 Project *Project `json:"project"`
95 }
96 err := r.ExtractInto(&s)
97 return s.Project, err
98}