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

     1  package policies
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  type Role struct {
     9  	ID          string `json:"id"`
    10  	Name        string `json:"display_name"`
    11  	Catalog     string `json:"catalog"`
    12  	Description string `json:"description"`
    13  	Type        string `json:"type"`
    14  	Policy      Policy `json:"policy" required:"true"`
    15  	DomainId    string `json:"domain_id"`
    16  	References  int    `json:"references"`
    17  }
    18  
    19  type roleResult struct {
    20  	golangsdk.Result
    21  }
    22  
    23  // GetResult is the response from a Get operation. Call its Extract method
    24  // to interpret it as a Role.
    25  type GetResult struct {
    26  	roleResult
    27  }
    28  
    29  // CreateResult is the response from a Create operation. Call its Extract method
    30  // to interpret it as a Role
    31  type CreateResult struct {
    32  	roleResult
    33  }
    34  
    35  // UpdateResult is the response from an Update operation. Call its Extract
    36  // method to interpret it as a Role.
    37  type UpdateResult struct {
    38  	roleResult
    39  }
    40  
    41  // DeleteResult is the response from a Delete operation. Call its ExtractErr to
    42  // determine if the request succeeded or failed.
    43  type DeleteResult struct {
    44  	golangsdk.ErrResult
    45  }
    46  
    47  type RolePage struct {
    48  	pagination.LinkedPageBase
    49  }
    50  
    51  // Extract interprets any roleResults as a Role.
    52  func (r roleResult) Extract() (*Role, error) {
    53  	var s struct {
    54  		Role *Role `json:"role"`
    55  	}
    56  	err := r.ExtractInto(&s)
    57  	return s.Role, err
    58  }
    59  
    60  func (r RolePage) IsEmpty() (bool, error) {
    61  	is, err := ExtractPageRoles(r)
    62  	return len(is) == 0, err
    63  }
    64  
    65  func (r RolePage) NextPageURL() (string, error) {
    66  	var s struct {
    67  		Links struct {
    68  			Next     string `json:"next"`
    69  			Previous string `json:"previous"`
    70  		} `json:"links"`
    71  	}
    72  	err := r.ExtractInto(&s)
    73  	if err != nil {
    74  		return "", err
    75  	}
    76  	return s.Links.Next, err
    77  }
    78  
    79  func ExtractPageRoles(r pagination.Page) ([]Role, error) {
    80  	var s struct {
    81  		Roles []Role `json:"roles"`
    82  	}
    83  	err := (r.(RolePage)).ExtractInto(&s)
    84  	return s.Roles, err
    85  }