Skip to content

fix(mongodb): add the new SetUserRole endpoint on the documentation #4724

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

Merged
merged 5 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Delete an existing user on a Database Instance.

USAGE:
scw mongodb user delete [arg=value ...]

ARGS:
instance-id UUID of the Database Instance the user belongs to
name Name of the database user
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for delete

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Apply preset roles for a user in a Database Instance.

USAGE:
scw mongodb user set-role [arg=value ...]

ARGS:
instance-id UUID of the Database Instance the user belongs to
[user-name] Name of the database user
[roles.{index}.role] Name of the preset role (unknown_role | read | read_write | db_admin | sync)
[roles.{index}.database] Name of the database on which the preset role will be used
[roles.{index}.any-database] Flag to enable the preset role in all databases
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for set-role

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
2 changes: 2 additions & 0 deletions cmd/scw/testdata/test-all-usage-mongodb-user-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ USAGE:
scw mongodb user <command>

AVAILABLE COMMANDS:
delete Delete a user on a Database Instance
list List users of a Database Instance
set-role Apply user roles
update Update a user on a Database Instance

FLAGS:
Expand Down
47 changes: 47 additions & 0 deletions docs/commands/mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ This API allows you to manage your Managed Databases for MongoDB®.
- [Restore a Database Instance snapshot](#restore-a-database-instance-snapshot)
- [Update a Database Instance snapshot](#update-a-database-instance-snapshot)
- [User management commands](#user-management-commands)
- [Delete a user on a Database Instance](#delete-a-user-on-a-database-instance)
- [List users of a Database Instance](#list-users-of-a-database-instance)
- [Apply user roles](#apply-user-roles)
- [Update a user on a Database Instance](#update-a-user-on-a-database-instance)
- [MongoDB® version management commands](#mongodb®-version-management-commands)
- [List available MongoDB® versions](#list-available-mongodb®-versions)
Expand Down Expand Up @@ -373,6 +375,27 @@ scw mongodb snapshot update <snapshot-id ...> [arg=value ...]
Users are profiles to which you can attribute database-level permissions. They allow you to define permissions specific to each type of database usage.


### Delete a user on a Database Instance

Delete an existing user on a Database Instance.

**Usage:**

```
scw mongodb user delete [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| instance-id | Required | UUID of the Database Instance the user belongs to |
| name | Required | Name of the database user |
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |



### List users of a Database Instance

List all users of a given Database Instance.
Expand All @@ -395,6 +418,30 @@ scw mongodb user list [arg=value ...]



### Apply user roles

Apply preset roles for a user in a Database Instance.

**Usage:**

```
scw mongodb user set-role [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| instance-id | Required | UUID of the Database Instance the user belongs to |
| user-name | | Name of the database user |
| roles.{index}.role | One of: `unknown_role`, `read`, `read_write`, `db_admin`, `sync` | Name of the preset role |
| roles.{index}.database | | Name of the database on which the preset role will be used |
| roles.{index}.any-database | | Flag to enable the preset role in all databases |
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |



### Update a user on a Database Instance

Update the parameters of a user on a Database Instance. You can update the `password` parameter, but you cannot change the name of the user.
Expand Down
111 changes: 111 additions & 0 deletions internal/namespaces/mongodb/v1alpha1/mongodb_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func GetGeneratedCommands() *core.Commands {
mongodbSnapshotDelete(),
mongodbUserList(),
mongodbUserUpdate(),
mongodbUserDelete(),
mongodbUserSetRole(),
)
}

Expand Down Expand Up @@ -935,3 +937,112 @@ func mongodbUserUpdate() *core.Command {
},
}
}

func mongodbUserDelete() *core.Command {
return &core.Command{
Short: `Delete a user on a Database Instance`,
Long: `Delete an existing user on a Database Instance.`,
Namespace: "mongodb",
Resource: "user",
Verb: "delete",
// Deprecated: false,
ArgsType: reflect.TypeOf(mongodb.DeleteUserRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "instance-id",
Short: `UUID of the Database Instance the user belongs to`,
Required: true,
Deprecated: false,
Positional: false,
},
{
Name: "name",
Short: `Name of the database user`,
Required: true,
Deprecated: false,
Positional: false,
},
core.RegionArgSpec(scw.RegionFrPar),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*mongodb.DeleteUserRequest)

client := core.ExtractClient(ctx)
api := mongodb.NewAPI(client)
e = api.DeleteUser(request)
if e != nil {
return nil, e
}

return &core.SuccessResult{
Resource: "user",
Verb: "delete",
}, nil
},
}
}

func mongodbUserSetRole() *core.Command {
return &core.Command{
Short: `Apply user roles`,
Long: `Apply preset roles for a user in a Database Instance.`,
Namespace: "mongodb",
Resource: "user",
Verb: "set-role",
// Deprecated: false,
ArgsType: reflect.TypeOf(mongodb.SetUserRoleRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "instance-id",
Short: `UUID of the Database Instance the user belongs to`,
Required: true,
Deprecated: false,
Positional: false,
},
{
Name: "user-name",
Short: `Name of the database user`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "roles.{index}.role",
Short: `Name of the preset role`,
Required: false,
Deprecated: false,
Positional: false,
EnumValues: []string{
"unknown_role",
"read",
"read_write",
"db_admin",
"sync",
},
},
{
Name: "roles.{index}.database",
Short: `Name of the database on which the preset role will be used`,
Required: false,
Deprecated: false,
Positional: false,
},
{
Name: "roles.{index}.any-database",
Short: `Flag to enable the preset role in all databases`,
Required: false,
Deprecated: false,
Positional: false,
},
core.RegionArgSpec(scw.RegionFrPar),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*mongodb.SetUserRoleRequest)

client := core.ExtractClient(ctx)
api := mongodb.NewAPI(client)

return api.SetUserRole(request)
},
}
}
Loading