Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(database): add database user password update route #373

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: "databases" and "users" shouldn't be constants?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, but IMO I prefer to see what is the route by seeing the string "databases".

But indeed it leaves room for potential manual errors.

However I think we should make this consistent with all other packages too.
It should be a dedicated issue I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you are right it should be a dedicated issue.
Can you create one for that please 🙏

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here: #375

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! ❤️

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"`
Expand Down