blob: 68fd05cf69308f4c9eec9b54c940a74f48c82b8d [file] [log] [blame]
Jamie Hannafordaf4570f2015-02-12 13:33:25 +01001package users
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02005 db "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/db/v1/databases"
6 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
Jamie Hannafordaf4570f2015-02-12 13:33:25 +01007)
8
9// User represents a database user
10type User struct {
11 // The user name
12 Name string
13
14 // The user password
15 Password string
16
17 // The databases associated with this user
18 Databases []db.Database
19}
20
Jamie Hannaford9793d942015-02-18 15:13:20 +010021// CreateResult represents the result of a create operation.
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010022type CreateResult struct {
23 gophercloud.ErrResult
24}
25
Jamie Hannaford9793d942015-02-18 15:13:20 +010026// DeleteResult represents the result of a delete operation.
27type DeleteResult struct {
28 gophercloud.ErrResult
29}
30
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010031// UserPage represents a single page of a paginated user collection.
32type UserPage struct {
33 pagination.LinkedPageBase
34}
35
36// IsEmpty checks to see whether the collection is empty.
37func (page UserPage) IsEmpty() (bool, error) {
38 users, err := ExtractUsers(page)
Jon Perritt12395212016-02-24 10:41:17 -060039 return len(users) == 0, err
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010040}
41
42// NextPageURL will retrieve the next page URL.
43func (page UserPage) NextPageURL() (string, error) {
Jon Perritt12395212016-02-24 10:41:17 -060044 var s struct {
45 Links []gophercloud.Link `json:"users_links"`
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010046 }
Jon Perritt12395212016-02-24 10:41:17 -060047 err := page.ExtractInto(&s)
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010048 if err != nil {
49 return "", err
50 }
Jon Perritt12395212016-02-24 10:41:17 -060051 return gophercloud.ExtractNextURL(s.Links)
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010052}
53
54// ExtractUsers will convert a generic pagination struct into a more
55// relevant slice of User structs.
Jon Perritt31b66462016-02-25 22:25:30 -060056func ExtractUsers(r pagination.Page) ([]User, error) {
Jon Perritt12395212016-02-24 10:41:17 -060057 var s struct {
58 Users []User `json:"users"`
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010059 }
Jon Perritt31b66462016-02-25 22:25:30 -060060 err := (r.(UserPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060061 return s.Users, err
Jamie Hannafordaf4570f2015-02-12 13:33:25 +010062}