Skip to content

Commit

Permalink
Merge pull request #373 from Scalingo/fix/cli/642/database_user_update
Browse files Browse the repository at this point in the history
feat(database): add database user password update route
  • Loading branch information
curzolapierre authored Feb 22, 2024
2 parents 07661a2 + 6e32bbe commit c8f2b1e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
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)
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
2 changes: 1 addition & 1 deletion http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c8f2b1e

Please sign in to comment.