Skip to content

Commit

Permalink
Add UpdateUser endpoint for Databases (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinshenker authored Dec 1, 2023
1 parent e3fe224 commit cbd1bc6
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
2 changes: 2 additions & 0 deletions specification/DigitalOcean-public.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ paths:
$ref: 'resources/databases/databases_get_user.yml'
delete:
$ref: 'resources/databases/databases_delete_user.yml'
put:
$ref: 'resources/databases/databases_update_user.yml'

/v2/databases/{database_cluster_uuid}/users/{username}/reset_auth:
post:
Expand Down
75 changes: 75 additions & 0 deletions specification/resources/databases/databases_update_user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
operationId: databases_update_user

summary: Update a Database User

description: |
To update an existing database user, send a PUT request to `/v2/databases/$DATABASE_ID/users/$USERNAME`
with the desired settings.
**Note**: only `settings` can be updated via this type of request. If you wish to change the name of a user,
you must recreate a new user.
The response will be a JSON object with a key called `user`. The value of this will be an
object that contains the name of the update database user, along with the `settings` object that
has been updated.
tags:
- Databases

parameters:
- $ref: 'parameters.yml#/database_cluster_uuid'
- $ref: 'parameters.yml#/username'

requestBody:
required: true
content:
application/json:
schema:
allOf:
- type: object
properties:
settings:
$ref: './models/user_settings.yml'
required:
- settings
examples:
Update User Kafka ACLs:
value:
settings:
acl:
- id: acl128aaaa99239
permission: produceconsume
topic: customer-events
- id: acl293098flskdf
permission: produce
topic: customer-events.*
- id: acl128ajei20123
permission: consume
topic: customer-events

responses:
'201':
$ref: 'responses/user.yml'

'401':
$ref: '../../shared/responses/unauthorized.yml'

'404':
$ref: '../../shared/responses/not_found.yml'

'429':
$ref: '../../shared/responses/too_many_requests.yml'

'500':
$ref: '../../shared/responses/server_error.yml'

default:
$ref: '../../shared/responses/unexpected_error.yml'

x-codeSamples:
- $ref: 'examples/curl/databases_update_user.yml'
- $ref: 'examples/go/databases_update_user.yml'

security:
- bearer_auth:
- 'write'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lang: cURL
source: |-
curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d '{"settings": {"acl": [{"topic": "events", "permission": "produce"}]}}' \
"https://api.digitalocean.com/v2/databases/9cc10173-e9ea-4176-9dbc-a4cee4c4ff30/users"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
lang: Go
source: |-
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
userName := "test-user"
updateUserRequest := &godo.DatabaseUpdateUserRequest{
Settings: {
ACL: [
{
Permssion: "consume",
Topic: "events",
}
{
Permission: "produce",
Topic: "metrics",
}
]
}
}
user, _, err := client.Databases.UpdateUser(ctx, "88055188-9e54-4f21-ab11-8a918ed79ee2", userName, updateUserRequest)
}
2 changes: 1 addition & 1 deletion specification/resources/databases/models/user_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ properties:
properties:
id:
type: string
description: An identifier for the ACL.
description: An identifier for the ACL. Will be computed after the ACL is created/updated.
example: "aaa"
topic:
type: string
Expand Down

0 comments on commit cbd1bc6

Please sign in to comment.