Skip to content

Commit

Permalink
feat(database): add database user password update route
Browse files Browse the repository at this point in the history
  • Loading branch information
curzolapierre committed Feb 20, 2024
1 parent 07661a2 commit 6b3af9f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## To Be Released

feat(databases): add databases user update

## 6.7.6

fix(errors): `IsOTPRequired` detects 'OTP Required' API errors
Expand Down
23 changes: 23 additions & 0 deletions databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 6b3af9f

Please sign in to comment.