diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d0cf55..dce80f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,15 @@ ## To Be Released +* feat(databases): add databases user update + ## 6.7.6 -fix(errors): `IsOTPRequired` detects 'OTP Required' API errors +* fix(errors): `IsOTPRequired` detects 'OTP Required' API errors ## 6.7.5 -fix(events): `link_scm` data types +* fix(events): `link_scm` data types ## 6.7.4 diff --git a/databases.go b/databases.go index 992ebfb..a151f10 100644 --- a/databases.go +++ b/databases.go @@ -277,6 +277,29 @@ func (c *Client) DatabaseCreateUser(ctx context.Context, app, addonID string, us return res.DatabaseUser, nil } +type DatabaseUpdateUserParam struct { + DatabaseID string `json:"database_id"` + Password string `json:"password,omitempty"` + PasswordConfirmation string `json:"password_confirmation,omitempty"` +} + +type databaseUpdateUserPayload struct { + DatabaseUser DatabaseUpdateUserParam `json:"database_user"` +} + +// DatabaseUpdateUser updates a user to the given database addon +func (c *Client) DatabaseUpdateUser(ctx context.Context, app, addonID, username string, databaseUserParams DatabaseUpdateUserParam) (DatabaseUser, error) { + res := DatabaseUserResponse{} + payload := databaseUpdateUserPayload{ + DatabaseUser: databaseUserParams, + } + err := c.DBAPI(app, addonID).SubresourceUpdate(ctx, "databases", addonID, "users", username, payload, &res) + if err != nil { + return res.DatabaseUser, errors.Wrapf(ctx, err, "update a user on database %s", addonID) + } + return res.DatabaseUser, nil +} + // DatabaseUsersResponse is the response body of database list users type DatabaseUsersResponse struct { DatabaseUsers []DatabaseUser `json:"database-users"` diff --git a/http/client.go b/http/client.go index 646c172..9790d6f 100644 --- a/http/client.go +++ b/http/client.go @@ -24,7 +24,7 @@ type Client interface { SubresourceList(ctx context.Context, resource, resourceID, subresource string, payload, data interface{}) error SubresourceAdd(ctx context.Context, resource, resourceID, subresource string, payload, data interface{}) error SubresourceGet(ctx context.Context, resource, resourceID, subresource, id string, payload, data interface{}) error - SubresourceUpdate(rctx context.Context, esource, resourceID, subresource, id string, payload, data interface{}) error + SubresourceUpdate(ctx context.Context, resource, resourceID, subresource, id string, payload, data interface{}) error SubresourceDelete(ctx context.Context, resource, resourceID, subresource, id string) error DoRequest(ctx context.Context, req *APIRequest, data interface{}) error Do(context.Context, *APIRequest) (*http.Response, error)