Skip to content

Commit 9863042

Browse files
feat(mongodb): add support for endpoint management (#4739)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 1e9d4d8 commit 9863042

7 files changed

+248
-3
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+
Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request.
4+
5+
USAGE:
6+
scw mongodb endpoint create <instance-id ...> [arg=value ...]
7+
8+
ARGS:
9+
instance-id UUID of the Database Instance
10+
[endpoint.private-network.private-network-id] UUID of the Private Network
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 create
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Delete the endpoint of a Database Instance. You must specify the `endpoint_id` parameter of the endpoint you want to delete. Note that you might need to update any environment configurations that point to the deleted endpoint.
4+
5+
USAGE:
6+
scw mongodb endpoint delete <endpoint-id ...> [arg=value ...]
7+
8+
ARGS:
9+
endpoint-id UUID of the Endpoint to delete
10+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)
11+
12+
FLAGS:
13+
-h, --help help for delete
14+
15+
GLOBAL FLAGS:
16+
-c, --config string The path to the config file
17+
-D, --debug Enable debug mode
18+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
19+
-p, --profile string The config profile to use

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
Instance endpoints enable connection to your instance.
44

55
USAGE:
6-
scw mongodb endpoint
6+
scw mongodb endpoint <command>
7+
8+
AVAILABLE COMMANDS:
9+
create Create a new Instance endpoint
10+
delete Delete a Database Instance endpoint
711

812
FLAGS:
913
-h, --help help for endpoint
@@ -13,3 +17,5 @@ GLOBAL FLAGS:
1317
-D, --debug Enable debug mode
1418
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
1519
-p, --profile string The config profile to use
20+
21+
Use "scw mongodb endpoint [command] --help" for more information about a command.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request.
4+
5+
USAGE:
6+
scw mongodb user create [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+
[password] Password of the database user
12+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)
13+
14+
FLAGS:
15+
-h, --help help for create
16+
17+
GLOBAL FLAGS:
18+
-c, --config string The path to the config file
19+
-D, --debug Enable debug mode
20+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
21+
-p, --profile string The config profile to use

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

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

88
AVAILABLE COMMANDS:
9+
create Create an user on a Database Instance
910
delete Delete a user on a Database Instance
1011
list List users of a Database Instance
1112
set-role Apply user roles

docs/commands/mongodb.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
This API allows you to manage your Managed Databases for MongoDB®.
44

