blob: 28de6bb410820aa130abc93232ee0a9c3127da55 [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.
Jon Perritt31b66462016-02-25 22:25:30 -060029func (r RolePage) IsEmpty() (bool, error) {
30 users, err := ExtractRoles(r)
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.
Jon Perritt31b66462016-02-25 22:25:30 -060035func ExtractRoles(r pagination.Page) ([]Role, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060036 var s struct {
37 Roles []Role `json:"roles"`
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010038 }
Jon Perritt31b66462016-02-25 22:25:30 -060039 err := (r.(RolePage)).ExtractInto(&s)
Jon Perritt3c166472016-02-25 03:07:41 -060040 return s.Roles, err
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010041}
Jamie Hannaford9b642e02014-10-30 13:20:06 +010042
Jamie Hannafordede36712014-10-30 13:43:42 +010043// UserRoleResult represents the result of either an AddUserRole or
44// a DeleteUserRole operation.
Jamie Hannafordb15878a2014-10-30 13:26:32 +010045type UserRoleResult struct {
Jamie Hannaford9b642e02014-10-30 13:20:06 +010046 gophercloud.ErrResult
47}