github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/projects/results.go (about)

     1  package projects
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  type projectResult struct {
     9  	golangsdk.Result
    10  }
    11  
    12  // GetResult is the result of a Get request. Call its Extract method to
    13  // interpret it as a Project.
    14  type GetResult struct {
    15  	projectResult
    16  }
    17  
    18  // CreateResult is the result of a Create request. Call its Extract method to
    19  // interpret it as a Project.
    20  type CreateResult struct {
    21  	projectResult
    22  }
    23  
    24  // DeleteResult is the result of a Delete request. Call its ExtractErr method to
    25  // determine if the request succeeded or failed.
    26  type DeleteResult struct {
    27  	golangsdk.ErrResult
    28  }
    29  
    30  // UpdateResult is the result of an Update request. Call its Extract method to
    31  // interpret it as a Project.
    32  type UpdateResult struct {
    33  	projectResult
    34  }
    35  
    36  // Project represents an OpenStack Identity Project.
    37  type Project struct {
    38  	// IsDomain indicates whether the project is a domain.
    39  	IsDomain bool `json:"is_domain"`
    40  
    41  	// Description is the description of the project.
    42  	Description string `json:"description"`
    43  
    44  	// DomainID is the domain ID the project belongs to.
    45  	DomainID string `json:"domain_id"`
    46  
    47  	// Enabled is whether or not the project is enabled.
    48  	Enabled bool `json:"enabled"`
    49  
    50  	// ID is the unique ID of the project.
    51  	ID string `json:"id"`
    52  
    53  	// Name is the name of the project.
    54  	Name string `json:"name"`
    55  
    56  	// ParentID is the parent_id of the project.
    57  	ParentID string `json:"parent_id"`
    58  }
    59  
    60  // ProjectPage is a single page of Project results.
    61  type ProjectPage struct {
    62  	pagination.LinkedPageBase
    63  }
    64  
    65  // IsEmpty determines whether or not a page of Projects contains any results.
    66  func (r ProjectPage) IsEmpty() (bool, error) {
    67  	projects, err := ExtractProjects(r)
    68  	return len(projects) == 0, err
    69  }
    70  
    71  // NextPageURL extracts the "next" link from the links section of the result.
    72  func (r ProjectPage) NextPageURL() (string, error) {
    73  	var s struct {
    74  		Links struct {
    75  			Next     string `json:"next"`
    76  			Previous string `json:"previous"`
    77  		} `json:"links"`
    78  	}
    79  	err := r.ExtractInto(&s)
    80  	if err != nil {
    81  		return "", err
    82  	}
    83  	return s.Links.Next, err
    84  }
    85  
    86  // ExtractProjects returns a slice of Projects contained in a single page of
    87  // results.
    88  func ExtractProjects(r pagination.Page) ([]Project, error) {
    89  	var s struct {
    90  		Projects []Project `json:"projects"`
    91  	}
    92  	err := (r.(ProjectPage)).ExtractInto(&s)
    93  	return s.Projects, err
    94  }
    95  
    96  // Extract interprets any projectResults as a Project.
    97  func (r projectResult) Extract() (*Project, error) {
    98  	var s struct {
    99  		Project *Project `json:"project"`
   100  	}
   101  	err := r.ExtractInto(&s)
   102  	return s.Project, err
   103  }