Skip to content

Commit f604dfa

Browse files
fix(mongodb): add the new SetUserRole endpoint on the documentation (#4724)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 45fbdcf commit f604dfa

File tree

5 files changed

+203
-0
lines changed

5 files changed

+203
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Delete an existing user on a Database Instance.
4+
5+
USAGE:
6+
scw mongodb user delete [arg=value ...]
7+
8+
ARGS:
9+
instance-id UUID of the Database Instance the user belongs to
10+
name Name of the database user
11+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)
12+
13+
FLAGS:
14+
-h, --help help for delete
15+
16+
GLOBAL FLAGS:
17+
-c, --config string The path to the config file
18+
-D, --debug Enable debug mode
19+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
20+
-p, --profile string The config profile to use
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Apply preset roles for a user in a Database Instance.
4+
5+
USAGE:
6+
scw mongodb user set-role [arg=value ...]
7+
8+
ARGS:
9+
instance-id UUID of the Database Instance the user belongs to
10+
[user-name] Name of the database user
11+
[roles.{index}.role] Name of the preset role (unknown_role | read | read_write | db_admin | sync)
12+
[roles.{index}.database] Name of the database on which the preset role will be used
13+
[roles.{index}.any-database] Flag to enable the preset role in all databases
14+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)
15+
16+
FLAGS:
17+
-h, --help help for set-role
18+
19+
GLOBAL FLAGS:
20+
-c, --config string The path to the config file
21+
-D, --debug Enable debug mode
22+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
23+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-mongodb-user-usage.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ USAGE:
66
scw mongodb user <command>
77

88
AVAILABLE COMMANDS:
9+
delete Delete a user on a Database Instance
910
list List users of a Database Instance
11+
set-role Apply user roles
1012
update Update a user on a Database Instance
1113

1214
FLAGS:

