diff --git a/cmd/scw/testdata/test-all-usage-mongodb-endpoint-create-usage.golden b/cmd/scw/testdata/test-all-usage-mongodb-endpoint-create-usage.golden new file mode 100644 index 0000000000..b0124f6082 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-mongodb-endpoint-create-usage.golden @@ -0,0 +1,20 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +🟥🟥🟥 STDERR️️ 🟥🟥🟥️ +Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request. + +USAGE: + scw mongodb endpoint create [arg=value ...] + +ARGS: + instance-id UUID of the Database Instance + [endpoint.private-network.private-network-id] UUID of the Private Network + [region=fr-par] Region to target. If none is passed will use default region from the config (fr-par) + +FLAGS: + -h, --help help for create + +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 diff --git a/cmd/scw/testdata/test-all-usage-mongodb-endpoint-delete-usage.golden b/cmd/scw/testdata/test-all-usage-mongodb-endpoint-delete-usage.golden new file mode 100644 index 0000000000..528380557a --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-mongodb-endpoint-delete-usage.golden @@ -0,0 +1,19 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +🟥🟥🟥 STDERR️️ 🟥🟥🟥️ +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. + +USAGE: + scw mongodb endpoint delete [arg=value ...] + +ARGS: + endpoint-id UUID of the Endpoint to delete + [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 diff --git a/cmd/scw/testdata/test-all-usage-mongodb-endpoint-usage.golden b/cmd/scw/testdata/test-all-usage-mongodb-endpoint-usage.golden index ed392f1bb7..3302b2d078 100644 --- a/cmd/scw/testdata/test-all-usage-mongodb-endpoint-usage.golden +++ b/cmd/scw/testdata/test-all-usage-mongodb-endpoint-usage.golden @@ -3,7 +3,11 @@ Instance endpoints enable connection to your instance. USAGE: - scw mongodb endpoint + scw mongodb endpoint + +AVAILABLE COMMANDS: + create Create a new Instance endpoint + delete Delete a Database Instance endpoint FLAGS: -h, --help help for endpoint @@ -13,3 +17,5 @@ GLOBAL FLAGS: -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 + +Use "scw mongodb endpoint [command] --help" for more information about a command. diff --git a/cmd/scw/testdata/test-all-usage-mongodb-user-create-usage.golden b/cmd/scw/testdata/test-all-usage-mongodb-user-create-usage.golden new file mode 100644 index 0000000000..b2524af3f0 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-mongodb-user-create-usage.golden @@ -0,0 +1,21 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +🟥🟥🟥 STDERR️️ 🟥🟥🟥️ +Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request. + +USAGE: + scw mongodb user create [arg=value ...] + +ARGS: + instance-id UUID of the Database Instance the user belongs to + [name] Name of the database user + [password] Password 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 create + +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 diff --git a/cmd/scw/testdata/test-all-usage-mongodb-user-usage.golden b/cmd/scw/testdata/test-all-usage-mongodb-user-usage.golden index dfe8dad643..0a86c0ce43 100644 --- a/cmd/scw/testdata/test-all-usage-mongodb-user-usage.golden +++ b/cmd/scw/testdata/test-all-usage-mongodb-user-usage.golden @@ -6,6 +6,7 @@ USAGE: scw mongodb user AVAILABLE COMMANDS: + create Create an user on a Database Instance delete Delete a user on a Database Instance list List users of a Database Instance set-role Apply user roles diff --git a/docs/commands/mongodb.md b/docs/commands/mongodb.md index 40560ee20c..a2a0e37265 100644 --- a/docs/commands/mongodb.md +++ b/docs/commands/mongodb.md @@ -3,6 +3,8 @@ This API allows you to manage your Managed Databases for MongoDB®. - [Endpoint management commands](#endpoint-management-commands) + - [Create a new Instance endpoint](#create-a-new-instance-endpoint) + - [Delete a Database Instance endpoint](#delete-a-database-instance-endpoint) - [Instance management commands](#instance-management-commands) - [Create a MongoDB® Database Instance](#create-a-mongodb®-database-instance) - [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®. - [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) + - [Create an user on a Database Instance](#create-an-user-on-a-database-instance) - [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) @@ -33,15 +36,47 @@ This API allows you to manage your Managed Databases for MongoDB®. Instance endpoints enable connection to your instance. -Instance endpoints enable connection to your instance. + +### Create a new Instance endpoint + +Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request. **Usage:** ``` -scw mongodb endpoint +scw mongodb endpoint create [arg=value ...] ``` +**Args:** + +| Name | | Description | +|------|---|-------------| +| instance-id | Required | UUID of the Database Instance | +| endpoint.private-network.private-network-id | | UUID of the Private Network | +| region | Default: `fr-par`
One of: `fr-par` | Region to target. If none is passed will use default region from the config | + + + +### Delete a Database Instance endpoint + +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. + +**Usage:** + +``` +scw mongodb endpoint delete [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| endpoint-id | Required | UUID of the Endpoint to delete | +| region | Default: `fr-par`
One of: `fr-par` | Region to target. If none is passed will use default region from the config | + + ## Instance management commands @@ -375,6 +410,28 @@ scw mongodb snapshot update [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. +### Create an user on a Database Instance + +Create an user on a Database Instance. You must define the `name`, `password` of the user and `instance_id` parameters in the request. + +**Usage:** + +``` +scw mongodb user create [arg=value ...] +``` + + +**Args:** + +| Name | | Description | +|------|---|-------------| +| instance-id | Required | UUID of the Database Instance the user belongs to | +| name | | Name of the database user | +| password | | Password of the database user | +| region | Default: `fr-par`
One of: `fr-par` | Region to target. If none is passed will use default region from the config | + + + ### Delete a user on a Database Instance Delete an existing user on a Database Instance. diff --git a/internal/namespaces/mongodb/v1alpha1/mongodb_cli.go b/internal/namespaces/mongodb/v1alpha1/mongodb_cli.go index 3571ddf1e6..3176824d3f 100644 --- a/internal/namespaces/mongodb/v1alpha1/mongodb_cli.go +++ b/internal/namespaces/mongodb/v1alpha1/mongodb_cli.go @@ -42,9 +42,12 @@ func GetGeneratedCommands() *core.Commands { mongodbSnapshotList(), mongodbSnapshotDelete(), mongodbUserList(), + mongodbUserCreate(), mongodbUserUpdate(), mongodbUserDelete(), mongodbUserSetRole(), + mongodbEndpointDelete(), + mongodbEndpointCreate(), ) } @@ -894,6 +897,50 @@ func mongodbUserList() *core.Command { } } +func mongodbUserCreate() *core.Command { + return &core.Command{ + Short: `Create an user on a Database Instance`, + Long: `Create an user on a Database Instance. You must define the ` + "`" + `name` + "`" + `, ` + "`" + `password` + "`" + ` of the user and ` + "`" + `instance_id` + "`" + ` parameters in the request.`, + Namespace: "mongodb", + Resource: "user", + Verb: "create", + // Deprecated: false, + ArgsType: reflect.TypeOf(mongodb.CreateUserRequest{}), + 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: false, + Deprecated: false, + Positional: false, + }, + { + Name: "password", + Short: `Password of the database user`, + Required: false, + Deprecated: false, + Positional: false, + }, + core.RegionArgSpec(scw.RegionFrPar), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*mongodb.CreateUserRequest) + + client := core.ExtractClient(ctx) + api := mongodb.NewAPI(client) + + return api.CreateUser(request) + }, + } +} + func mongodbUserUpdate() *core.Command { return &core.Command{ Short: `Update a user on a Database Instance`, @@ -1046,3 +1093,77 @@ func mongodbUserSetRole() *core.Command { }, } } + +func mongodbEndpointDelete() *core.Command { + return &core.Command{ + Short: `Delete a Database Instance endpoint`, + 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.`, + Namespace: "mongodb", + Resource: "endpoint", + Verb: "delete", + // Deprecated: false, + ArgsType: reflect.TypeOf(mongodb.DeleteEndpointRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "endpoint-id", + Short: `UUID of the Endpoint to delete`, + Required: true, + Deprecated: false, + Positional: true, + }, + core.RegionArgSpec(scw.RegionFrPar), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*mongodb.DeleteEndpointRequest) + + client := core.ExtractClient(ctx) + api := mongodb.NewAPI(client) + e = api.DeleteEndpoint(request) + if e != nil { + return nil, e + } + + return &core.SuccessResult{ + Resource: "endpoint", + Verb: "delete", + }, nil + }, + } +} + +func mongodbEndpointCreate() *core.Command { + return &core.Command{ + Short: `Create a new Instance endpoint`, + 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.`, + Namespace: "mongodb", + Resource: "endpoint", + Verb: "create", + // Deprecated: false, + ArgsType: reflect.TypeOf(mongodb.CreateEndpointRequest{}), + ArgSpecs: core.ArgSpecs{ + { + Name: "instance-id", + Short: `UUID of the Database Instance`, + Required: true, + Deprecated: false, + Positional: true, + }, + { + Name: "endpoint.private-network.private-network-id", + Short: `UUID of the Private Network`, + Required: false, + Deprecated: false, + Positional: false, + }, + core.RegionArgSpec(scw.RegionFrPar), + }, + Run: func(ctx context.Context, args interface{}) (i interface{}, e error) { + request := args.(*mongodb.CreateEndpointRequest) + + client := core.ExtractClient(ctx) + api := mongodb.NewAPI(client) + + return api.CreateEndpoint(request) + }, + } +}