Skip to content

Commit bb0012c

Browse files
Monitobquantumsheepdependabot[bot]scaleway-botremyleone
authored
feat(rdb) add verb settings to namespace rdb engine (#2548)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Nathanael Demacon <nathanael.dmc@outlook.fr> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Scaleway Bot <github@scaleway.com> Co-authored-by: Rémy Léone <rleone@scaleway.com> Co-authored-by: Jules Castéran <jcasteran@scaleway.com>
1 parent 08f2f0f commit bb0012c

10 files changed

+1105
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List available settings from an engine.
4+
5+
USAGE:
6+
scw rdb engine settings [arg=value ...]
7+
8+
EXAMPLES:
9+
List Engine Settings
10+
scw rdb engine settings name=MySQL version=8
11+
12+
ARGS:
13+
name The name of your engine where you want list the available settings.
14+
version The version of the engine.
15+
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)
16+
17+
FLAGS:
18+
-h, --help help for settings
19+
20+
GLOBAL FLAGS:
21+
-c, --config string The path to the config file
22+
-D, --debug Enable debug mode
23+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
24+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-rdb-engine-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ USAGE:
77

88
AVAILABLE COMMANDS:
99
list List available database engines
10+
settings List available settings from an engine.
1011

1112
FLAGS:
1213
-h, --help help for engine

docs/commands/rdb.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Database RDB API
2222
- [List all database in a given instance](#list-all-database-in-a-given-instance)
2323
- [Database engines commands](#database-engines-commands)
2424
- [List available database engines](#list-available-database-engines)
25+
- [List available settings from an engine.](#list-available-settings-from-an-engine.)
2526
- [Instance management commands](#instance-management-commands)
2627
- [Clone an instance](#clone-an-instance)
2728
- [Connect to an instance using locally installed CLI](#connect-to-an-instance-using-locally-installed-cli)
@@ -452,6 +453,37 @@ scw rdb engine list [arg=value ...]
452453

453454

454455

456+
### List available settings from an engine.
457+
458+
List available settings from an engine.
459+
460+
**Usage:**
461+
462+
```
463+
scw rdb engine settings [arg=value ...]
464+
```
465+
466+
467+
**Args:**
468+
469+
| Name | | Description |
470+
|------|---|-------------|
471+
| name | Required | The name of your engine where you want list the available settings. |
472+
| version | Required | The version of the engine. |
473+
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config |
474+
475+
476+
**Examples:**
477+
478+
479+
List Engine Settings
480+
```
481+
scw rdb engine settings name=MySQL version=8
482+
```
483+
484+
485+
486+
455487
## Instance management commands
456488

457489
A Database Instance is composed of one or more Nodes, depending of the is_ha_cluster setting. Autohealing is enabled by default for HA clusters. Database automated backup is enabled by default in order to prevent data loss.

internal/namespaces/rdb/v1/custom.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func GetCommands() *core.Commands {
3636
instanceConnectCommand(),
3737
backupWaitCommand(),
3838
backupDownloadCommand(),
39+
engineSettingsCommand(),
3940
))
4041
cmds.MustFind("rdb", "acl", "add").Override(aclAddBuilder)
4142
cmds.MustFind("rdb", "acl", "delete").Override(aclDeleteBuilder)
@@ -46,7 +47,6 @@ func GetCommands() *core.Commands {
4647

4748
cmds.MustFind("rdb", "instance", "create").Override(instanceCreateBuilder)
4849
cmds.MustFind("rdb", "instance", "clone").Override(instanceCloneBuilder)
49-
cmds.MustFind("rdb", "instance", "create").Override(instanceCreateBuilder)
5050
cmds.MustFind("rdb", "instance", "upgrade").Override(instanceUpgradeBuilder)
5151
cmds.MustFind("rdb", "instance", "update").Override(instanceUpdateBuilder)
5252

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package rdb
2+
3+
import (
4+
"context"
5+
"reflect"
6+
7+
"github.com/scaleway/scaleway-cli/v2/internal/core"
8+
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
9+
"github.com/scaleway/scaleway-sdk-go/scw"
10+
)
11+
12+
func engineSettingsCommand() *core.Command {
13+
type engineSettingsArgs struct {
14+
Name string
15+
Version string
16+
Region scw.Region
17+
}
18+
19+
return &core.Command{
20+
Short: `List available settings from an engine.`,
21+
Long: `List available settings from an engine.`,
22+
Namespace: "rdb",
23+
Resource: "engine",
24+
Verb: "settings",
25+
ArgsType: reflect.TypeOf(engineSettingsArgs{}),
26+
Run: func(ctx context.Context, argsI interface{}) (i interface{}, err error) {
27+
args := argsI.(*engineSettingsArgs)
28+
api := rdb.NewAPI(core.ExtractClient(ctx))
29+
30+
databaseEnginesRequest := &rdb.ListDatabaseEnginesRequest{
31+
Region: args.Region,
32+
Name: &args.Name,
33+
Version: &args.Version,
34+
}
35+
36+
engines, err := api.ListDatabaseEngines(databaseEnginesRequest)
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
var responseEngineSettings []*rdb.EngineSetting
42+
for _, e := range engines.Engines {
43+
for _, ev := range e.Versions {
44+
if ev.Version == args.Version {
45+
responseEngineSettings = ev.AvailableSettings
46+
}
47+
}
48+
}
49+
50+
return responseEngineSettings, nil
51+
},
52+
ArgSpecs: core.ArgSpecs{
53+
{
54+
Name: "name",
55+
Short: `The name of your engine where you want list the available settings.`,
56+
Required: true,
57+
},
58+
{
59+
Name: "version",
60+
Required: true,
61+
Short: "The version of the engine.",
62+
},
63+
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw),
64+
},
65+
Examples: []*core.Example{
66+
{
67+
Short: "List Engine Settings",
68+
ArgsJSON: `{"name": "MySQL", "version": "8"}`,
69+
},
70+
},
71+
}
72+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package rdb
2+
3+
import (
4+
"testing"
5+
6+
"github.com/scaleway/scaleway-cli/v2/internal/core"
7+
)
8+
9+
func Test_ListEngineSettings(t *testing.T) {
10+
t.Run("Simple", core.Test(&core.TestConfig{
11+
Commands: GetCommands(),
12+
Cmd: "scw rdb engine settings name=MySQL version=8",
13+
Check: core.TestCheckCombine(
14+
core.TestCheckGolden(),
15+
core.TestCheckExitCode(0),
16+
),
17+
}))
18+
19+
t.Run("Lowercase", core.Test(&core.TestConfig{
20+
Commands: GetCommands(),
21+
Cmd: "scw rdb engine settings name=mysql version=8",
22+
Check: core.TestCheckCombine(
23+
core.TestCheckGolden(),
24+
core.TestCheckExitCode(0),
25+
),
26+
}))
27+
}

0 commit comments

Comments
 (0)