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

     1  package users
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // User represents a user resource that exists on the API.
     9  type User struct {
    10  	// ID is the UUID for this user.
    11  	ID string
    12  
    13  	// Name is the human name for this user.
    14  	Name string
    15  
    16  	// Username is the username for this user.
    17  	Username string
    18  
    19  	// Enabled indicates whether the user is enabled (true) or disabled (false).
    20  	Enabled bool
    21  
    22  	// Email is the email address for this user.
    23  	Email string
    24  
    25  	// TenantID is the ID of the tenant to which this user belongs.
    26  	TenantID string `json:"tenant_id"`
    27  }
    28  
    29  // Role assigns specific responsibilities to users, allowing them to accomplish
    30  // certain API operations whilst scoped to a service.
    31  type Role struct {
    32  	// ID is the UUID of the role.
    33  	ID string
    34  
    35  	// Name is the name of the role.
    36  	Name string
    37  }
    38  
    39  // UserPage is a single page of a User collection.
    40  type UserPage struct {
    41  	pagination.SinglePageBase
    42  }
    43  
    44  // RolePage is a single page of a user Role collection.
    45  type RolePage struct {
    46  	pagination.SinglePageBase
    47  }
    48  
    49  // IsEmpty determines whether or not a page of Users contains any results.
    50  func (r UserPage) IsEmpty() (bool, error) {
    51  	users, err := ExtractUsers(r)
    52  	return len(users) == 0, err
    53  }
    54  
    55  // ExtractUsers returns a slice of Users contained in a single page of results.
    56  func ExtractUsers(r pagination.Page) ([]User, error) {
    57  	var s struct {
    58  		Users []User `json:"users"`
    59  	}
    60  	err := (r.(UserPage)).ExtractInto(&s)
    61  	return s.Users, err
    62  }
    63  
    64  // IsEmpty determines whether or not a page of Roles contains any results.
    65  func (r RolePage) IsEmpty() (bool, error) {
    66  	users, err := ExtractRoles(r)
    67  	return len(users) == 0, err
    68  }
    69  
    70  // ExtractRoles returns a slice of Roles contained in a single page of results.
    71  func ExtractRoles(r pagination.Page) ([]Role, error) {
    72  	var s struct {
    73  		Roles []Role `json:"roles"`
    74  	}
    75  	err := (r.(RolePage)).ExtractInto(&s)
    76  	return s.Roles, err
    77  }
    78  
    79  type commonResult struct {
    80  	golangsdk.Result
    81  }
    82  
    83  // Extract interprets any commonResult as a User, if possible.
    84  func (r commonResult) Extract() (*User, error) {
    85  	var s struct {
    86  		User *User `json:"user"`
    87  	}
    88  	err := r.ExtractInto(&s)
    89  	return s.User, err
    90  }
    91  
    92  // CreateResult represents the result of a Create operation. Call its Extract
    93  // method to interpret the result as a User.
    94  type CreateResult struct {
    95  	commonResult
    96  }
    97  
    98  // GetResult represents the result of a Get operation. Call its Extract method
    99  // to interpret the result as a User.
   100  type GetResult struct {
   101  	commonResult
   102  }
   103  
   104  // UpdateResult represents the result of an Update operation. Call its Extract
   105  // method to interpret the result as a User.
   106  type UpdateResult struct {
   107  	commonResult
   108  }
   109  
   110  // DeleteResult represents the result of a Delete operation. Call its
   111  // ExtractErr method to determine if the request succeeded or failed.
   112  type DeleteResult struct {
   113  	commonResult
   114  }