docs/commands/mongodb.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ This API allows you to manage your Managed Databases for MongoDB®.
2121
- [Restore a Database Instance snapshot](#restore-a-database-instance-snapshot)
2222
- [Update a Database Instance snapshot](#update-a-database-instance-snapshot)
2323
- [User management commands](#user-management-commands)
24+
- [Delete a user on a Database Instance](#delete-a-user-on-a-database-instance)
2425
- [List users of a Database Instance](#list-users-of-a-database-instance)
26+
- [Apply user roles](#apply-user-roles)
2527
- [Update a user on a Database Instance](#update-a-user-on-a-database-instance)
2628
- [MongoDB® version management commands](#mongodb®-version-management-commands)
2729
- [List available MongoDB® versions](#list-available-mongodb®-versions)
@@ -373,6 +375,27 @@ scw mongodb snapshot update <snapshot-id ...> [arg=value ...]
373375
Users are profiles to which you can attribute database-level permissions. They allow you to define permissions specific to each type of database usage.
374376

375377

378+
### Delete a user on a Database Instance
379+
380+
Delete an existing user on a Database Instance.
381+
382+
**Usage:**
383+
384+
```
385+
scw mongodb user delete [arg=value ...]
386+
```
387+
388+
389+
**Args:**
390+
391+
| Name | | Description |
392+
|------|---|-------------|
393+
| instance-id | Required | UUID of the Database Instance the user belongs to |
394+
| name | Required | Name of the database user |
395+
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |
396+
397+
398+
376399
### List users of a Database Instance
377400

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

396419

397420

421+
### Apply user roles
422+
423+
Apply preset roles for a user in a Database Instance.
424+
425+
**Usage:**
426+
427+
```
428+
scw mongodb user set-role [arg=value ...]
429+
```
430+
431+
432+
**Args:**
433+
434+
| Name | | Description |
435+
|------|---|-------------|
436+
| instance-id | Required | UUID of the Database Instance the user belongs to |
437+
| user-name | | Name of the database user |
438+
| roles.{index}.role | One of: `unknown_role`, `read`, `read_write`, `db_admin`, `sync` | Name of the preset role |
439+
| roles.{index}.database | | Name of the database on which the preset role will be used |
440+
| roles.{index}.any-database | | Flag to enable the preset role in all databases |
441+
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |
442+
443+
444+
398445
### Update a user on a Database Instance
399446

400447
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.

internal/namespaces/mongodb/v1alpha1/mongodb_cli.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func GetGeneratedCommands() *core.Commands {
4343
mongodbSnapshotDelete(),
4444
mongodbUserList(),
4545
mongodbUserUpdate(),
46+
mongodbUserDelete(),
47+
mongodbUserSetRole(),
4648
)
4749
}
4850

@@ -935,3 +937,112 @@ func mongodbUserUpdate() *core.Command {
935937
},
936938
}
937939
}
940+
941+
func mongodbUserDelete() *core.Command {
942+
return &core.Command{
943+
Short: `Delete a user on a Database Instance`,
944+
Long: `Delete an existing user on a Database Instance.`,
945+
Namespace: "mongodb",
946+
Resource: "user",
947+
Verb: "delete",
948+
// Deprecated: false,
949+
ArgsType: reflect.TypeOf(mongodb.DeleteUserRequest{}),
950+
ArgSpecs: core.ArgSpecs{
951+
{
952+
Name: "instance-id",
953+
Short: `UUID of the Database Instance the user belongs to`,
954+
Required: true,
955+
Deprecated: false,
956+
Positional: false,
957+
},
958+
{
959+
Name: "name",
960+
Short: `Name of the database user`,
961+
Required: true,
962+
Deprecated: false,
963+
Positional: false,
964+
},
965+
core.RegionArgSpec(scw.RegionFrPar),
966+
},
967+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
968+
request := args.(*mongodb.DeleteUserRequest)
969+
970+
client := core.ExtractClient(ctx)
971+
api := mongodb.NewAPI(client)
972+
e = api.DeleteUser(request)
973+
if e != nil {
974+
return nil, e
975+
}
976+
977+
return &core.SuccessResult{
978+
Resource: "user",
979+
Verb: "delete",
980+
}, nil
981+
},
982+
}
983+
}
984+
985+
func mongodbUserSetRole() *core.Command {
986+
return &core.Command{
987+
Short: `Apply user roles`,
988+
Long: `Apply preset roles for a user in a Database Instance.`,
989+
Namespace: "mongodb",
990+
Resource: "user",
991+
Verb: "set-role",
992+
// Deprecated: false,
993+
ArgsType: reflect.TypeOf(mongodb.SetUserRoleRequest{}),
994+
ArgSpecs: core.ArgSpecs{
995+
{
996+
Name: "instance-id",
997+
Short: `UUID of the Database Instance the user belongs to`,
998+
Required: true,
999+
Deprecated: false,
1000+
Positional: false,
1001+
},
1002+
{
1003+
Name: "user-name",
1004+
Short: `Name of the database user`,
1005+
Required: false,
1006+
Deprecated: false,
1007+
Positional: false,
1008+
},
1009+
{
1010+
Name: "roles.{index}.role",
1011+
Short: `Name of the preset role`,
1012+
Required: false,
1013+
Deprecated: false,
1014+
Positional: false,
1015+
EnumValues: []string{
1016+
"unknown_role",
1017+
"read",
1018+
"read_write",
1019+
"db_admin",
1020+
"sync",
1021+
},
1022+
},
1023+
{
1024+
Name: "roles.{index}.database",
1025+
Short: `Name of the database on which the preset role will be used`,
1026+
Required: false,
1027+
Deprecated: false,
1028+
Positional: false,
1029+
},
1030+
{
1031+
Name: "roles.{index}.any-database",
1032+
Short: `Flag to enable the preset role in all databases`,
1033+
Required: false,
1034+
Deprecated: false,
1035+
Positional: false,
1036+
},
1037+
core.RegionArgSpec(scw.RegionFrPar),
1038+
},
1039+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1040+
request := args.(*mongodb.SetUserRoleRequest)
1041+
1042+
client := core.ExtractClient(ctx)
1043+
api := mongodb.NewAPI(client)
1044+
1045+
return api.SetUserRole(request)
1046+
},
1047+
}
1048+
}

0 commit comments

Comments
 (0)