blob: f526cf9ffc162553d574cfdb4a804ccbb93d4b16 [file] [log] [blame]
Jamie Hannaford984e9172015-02-13 14:34:03 +01001package users
2
3import (
Jamie Hannaford984e9172015-02-13 14:34:03 +01004 "github.com/rackspace/gophercloud"
5 db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
6 os "github.com/rackspace/gophercloud/openstack/db/v1/users"
7 "github.com/rackspace/gophercloud/pagination"
8)
9
10func ChangePassword(client *gophercloud.ServiceClient, instanceID string, opts os.BatchCreateOpts) UpdatePasswordsResult {
11 var res UpdatePasswordsResult
12
13 reqBody, err := opts.ToUserCreateMap()
14 if err != nil {
15 res.Err = err
16 return res
17 }
18
Jamie Hannaforda50d1352015-02-18 11:38:38 +010019 _, res.Err = client.Request("PUT", baseURL(client, instanceID), gophercloud.RequestOpts{
20 JSONBody: &reqBody,
21 OkCodes: []int{202},
Jamie Hannaford984e9172015-02-13 14:34:03 +010022 })
23
24 return res
25}
26
27func Update(client *gophercloud.ServiceClient, instanceID, userName string, opts os.CreateOpts) UpdateResult {
28 var res UpdateResult
29
30 reqBody, err := opts.ToMap()
31 if err != nil {
32 res.Err = err
33 return res
34 }
35 reqBody = map[string]interface{}{"user": reqBody}
36
Jamie Hannaforda50d1352015-02-18 11:38:38 +010037 _, res.Err = client.Request("PUT", userURL(client, instanceID, userName), gophercloud.RequestOpts{
38 JSONBody: &reqBody,
39 OkCodes: []int{202},
Jamie Hannaford984e9172015-02-13 14:34:03 +010040 })
41
42 return res
43}
44
45func Get(client *gophercloud.ServiceClient, instanceID, userName string) GetResult {
46 var res GetResult
47
Jamie Hannaforda50d1352015-02-18 11:38:38 +010048 _, res.Err = client.Request("GET", userURL(client, instanceID, userName), gophercloud.RequestOpts{
49 JSONResponse: &res.Body,
50 OkCodes: []int{200},
Jamie Hannaford984e9172015-02-13 14:34:03 +010051 })
52
53 return res
54}
55
56func ListAccess(client *gophercloud.ServiceClient, instanceID, userName string) pagination.Pager {
57 pageFn := func(r pagination.PageResult) pagination.Page {
58 return AccessPage{pagination.LinkedPageBase{PageResult: r}}
59 }
60
61 return pagination.NewPager(client, dbsURL(client, instanceID, userName), pageFn)
62}
63
64func GrantAccess(client *gophercloud.ServiceClient, instanceID, userName string, opts db.BatchCreateOpts) GrantAccessResult {
65 var res GrantAccessResult
66
67 reqBody, err := opts.ToDBCreateMap()
68 if err != nil {
69 res.Err = err
70 return res
71 }
72
Jamie Hannaforda50d1352015-02-18 11:38:38 +010073 _, res.Err = client.Request("PUT", dbsURL(client, instanceID, userName), gophercloud.RequestOpts{
74 JSONBody: &reqBody,
75 OkCodes: []int{202},
Jamie Hannaford984e9172015-02-13 14:34:03 +010076 })
77
78 return res
79}
80
81func RevokeAccess(client *gophercloud.ServiceClient, instanceID, userName, dbName string) RevokeAccessResult {
82 var res RevokeAccessResult
83
Jamie Hannaforda50d1352015-02-18 11:38:38 +010084 _, res.Err = client.Request("DELETE", dbURL(client, instanceID, userName, dbName), gophercloud.RequestOpts{
85 OkCodes: []int{202},
Jamie Hannaford984e9172015-02-13 14:34:03 +010086 })
87
88 return res
89}