From 6b3af9f04d8c2d9287c1839044c7fbaad078f5fe Mon Sep 17 00:00:00 2001 From: CURZOLA Pierre Date: Fri, 9 Feb 2024 18:17:02 +0100 Subject: [PATCH] feat(database): add database user password update route --- CHANGELOG.md | 2 ++ databases.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d0cf55..1c4391c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## To Be Released +feat(databases): add databases user update + ## 6.7.6 fix(errors): `IsOTPRequired` detects 'OTP Required' API errors diff --git a/databases.go b/databases.go index 992ebfb..998e346 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 an user to the given database addon +func (c *Client) DatabaseUpdateUser(ctx context.Context, app, addonID, username string, user DatabaseUpdateUserParam) (DatabaseUser, error) { + res := DatabaseUserResponse{} + payload := databaseUpdateUserPayload{ + DatabaseUser: user, + } + err := c.DBAPI(app, addonID).SubresourceUpdate(ctx, "databases", addonID, "users", username, payload, &res) + if err != nil { + return res.DatabaseUser, errors.Wrapf(ctx, err, "create 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"`