github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/identity/v3/users/results.go (about)

     1  package users
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/opentelekomcloud/gophertelekomcloud"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     9  )
    10  
    11  // User represents a User in the OpenStack Identity Service.
    12  type User struct {
    13  	// DefaultProjectID is the ID of the default project of the user.
    14  	DefaultProjectID string `json:"default_project_id"`
    15  
    16  	// Description is a description of the user.
    17  	Description string `json:"description"`
    18  
    19  	// DomainID is the domain ID the user belongs to.
    20  	DomainID string `json:"domain_id"`
    21  
    22  	// Enabled is whether the user is enabled.
    23  	Enabled bool `json:"enabled"`
    24  
    25  	// ID is the unique ID of the user.
    26  	ID string `json:"id"`
    27  
    28  	// Links contains referencing links to the user.
    29  	Links map[string]interface{} `json:"links"`
    30  
    31  	// Name is the name of the user.
    32  	Name string `json:"name"`
    33  
    34  	// PasswordExpiresAt is the timestamp when the user's password expires.
    35  	PasswordExpiresAt time.Time `json:"-"`
    36  
    37  	// Email is the email of the user
    38  	Email string `json:"email,omitempty"`
    39  
    40  	// AreaCode is country code
    41  	AreaCode string `json:"areacode,omitempty"`
    42  
    43  	// Phone is mobile number, which can contain a maximum of 32 digits.
    44  	// The mobile number must be used together with a country code.
    45  	Phone string `json:"phone,omitempty"`
    46  
    47  	// Whether password reset is required at first login
    48  	PwdResetRequired bool `json:"pwd_status,omitempty"`
    49  
    50  	// XUserType is Type of the IAM user in the external system.
    51  	XUserType string `json:"xuser_type,omitempty"`
    52  
    53  	// XUserID is ID of the IAM user in the external system.
    54  	XUserID string `json:"xuser_id,omitempty"`
    55  }
    56  
    57  func (r *User) UnmarshalJSON(b []byte) error {
    58  	type tmp User
    59  	var s struct {
    60  		tmp
    61  		PasswordExpiresAt golangsdk.JSONRFC3339MilliNoZ `json:"password_expires_at"`
    62  	}
    63  	err := json.Unmarshal(b, &s)
    64  	if err != nil {
    65  		return err
    66  	}
    67  	*r = User(s.tmp)
    68  
    69  	r.PasswordExpiresAt = time.Time(s.PasswordExpiresAt)
    70  
    71  	return err
    72  }
    73  
    74  type userResult struct {
    75  	golangsdk.Result
    76  }
    77  
    78  // GetResult is the response from a Get operation. Call its Extract method
    79  // to interpret it as a User.
    80  type GetResult struct {
    81  	userResult
    82  }
    83  
    84  // CreateResult is the response from a Create operation. Call its Extract method
    85  // to interpret it as a User.
    86  type CreateResult struct {
    87  	userResult
    88  }
    89  
    90  // UpdateResult is the response from an Update operation. Call its Extract
    91  // method to interpret it as a User.
    92  type UpdateResult struct {
    93  	userResult
    94  }
    95  
    96  // UpdateExtendedResult is the response from an UpdateExtended operation. Call its Extract
    97  // method to interpret it as a User.
    98  type UpdateExtendedResult struct {
    99  	userResult
   100  }
   101  
   102  // DeleteResult is the response from a Delete operation. Call its ExtractErr to
   103  // determine if the request succeeded or failed.
   104  type DeleteResult struct {
   105  	golangsdk.ErrResult
   106  }
   107  
   108  // UserPage is a single page of User results.
   109  type UserPage struct {
   110  	pagination.LinkedPageBase
   111  }
   112  
   113  // IsEmpty determines whether a UserPage contains any results.
   114  func (r UserPage) IsEmpty() (bool, error) {
   115  	users, err := ExtractUsers(r)
   116  	return len(users) == 0, err
   117  }
   118  
   119  // NextPageURL extracts the "next" link from the links section of the result.
   120  func (r UserPage) NextPageURL() (string, error) {
   121  	var s struct {
   122  		Links struct {
   123  			Next     string `json:"next"`
   124  			Previous string `json:"previous"`
   125  		} `json:"links"`
   126  	}
   127  	err := r.ExtractInto(&s)
   128  	if err != nil {
   129  		return "", err
   130  	}
   131  	return s.Links.Next, err
   132  }
   133  
   134  // ExtractUsers returns a slice of Users contained in a single page of results.
   135  func ExtractUsers(r pagination.Page) ([]User, error) {
   136  	var s []User
   137  	err := (r.(UserPage)).ExtractIntoSlicePtr(&s, "users")
   138  	if err != nil {
   139  		return nil, err
   140  	}
   141  	return s, nil
   142  }
   143  
   144  // Extract interprets any user results as a User.
   145  func (r userResult) Extract() (*User, error) {
   146  	s := new(User)
   147  	err := r.ExtractIntoStructPtr(s, "user")
   148  	if err != nil {
   149  		return nil, err
   150  	}
   151  	return s, nil
   152  }
   153  
   154  type AddMembershipResult struct {
   155  	golangsdk.ErrResult
   156  }
   157  
   158  type WelcomeResult struct {
   159  	golangsdk.ErrResult
   160  }