Skip to content

feat(rdb): add command for instance settings #4677

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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
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,28 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
This command opens the current settings of your RDB instance in your $EDITOR.
You can modify the values and save the file to apply the new configuration.

USAGE:
scw rdb instance edit-settings <instance-id ...> [arg=value ...]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be fixed


EXAMPLES:
Edit instance settings in YAML
scw rdb instance edit-settings 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=yaml

Edit instance settings in JSON
scw rdb instance edit-settings 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=json

ARGS:
instance-id ID of the instance
[mode=yaml] marshaling used when editing data (yaml | json)
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)

FLAGS:
-h, --help help for edit-settings

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
28 changes: 28 additions & 0 deletions cmd/scw/testdata/test-all-usage-rdb-setting-edit-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
This command opens the current settings of your RDB instance in your $EDITOR.
You can modify the values and save the file to apply the new configuration.

USAGE:
scw rdb setting edit <instance-id ...> [arg=value ...]

EXAMPLES:
Edit instance settings in YAML
scw rdb setting edit 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=yaml

Edit instance settings in JSON
scw rdb setting edit 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=json

ARGS:
instance-id ID of the instance
[mode=yaml] marshaling used when editing data (yaml | json)
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)

FLAGS:
-h, --help help for edit

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
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-rdb-setting-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ USAGE:
AVAILABLE COMMANDS:
add Add Database Instance advanced settings
delete Delete Database Instance advanced settings
edit Edit Database Instance settings in your default editor
set Set Database Instance advanced settings

FLAGS:
Expand Down
38 changes: 38 additions & 0 deletions docs/commands/rdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ This API allows you to manage your Managed Databases for PostgreSQL and MySQL.
- [Setting management](#setting-management)
- [Add Database Instance advanced settings](#add-database-instance-advanced-settings)
- [Delete Database Instance advanced settings](#delete-database-instance-advanced-settings)
- [Edit Database Instance settings in your default editor](#edit-database-instance-settings-in-your-default-editor)
- [Set Database Instance advanced settings](#set-database-instance-advanced-settings)
- [Block snapshot management](#block-snapshot-management)
- [Create a Database Instance snapshot](#create-a-database-instance-snapshot)
Expand Down Expand Up @@ -1398,6 +1399,43 @@ scw rdb setting delete [arg=value ...]



### Edit Database Instance settings in your default editor

This command opens the current settings of your RDB instance in your $EDITOR.
You can modify the values and save the file to apply the new configuration.

**Usage:**

```
scw rdb setting edit <instance-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| instance-id | Required | ID of the instance |
| mode | Default: `yaml`<br />One of: `yaml`, `json` | marshaling used when editing data |
| 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 |


**Examples:**


Edit instance settings in YAML
```
scw rdb setting edit 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=yaml
```

Edit instance settings in JSON
```
scw rdb setting edit 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=json
```




### Set Database Instance advanced settings

Update an advanced setting for a Database Instance. Settings added upon database engine initialization can only be defined once, and cannot, therefore, be updated.
Expand Down
1 change: 1 addition & 0 deletions internal/namespaces/rdb/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func GetCommands() *core.Commands {
instanceConnectCommand(),
instanceWaitCommand(),
userGetURLCommand(),
instanceEditSettingsCommand(),
))
cmds.MustFind("rdb", "acl", "add").Override(aclAddBuilder)
cmds.MustFind("rdb", "acl", "delete").Override(aclDeleteBuilder)
Expand Down
87 changes: 87 additions & 0 deletions internal/namespaces/rdb/v1/custom_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/core/human"
"github.com/scaleway/scaleway-cli/v2/internal/editor"
"github.com/scaleway/scaleway-cli/v2/internal/interactive"
"github.com/scaleway/scaleway-cli/v2/internal/passwordgenerator"
"github.com/scaleway/scaleway-cli/v2/internal/terminal"
Expand Down Expand Up @@ -925,3 +926,89 @@ func instanceConnectCommand() *core.Command {
},
}
}

func instanceEditSettingsCommand() *core.Command {
type editSettingsArgs struct {
InstanceID string `arg:"positional,required"`
Region scw.Region `arg:"required"`
Mode editor.MarshalMode
}

return &core.Command{
Namespace: "rdb",
Resource: "setting",
Verb: "edit",
Short: "Edit Database Instance settings in your default editor",
Long: `This command opens the current settings of your RDB instance in your $EDITOR.
You can modify the values and save the file to apply the new configuration.`,
ArgsType: reflect.TypeOf(editSettingsArgs{}),
ArgSpecs: core.ArgSpecs{
{
Name: "instance-id",
Short: "ID of the instance",
Required: true,
Positional: true,
},
editor.MarshalModeArgSpec(), // --mode=yaml|json
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw),
},
Examples: []*core.Example{
{
Short: "Edit instance settings in YAML",
Raw: "scw rdb setting edit 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=yaml",
},
{
Short: "Edit instance settings in JSON",
Raw: "scw rdb setting edit 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=json",
},
},
Run: func(ctx context.Context, argsI interface{}) (interface{}, error) {
args := argsI.(*editSettingsArgs)

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

instance, err := api.GetInstance(&rdbSDK.GetInstanceRequest{
InstanceID: args.InstanceID,
Region: args.Region,
})
if err != nil {
return nil, err
}

initialRequest := &rdbSDK.SetInstanceSettingsRequest{
Region: args.Region,
InstanceID: args.InstanceID,
Settings: instance.Settings,
}

editedRequestRaw, err := editor.UpdateResourceEditor(
initialRequest,
&rdbSDK.SetInstanceSettingsRequest{
Region: args.Region,
InstanceID: args.InstanceID,
},
&editor.Config{
PutRequest: true,
MarshalMode: args.Mode,
},
)
if err != nil {
return nil, err
}

editedRequest := editedRequestRaw.(*rdbSDK.SetInstanceSettingsRequest)

if reflect.DeepEqual(initialRequest.Settings, editedRequest.Settings) {
return &core.SuccessResult{Message: "No changes detected."}, nil
}

_, err = api.SetInstanceSettings(editedRequest)
if err != nil {
return nil, err
}

return &core.SuccessResult{Message: "Settings successfully updated."}, nil
},
}
}
Loading