blob: db27d3c599a1fd54e536d162a1aa5797301eaa9a [file] [log] [blame]
Jamie Hannaford2a130242014-10-28 11:19:46 +01001package users
Jamie Hannaford929bd002014-10-29 11:14:25 +01002
3import (
4 "github.com/mitchellh/mapstructure"
5 "github.com/rackspace/gophercloud/pagination"
6)
7
8// User represents a user resource that exists on the API.
9type User struct {
10 // The UUID for this user.
11 ID string
12
13 // The human name for this user.
14 Name string
15
16 // The username for this user.
17 Username string
18
19 // Indicates whether the user is enabled (true) or disabled (false).
20 Enabled bool
21
22 // The email address for this user.
23 Email string
24
25 // The ID of the tenant to which this user belongs.
26 TenantID string `mapstructure:"tenant_id"`
27}
28
29// UserPage is a single page of a User collection.
30type UserPage struct {
31 pagination.SinglePageBase
32}
33
34// IsEmpty determines whether or not a page of Tenants contains any results.
35func (page UserPage) IsEmpty() (bool, error) {
36 users, err := ExtractUsers(page)
37 if err != nil {
38 return false, err
39 }
40 return len(users) == 0, nil
41}
42
43// ExtractUsers returns a slice of Tenants contained in a single page of results.
44func ExtractUsers(page pagination.Page) ([]User, error) {
45 casted := page.(UserPage).Body
46 var response struct {
47 Users []User `mapstructure:"users"`
48 }
49
50 err := mapstructure.Decode(casted, &response)
51 return response.Users, err
52}