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