dsl struct tags; wip
diff --git a/openstack/db/v1/users/requests.go b/openstack/db/v1/users/requests.go
index 6815c1c..910a615 100644
--- a/openstack/db/v1/users/requests.go
+++ b/openstack/db/v1/users/requests.go
@@ -14,71 +14,35 @@
// CreateOpts is the struct responsible for configuring a new user; often in the
// context of an instance.
type CreateOpts struct {
- // [REQUIRED] Specifies a name for the user. Valid names can be composed
+ // Specifies a name for the user. Valid names can be composed
// of the following characters: letters (either case); numbers; these
// characters '@', '?', '#', ' ' but NEVER beginning a name string; '_' is
// permitted anywhere. Prohibited characters that are forbidden include:
// single quotes, double quotes, back quotes, semicolons, commas, backslashes,
// and forward slashes. Spaces at the front or end of a user name are also
// not permitted.
- Name string
-
- // [REQUIRED] Specifies a password for the user.
- Password string
-
- // [OPTIONAL] An array of databases that this user will connect to. The
+ Name string `json:"name" required:"true"`
+ // Specifies a password for the user.
+ Password string `json:"password" required:"true"`
+ // An array of databases that this user will connect to. The
// "name" field is the only requirement for each option.
- Databases db.BatchCreateOpts
-
- // [OPTIONAL] Specifies the host from which a user is allowed to connect to
+ Databases db.BatchCreateOpts `json:"databases,omitempty"`
+ // 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
+ Host string `json:"host,omitempty"`
}
// ToMap is a convenience function for creating sub-maps for individual users.
func (opts CreateOpts) ToMap() (map[string]interface{}, error) {
-
if opts.Name == "root" {
err := gophercloud.ErrInvalidInput{}
- err.Function = "users.ToUserCreateMap"
err.Argument = "users.CreateOpts.Name"
err.Value = "root"
err.Info = "root is a reserved user name and cannot be used"
return nil, err
}
- if opts.Name == "" {
- err := gophercloud.ErrMissingInput{}
- err.Function = "users.ToUserCreateMap"
- err.Argument = "users.CreateOpts.Name"
- return nil, err
- }
- if opts.Password == "" {
- err := gophercloud.ErrMissingInput{}
- err.Function = "users.ToUserCreateMap"
- err.Argument = "users.CreateOpts.Password"
- return nil, err
- }
-
- user := map[string]interface{}{
- "name": opts.Name,
- "password": opts.Password,
- }
-
- if opts.Host != "" {
- user["host"] = opts.Host
- }
-
- dbs := make([]map[string]string, len(opts.Databases))
- for i, db := range opts.Databases {
- dbs[i] = map[string]string{"name": db.Name}
- }
-
- if len(dbs) > 0 {
- user["databases"] = dbs
- }
-
- return user, nil
+ return gophercloud.BuildRequestBody(opts, "")
}
// BatchCreateOpts allows multiple users to be created at once.
@@ -102,40 +66,28 @@
// assigned for a particular user, the user will be granted all privileges
// for those specified databases. "root" is a reserved name and cannot be used.
func Create(client *gophercloud.ServiceClient, instanceID string, opts CreateOptsBuilder) CreateResult {
- var res CreateResult
-
- reqBody, err := opts.ToUserCreateMap()
+ var r CreateResult
+ b, err := opts.ToUserCreateMap()
if err != nil {
- res.Err = err
- return res
+ r.Err = err
+ return r
}
-
- _, res.Err = client.Request("POST", baseURL(client, instanceID), &gophercloud.RequestOpts{
- JSONBody: &reqBody,
- OkCodes: []int{202},
- })
-
- return res
+ _, r.Err = client.Post(baseURL(client, instanceID), &b, nil, nil)
+ return r
}
// List will list all the users associated with a specified database instance,
// along with their associated databases. This operation will not return any
// system users or administrators for a database.
func List(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
- createPageFn := func(r pagination.PageResult) pagination.Page {
+ return pagination.NewPager(client, baseURL(client, instanceID), func(r pagination.PageResult) pagination.Page {
return UserPage{pagination.LinkedPageBase{PageResult: r}}
- }
-
- return pagination.NewPager(client, baseURL(client, instanceID), createPageFn)
+ })
}
// Delete will permanently delete a user from a specified database instance.
func Delete(client *gophercloud.ServiceClient, instanceID, userName string) DeleteResult {
- var res DeleteResult
-
- _, res.Err = client.Request("DELETE", userURL(client, instanceID, userName), &gophercloud.RequestOpts{
- OkCodes: []int{202},
- })
-
- return res
+ var r DeleteResult
+ _, r.Err = client.Delete(userURL(client, instanceID, userName), nil)
+ return r
}