github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/users/results.go (about) 1 package users 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/huaweicloud/golangsdk" 8 "github.com/huaweicloud/golangsdk/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 or not 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 38 func (r *User) UnmarshalJSON(b []byte) error { 39 type tmp User 40 var s struct { 41 tmp 42 PasswordExpiresAt golangsdk.JSONRFC3339MilliNoZ `json:"password_expires_at"` 43 } 44 err := json.Unmarshal(b, &s) 45 if err != nil { 46 return err 47 } 48 *r = User(s.tmp) 49 50 r.PasswordExpiresAt = time.Time(s.PasswordExpiresAt) 51 52 return err 53 } 54 55 type userResult struct { 56 golangsdk.Result 57 } 58 59 // GetResult is the response from a Get operation. Call its Extract method 60 // to interpret it as a User. 61 type GetResult struct { 62 userResult 63 } 64 65 // CreateResult is the response from a Create operation. Call its Extract method 66 // to interpret it as a User. 67 type CreateResult struct { 68 userResult 69 } 70 71 // UpdateResult is the response from an Update operation. Call its Extract 72 // method to interpret it as a User. 73 type UpdateResult struct { 74 userResult 75 } 76 77 // DeleteResult is the response from a Delete operation. Call its ExtractErr to 78 // determine if the request succeeded or failed. 79 type DeleteResult struct { 80 golangsdk.ErrResult 81 } 82 83 // UserPage is a single page of User results. 84 type UserPage struct { 85 pagination.LinkedPageBase 86 } 87 88 // IsEmpty determines whether or not a UserPage contains any results. 89 func (r UserPage) IsEmpty() (bool, error) { 90 users, err := ExtractUsers(r) 91 return len(users) == 0, err 92 } 93 94 // NextPageURL extracts the "next" link from the links section of the result. 95 func (r UserPage) NextPageURL() (string, error) { 96 var s struct { 97 Links struct { 98 Next string `json:"next"` 99 Previous string `json:"previous"` 100 } `json:"links"` 101 } 102 err := r.ExtractInto(&s) 103 if err != nil { 104 return "", err 105 } 106 return s.Links.Next, err 107 } 108 109 // ExtractUsers returns a slice of Users contained in a single page of results. 110 func ExtractUsers(r pagination.Page) ([]User, error) { 111 var s struct { 112 Users []User `json:"users"` 113 } 114 err := (r.(UserPage)).ExtractInto(&s) 115 return s.Users, err 116 } 117 118 // Extract interprets any user results as a User. 119 func (r userResult) Extract() (*User, error) { 120 var s struct { 121 User *User `json:"user"` 122 } 123 err := r.ExtractInto(&s) 124 return s.User, err 125 } 126 127 type AddMembershipResult struct { 128 golangsdk.ErrResult 129 }