Add reset user auth routes to db service
This commit is contained in:
parent
38ed6ff2ed
commit
3bea0c6884
21
databases.go
21
databases.go
|
@ -17,6 +17,7 @@ const (
|
||||||
databaseBackupsPath = databaseBasePath + "/%s/backups"
|
databaseBackupsPath = databaseBasePath + "/%s/backups"
|
||||||
databaseUsersPath = databaseBasePath + "/%s/users"
|
databaseUsersPath = databaseBasePath + "/%s/users"
|
||||||
databaseUserPath = databaseBasePath + "/%s/users/%s"
|
databaseUserPath = databaseBasePath + "/%s/users/%s"
|
||||||
|
databaseResetUserAuthPath = databaseUserPath + "/reset_auth"
|
||||||
databaseDBPath = databaseBasePath + "/%s/dbs/%s"
|
databaseDBPath = databaseBasePath + "/%s/dbs/%s"
|
||||||
databaseDBsPath = databaseBasePath + "/%s/dbs"
|
databaseDBsPath = databaseBasePath + "/%s/dbs"
|
||||||
databasePoolPath = databaseBasePath + "/%s/pools/%s"
|
databasePoolPath = databaseBasePath + "/%s/pools/%s"
|
||||||
|
@ -100,6 +101,7 @@ type DatabasesService interface {
|
||||||
ListUsers(context.Context, string, *ListOptions) ([]DatabaseUser, *Response, error)
|
ListUsers(context.Context, string, *ListOptions) ([]DatabaseUser, *Response, error)
|
||||||
CreateUser(context.Context, string, *DatabaseCreateUserRequest) (*DatabaseUser, *Response, error)
|
CreateUser(context.Context, string, *DatabaseCreateUserRequest) (*DatabaseUser, *Response, error)
|
||||||
DeleteUser(context.Context, string, string) (*Response, error)
|
DeleteUser(context.Context, string, string) (*Response, error)
|
||||||
|
ResetUserAuth(context.Context, string, string, *DatabaseResetUserAuthRequest) (*DatabaseUser, *Response, error)
|
||||||
ListDBs(context.Context, string, *ListOptions) ([]DatabaseDB, *Response, error)
|
ListDBs(context.Context, string, *ListOptions) ([]DatabaseDB, *Response, error)
|
||||||
CreateDB(context.Context, string, *DatabaseCreateDBRequest) (*DatabaseDB, *Response, error)
|
CreateDB(context.Context, string, *DatabaseCreateDBRequest) (*DatabaseDB, *Response, error)
|
||||||
GetDB(context.Context, string, string) (*DatabaseDB, *Response, error)
|
GetDB(context.Context, string, string) (*DatabaseDB, *Response, error)
|
||||||
|
@ -267,6 +269,11 @@ type DatabaseCreateUserRequest struct {
|
||||||
MySQLSettings *DatabaseMySQLUserSettings `json:"mysql_settings,omitempty"`
|
MySQLSettings *DatabaseMySQLUserSettings `json:"mysql_settings,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DatabaseResetUserAuth request is used to reset a users DB auth
|
||||||
|
type DatabaseResetUserAuthRequest struct {
|
||||||
|
MySQLSettings *DatabaseMySQLUserSettings `json:"mysql_settings,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// DatabaseCreateDBRequest is used to create a new engine-specific database within the cluster
|
// DatabaseCreateDBRequest is used to create a new engine-specific database within the cluster
|
||||||
type DatabaseCreateDBRequest struct {
|
type DatabaseCreateDBRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -530,6 +537,20 @@ func (svc *DatabasesServiceOp) CreateUser(ctx context.Context, databaseID string
|
||||||
return root.User, resp, nil
|
return root.User, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc *DatabasesServiceOp) ResetUserAuth(ctx context.Context, databaseID, userID string, resetAuth *DatabaseResetUserAuthRequest) (*DatabaseUser, *Response, error) {
|
||||||
|
path := fmt.Sprintf(databaseResetUserAuthPath, databaseID, userID)
|
||||||
|
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, resetAuth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
root := new(databaseUserRoot)
|
||||||
|
resp, err := svc.client.Do(ctx, req, root)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
return root.User, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteUser will delete an existing database user
|
// DeleteUser will delete an existing database user
|
||||||
func (svc *DatabasesServiceOp) DeleteUser(ctx context.Context, databaseID, userID string) (*Response, error) {
|
func (svc *DatabasesServiceOp) DeleteUser(ctx context.Context, databaseID, userID string) (*Response, error) {
|
||||||
path := fmt.Sprintf(databaseUserPath, databaseID, userID)
|
path := fmt.Sprintf(databaseUserPath, databaseID, userID)
|
||||||
|
|
|
@ -533,6 +533,45 @@ func TestDatabases_DeleteUser(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDatabases_ResetUserAuth(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
dbID := "deadbeef-dead-4aa5-beef-deadbeef347d"
|
||||||
|
path := fmt.Sprintf("/v2/databases/%s/users/user/reset_auth", dbID)
|
||||||
|
|
||||||
|
body := `
|
||||||
|
{
|
||||||
|
"user": {
|
||||||
|
"name": "name",
|
||||||
|
"role": "foo",
|
||||||
|
"password": "pass",
|
||||||
|
"mysql_settings": {
|
||||||
|
"auth_plugin": "caching_sha2_password"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
testMethod(t, r, http.MethodPost)
|
||||||
|
fmt.Fprint(w, body)
|
||||||
|
})
|
||||||
|
|
||||||
|
want := &DatabaseUser{
|
||||||
|
Name: "name",
|
||||||
|
Role: "foo",
|
||||||
|
Password: "pass",
|
||||||
|
MySQLSettings: &DatabaseMySQLUserSettings{AuthPlugin: SQLAuthPluginCachingSHA2},
|
||||||
|
}
|
||||||
|
|
||||||
|
got, _, err := client.Databases.ResetUserAuth(ctx, dbID, "user", &DatabaseResetUserAuthRequest{
|
||||||
|
MySQLSettings: &DatabaseMySQLUserSettings{
|
||||||
|
AuthPlugin: SQLAuthPluginCachingSHA2,
|
||||||
|
}})
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, want, got)
|
||||||
|
}
|
||||||
|
|
||||||
func TestDatabases_ListDBs(t *testing.T) {
|
func TestDatabases_ListDBs(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
Loading…
Reference in New Issue