55
- [Endpoint management commands](#endpoint-management-commands)
6+
- [Create a new Instance endpoint](#create-a-new-instance-endpoint)
7+
- [Delete a Database Instance endpoint](#delete-a-database-instance-endpoint)
68
- [Instance management commands](#instance-management-commands)
79
- [Create a MongoDB® Database Instance](#create-a-mongodb®-database-instance)
810
- [Delete a MongoDB® Database Instance](#delete-a-mongodb®-database-instance)
@@ -21,6 +23,7 @@ This API allows you to manage your Managed Databases for MongoDB®.
2123
- [Restore a Database Instance snapshot](#restore-a-database-instance-snapshot)
2224
- [Update a Database Instance snapshot](#update-a-database-instance-snapshot)
2325
- [User management commands](#user-management-commands)
26+
- [Create an user on a Database Instance](#create-an-user-on-a-database-instance)
2427
- [Delete a user on a Database Instance](#delete-a-user-on-a-database-instance)
2528
- [List users of a Database Instance](#list-users-of-a-database-instance)
2629
- [Apply user roles](#apply-user-roles)
@@ -33,15 +36,47 @@ This API allows you to manage your Managed Databases for MongoDB®.
3336

3437
Instance endpoints enable connection to your instance.
3538

36-
Instance endpoints enable connection to your instance.
39+
40+
### Create a new Instance endpoint
41+
42+
Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request.
3743

3844
**Usage:**
3945

4046
```
41-
scw mongodb endpoint
47+
scw mongodb endpoint create <instance-id ...> [arg=value ...]
4248
```
4349

4450

51+
**Args:**
52+
53+
| Name | | Description |
54+
|------|---|-------------|
55+
| instance-id | Required | UUID of the Database Instance |
56+
| endpoint.private-network.private-network-id | | UUID of the Private Network |
57+
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |
58+
59+
60+
61+
### Delete a Database Instance endpoint
62+
63+
Delete the endpoint of a Database Instance. You must specify the `endpoint_id` parameter of the endpoint you want to delete. Note that you might need to update any environment configurations that point to the deleted endpoint.
64+
65+
**Usage:**
66+
67+
```
68+
scw mongodb endpoint delete <endpoint-id ...> [arg=value ...]
69+
```
70+
71+
72+
**Args:**
73+
74+
| Name | | Description |
75+
|------|---|-------------|
76+
| endpoint-id | Required | UUID of the Endpoint to delete |
77+
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |
78+
79+
4580

4681
## Instance management commands
4782

@@ -375,6 +410,28 @@ scw mongodb snapshot update <snapshot-id ...> [arg=value ...]
375410
Users are profiles to which you can attribute database-level permissions. They allow you to define permissions specific to each type of database usage.
376411

377412

413+
### Create an user on a Database Instance
414+
415+
Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request.
416+
417+
**Usage:**
418+
419+
```
420+
scw mongodb user create [arg=value ...]
421+
```
422+
423+
424+
**Args:**
425+
426+
| Name | | Description |
427+
|------|---|-------------|
428+
| instance-id | Required | UUID of the Database Instance the user belongs to |
429+
| name | | Name of the database user |
430+
| password | | Password of the database user |
431+
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |
432+
433+
434+
378435
### Delete a user on a Database Instance
379436

380437
Delete an existing user on a Database Instance.

internal/namespaces/mongodb/v1alpha1/mongodb_cli.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ func GetGeneratedCommands() *core.Commands {
4242
mongodbSnapshotList(),
4343
mongodbSnapshotDelete(),
4444
mongodbUserList(),
45+
mongodbUserCreate(),
4546
mongodbUserUpdate(),
4647
mongodbUserDelete(),
4748
mongodbUserSetRole(),
49+
mongodbEndpointDelete(),
50+
mongodbEndpointCreate(),
4851
)
4952
}
5053

@@ -894,6 +897,50 @@ func mongodbUserList() *core.Command {
894897
}
895898
}
896899

900+
func mongodbUserCreate() *core.Command {
901+
return &core.Command{
902+
Short: `Create an user on a Database Instance`,
903+
Long: `Create an user on a Database Instance. You must define the ` + "`" + `name` + "`" + `, ` + "`" + `password` + "`" + ` of the user and ` + "`" + `instance_id` + "`" + ` parameters in the request.`,
904+
Namespace: "mongodb",
905+
Resource: "user",
906+
Verb: "create",
907+
// Deprecated: false,
908+
ArgsType: reflect.TypeOf(mongodb.CreateUserRequest{}),
909+
ArgSpecs: core.ArgSpecs{
910+
{
911+
Name: "instance-id",
912+
Short: `UUID of the Database Instance the user belongs to`,
913+
Required: true,
914+
Deprecated: false,
915+
Positional: false,
916+
},
917+
{
918+
Name: "name",
919+
Short: `Name of the database user`,
920+
Required: false,
921+
Deprecated: false,
922+
Positional: false,
923+
},
924+
{
925+
Name: "password",
926+
Short: `Password of the database user`,
927+
Required: false,
928+
Deprecated: false,
929+
Positional: false,
930+
},
931+
core.RegionArgSpec(scw.RegionFrPar),
932+
},
933+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
934+
request := args.(*mongodb.CreateUserRequest)
935+
936+
client := core.ExtractClient(ctx)
937+
api := mongodb.NewAPI(client)
938+
939+
return api.CreateUser(request)
940+
},
941+
}
942+
}
943+
897944
func mongodbUserUpdate() *core.Command {
898945
return &core.Command{
899946
Short: `Update a user on a Database Instance`,
@@ -1046,3 +1093,77 @@ func mongodbUserSetRole() *core.Command {
10461093
},
10471094
}
10481095
}
1096+
1097+
func mongodbEndpointDelete() *core.Command {
1098+
return &core.Command{
1099+
Short: `Delete a Database Instance endpoint`,
1100+
Long: `Delete the endpoint of a Database Instance. You must specify the ` + "`" + `endpoint_id` + "`" + ` parameter of the endpoint you want to delete. Note that you might need to update any environment configurations that point to the deleted endpoint.`,
1101+
Namespace: "mongodb",
1102+
Resource: "endpoint",
1103+
Verb: "delete",
1104+
// Deprecated: false,
1105+
ArgsType: reflect.TypeOf(mongodb.DeleteEndpointRequest{}),
1106+
ArgSpecs: core.ArgSpecs{
1107+
{
1108+
Name: "endpoint-id",
1109+
Short: `UUID of the Endpoint to delete`,
1110+
Required: true,
1111+
Deprecated: false,
1112+
Positional: true,
1113+
},
1114+
core.RegionArgSpec(scw.RegionFrPar),
1115+
},
1116+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1117+
request := args.(*mongodb.DeleteEndpointRequest)
1118+
1119+
client := core.ExtractClient(ctx)
1120+
api := mongodb.NewAPI(client)
1121+
e = api.DeleteEndpoint(request)
1122+
if e != nil {
1123+
return nil, e
1124+
}
1125+
1126+
return &core.SuccessResult{
1127+
Resource: "endpoint",
1128+
Verb: "delete",
1129+
}, nil
1130+
},
1131+
}
1132+
}
1133+
1134+
func mongodbEndpointCreate() *core.Command {
1135+
return &core.Command{
1136+
Short: `Create a new Instance endpoint`,
1137+
Long: `Create a new endpoint for a MongoDB® Database Instance. You can add ` + "`" + `public_network` + "`" + ` or ` + "`" + `private_network` + "`" + ` specifications to the body of the request.`,
1138+
Namespace: "mongodb",
1139+
Resource: "endpoint",
1140+
Verb: "create",
1141+
// Deprecated: false,
1142+
ArgsType: reflect.TypeOf(mongodb.CreateEndpointRequest{}),
1143+
ArgSpecs: core.ArgSpecs{
1144+
{
1145+
Name: "instance-id",
1146+
Short: `UUID of the Database Instance`,
1147+
Required: true,
1148+
Deprecated: false,
1149+
Positional: true,
1150+
},
1151+
{
1152+
Name: "endpoint.private-network.private-network-id",
1153+
Short: `UUID of the Private Network`,
1154+
Required: false,
1155+
Deprecated: false,
1156+
Positional: false,
1157+
},
1158+
core.RegionArgSpec(scw.RegionFrPar),
1159+
},
1160+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
1161+
request := args.(*mongodb.CreateEndpointRequest)
1162+
1163+
client := core.ExtractClient(ctx)
1164+
api := mongodb.NewAPI(client)
1165+
1166+
return api.CreateEndpoint(request)
1167+
},
1168+
}
1169+
}

0 commit comments

Comments
 (0)