blob: 608f2068915a7d5f622b8266317e62dbbe6427ff [file] [log] [blame]
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01001package roles
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01006)
7
Jamie Hannafordede36712014-10-30 13:43:42 +01008// Role represents an API role resource.
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01009type Role struct {
10 // The unique ID for the role.
11 ID string
12
13 // The human-readable name of the role.
14 Name string
15
16 // The description of the role.
17 Description string
Jamie Hannaford41020d52014-10-30 13:53:31 +010018
19 // The associated service for this role.
20 ServiceID string
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010021}
22
23// RolePage is a single page of a user Role collection.
24type RolePage struct {
25 pagination.SinglePageBase
26}
27
28// IsEmpty determines whether or not a page of Tenants contains any results.
29func (page RolePage) IsEmpty() (bool, error) {
30 users, err := ExtractRoles(page)
Jon Perritt3c166472016-02-25 03:07:41 -060031 return len(users) == 0, err
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010032}
33
34// ExtractRoles returns a slice of roles contained in a single page of results.
35func ExtractRoles(page pagination.Page) ([]Role, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060036 r := page.(RolePage)
37 var s struct {
38 Roles []Role `json:"roles"`
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010039 }
Jon Perritt3c166472016-02-25 03:07:41 -060040 err := r.ExtractInto(&s)
41 return s.Roles, err
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010042}
Jamie Hannaford9b642e02014-10-30 13:20:06 +010043
Jamie Hannafordede36712014-10-30 13:43:42 +010044// UserRoleResult represents the result of either an AddUserRole or
45// a DeleteUserRole operation.
Jamie Hannafordb15878a2014-10-30 13:26:32 +010046type UserRoleResult struct {
Jamie Hannaford9b642e02014-10-30 13:20:06 +010047 gophercloud.ErrResult
48}