github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dli/v1/databases/requests.go (about) 1 package databases 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/openstack/common/tags" 6 ) 7 8 // CreateOpts is a structure which allows to create a new database using given parameters. 9 type CreateOpts struct { 10 // Name of the created database. 11 // NOTE: The default database is a built-in database. You cannot create a database named default. 12 Name string `json:"database_name" required:"true"` 13 // Information about the created database. 14 Description string `json:"description,omitempty"` 15 // Enterprise project ID. The value 0 indicates the default enterprise project. 16 // NOTE: Users who have enabled Enterprise Management can set this parameter to bind a specified project. 17 EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` 18 // Database tag. 19 Tags []tags.ResourceTag `json:"tags,omitempty"` 20 } 21 22 // Create is a method to create a new database by CreateOpts. 23 func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*RequestResp, error) { 24 b, err := golangsdk.BuildRequestBody(opts, "") 25 if err != nil { 26 return nil, err 27 } 28 29 var rst golangsdk.Result 30 _, err = c.Post(rootURL(c), b, &rst.Body, nil) 31 if err == nil { 32 var r RequestResp 33 rst.ExtractInto(&r) 34 return &r, nil 35 } 36 return nil, err 37 } 38 39 // ListOpts is a structure which allows to obtain databases using given parameters. 40 type ListOpts struct { 41 // Specifies whether to display the permission information. The value can be true or false. 42 // The default value is false. 43 IsDesplay bool `q:"with-priv"` 44 // The value should be no less than 0. The default value is 0. 45 Offset int `q:"offset"` 46 // Number of returned data records. The value must be greater than or equal to 0. 47 // By default, all data records are returned. 48 Limit int `q:"limit"` 49 // Database name filtering keyword. Fuzzy match is used to obtain all databases whose names contain the keyword. 50 Keyword string `q:"keyword"` 51 // Database tag. The format is key=value, for example: 52 // GET /v1.0/{project_id}/databases?offset=0&limit=10&with-priv=true&tags=foo%3Dbar 53 // In the preceding information, = needs to be escaped to %3D, foo indicates the tag key, and bar indicates the tag 54 // value. 55 Tags string `q:"tags"` 56 } 57 58 // List is a method to obtain a list of databases by ListOpts. 59 func List(c *golangsdk.ServiceClient, opts ListOpts) (*ListResp, error) { 60 url := rootURL(c) 61 query, err := golangsdk.BuildQueryString(opts) 62 if err != nil { 63 return nil, err 64 } 65 url += query.String() 66 67 var rst golangsdk.Result 68 _, err = c.Get(url, &rst.Body, nil) 69 if err == nil { 70 var r ListResp 71 rst.ExtractInto(&r) 72 return &r, nil 73 } 74 return nil, err 75 } 76 77 // UpdateDBOwnerOpts is a structure which allows to update database owner using given name. 78 type UpdateDBOwnerOpts struct { 79 // Name of the new owner. The new user must be a sub-user of the current tenant. 80 NewOwner string `json:"new_owner" required:"true"` 81 } 82 83 // UpdateDBOwner is a method to update database owner by UpdateDBOwnerOpts. 84 func UpdateDBOwner(c *golangsdk.ServiceClient, dbName string, opts UpdateDBOwnerOpts) (*RequestResp, error) { 85 b, err := golangsdk.BuildRequestBody(opts, "") 86 if err != nil { 87 return nil, err 88 } 89 90 var rst golangsdk.Result 91 _, err = c.Put(userURL(c, dbName), b, &rst.Body, nil) 92 if err == nil { 93 var r RequestResp 94 rst.ExtractInto(&r) 95 return &r, nil 96 } 97 return nil, err 98 } 99 100 // Delete is a method to remove the exist database by database name. 101 func Delete(c *golangsdk.ServiceClient, dbName string) *golangsdk.ErrResult { 102 var r golangsdk.ErrResult 103 _, r.Err = c.Delete(resourceURL(c, dbName), nil) 104 return &r 105 }