Jamie Hannaford | 6e4d795 | 2014-10-29 16:18:29 +0100 | [diff] [blame] | 1 | package users |
| 2 | |
| 3 | import ( |
| 4 | os "github.com/rackspace/gophercloud/openstack/identity/v2/users" |
| 5 | |
| 6 | "github.com/mitchellh/mapstructure" |
| 7 | ) |
| 8 | |
| 9 | // User represents a user resource that exists on the API. |
| 10 | type User struct { |
| 11 | // The UUID for this user. |
| 12 | ID string |
| 13 | |
| 14 | // The human name for this user. |
| 15 | Name string |
| 16 | |
| 17 | // The username for this user. |
| 18 | Username string |
| 19 | |
| 20 | // Indicates whether the user is enabled (true) or disabled (false). |
| 21 | Enabled bool |
| 22 | |
| 23 | // The email address for this user. |
| 24 | Email string |
| 25 | |
| 26 | // The ID of the tenant to which this user belongs. |
| 27 | TenantID string `mapstructure:"tenant_id"` |
| 28 | |
| 29 | // Specifies the default region for the user account. This value is inherited |
| 30 | // from the user administrator when the account is created. |
| 31 | DefaultRegion string `mapstructure:"RAX-AUTH:defaultRegion"` |
| 32 | |
| 33 | // Identifies the domain that contains the user account. This value is |
| 34 | // inherited from the user administrator when the account is created. |
| 35 | DomainID string `mapstructure:"RAX-AUTH:domainId"` |
| 36 | |
| 37 | // The password value that the user needs for authentication. If the Add user |
| 38 | // request included a password value, this attribute is not included in the |
| 39 | // response. |
| 40 | Password string `mapstructure:"OS-KSADM:password"` |
| 41 | |
| 42 | // Indicates whether the user has enabled multi-factor authentication. |
| 43 | MultiFactorEnabled string `mapstructure:"RAX-AUTH:multiFactorEnabled"` |
| 44 | } |
| 45 | |
| 46 | // CreateResult represents the result of a Create operation |
| 47 | type CreateResult struct { |
| 48 | os.CreateResult |
| 49 | } |
| 50 | |
| 51 | // GetResult represents the result of a Get operation |
| 52 | type GetResult struct { |
| 53 | os.GetResult |
| 54 | } |
| 55 | |
| 56 | // UpdateResult represents the result of an Update operation |
| 57 | type UpdateResult struct { |
| 58 | os.UpdateResult |
| 59 | } |
| 60 | |
| 61 | func commonExtract(resp interface{}, err error) (*User, error) { |
| 62 | if err != nil { |
| 63 | return nil, err |
| 64 | } |
| 65 | |
| 66 | var respStruct struct { |
| 67 | User *User `json:"user"` |
| 68 | } |
| 69 | |
| 70 | err = mapstructure.Decode(resp, &respStruct) |
| 71 | |
| 72 | return respStruct.User, err |
| 73 | } |
| 74 | |
| 75 | // Extract will get the Snapshot object out of the GetResult object. |
| 76 | func (r GetResult) Extract() (*User, error) { |
| 77 | return commonExtract(r.Body, r.Err) |
| 78 | } |
| 79 | |
| 80 | // Extract will get the Snapshot object out of the CreateResult object. |
| 81 | func (r CreateResult) Extract() (*User, error) { |
| 82 | return commonExtract(r.Body, r.Err) |
| 83 | } |
| 84 | |
| 85 | // Extract will get the Snapshot object out of the UpdateResult object. |
| 86 | func (r UpdateResult) Extract() (*User, error) { |
| 87 | return commonExtract(r.Body, r.Err) |
| 88 | } |