Extract out user functionality into its own namespace
diff --git a/openstack/db/v1/instances/fixtures.go b/openstack/db/v1/instances/fixtures.go
index 66448a7..0dda158 100644
--- a/openstack/db/v1/instances/fixtures.go
+++ b/openstack/db/v1/instances/fixtures.go
@@ -159,7 +159,6 @@
th.Mux.HandleFunc("/instances/"+id+"/root", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
-
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{"user":{"name":"root","password":"secretsecret"}}`)
})
@@ -169,7 +168,6 @@
th.Mux.HandleFunc("/instances/"+id+"/root", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
-
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{"rootEnabled":true}`)
})
diff --git a/openstack/db/v1/instances/requests.go b/openstack/db/v1/instances/requests.go
index fd9eea7..ecf8d46 100644
--- a/openstack/db/v1/instances/requests.go
+++ b/openstack/db/v1/instances/requests.go
@@ -6,6 +6,7 @@
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
+ users "github.com/rackspace/gophercloud/openstack/db/v1/databases"
"github.com/rackspace/gophercloud/pagination"
)
@@ -14,63 +15,6 @@
ToInstanceCreateMap() (map[string]interface{}, error)
}
-// UserOpts is the struct responsible for configuring a user; often in the
-// context of an instance.
-type UserOpts struct {
- // Specifies a name for the user.
- Name string
-
- // Specifies a password for the user.
- Password string
-
- // An array of databases that this user will connect to. The `name` field is
- // the only requirement for each option.
- Databases db.BatchCreateOpts
-
- // Specifies the host from which a user is allowed to connect to the database.
- // Possible values are a string containing an IPv4 address or "%" to allow
- // connecting from any host. Optional; the default is "%".
- Host string
-}
-
-func (opts UserOpts) ToMap() (map[string]interface{}, error) {
- user := map[string]interface{}{}
-
- if opts.Name != "" {
- user["name"] = opts.Name
- }
- if opts.Password != "" {
- user["password"] = opts.Password
- }
- if opts.Host != "" {
- user["host"] = opts.Host
- }
-
- var dbs []map[string]string
- for _, db := range opts.Databases {
- dbs = append(dbs, map[string]string{"name": db.Name})
- }
- if len(dbs) > 0 {
- user["databases"] = dbs
- }
-
- return user, nil
-}
-
-type UsersOpts []UserOpts
-
-func (opts UsersOpts) ToMap() ([]map[string]interface{}, error) {
- var users []map[string]interface{}
- for _, opt := range opts {
- user, err := opt.ToMap()
- if err != nil {
- return users, err
- }
- users = append(users, user)
- }
- return users, nil
-}
-
// CreateOpts is the struct responsible for configuring a new database instance.
type CreateOpts struct {
// Either the integer UUID (in string form) of the flavor, or its URI
@@ -89,7 +33,7 @@
Databases db.BatchCreateOpts
// A slice of user information options.
- Users UsersOpts
+ Users users.BatchCreateOpts
}
func (opts CreateOpts) ToInstanceCreateMap() (map[string]interface{}, error) {
@@ -116,11 +60,11 @@
instance["databases"] = dbs["databases"]
}
if len(opts.Users) > 0 {
- users, err := opts.Users.ToMap()
+ users, err := opts.Users.ToUserCreateMap()
if err != nil {
return nil, err
}
- instance["users"] = users
+ instance["users"] = users["users"]
}
return map[string]interface{}{"instance": instance}, nil
diff --git a/openstack/db/v1/instances/results.go b/openstack/db/v1/instances/results.go
index f211868..fa2d64e 100644
--- a/openstack/db/v1/instances/results.go
+++ b/openstack/db/v1/instances/results.go
@@ -3,6 +3,7 @@
import (
"github.com/mitchellh/mapstructure"
"github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/openstack/db/v1/users"
"github.com/rackspace/gophercloud/pagination"
)
@@ -56,15 +57,6 @@
Volume Volume
}
-// User represents a database user
-type User struct {
- // The user name
- Name string
-
- // The user password
- Password string
-}
-
type commonResult struct {
gophercloud.Result
}
@@ -154,7 +146,7 @@
}
var response struct {
- User User `mapstructure:"user"`
+ User users.User `mapstructure:"user"`
}
err := mapstructure.Decode(r.Body, &response)