Skip to content
Merged
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
6 changes: 3 additions & 3 deletions docs/stackit_beta_sqlserverflex_instance_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ stackit beta sqlserverflex instance create [flags]

```
Create an SQLServer Flex instance with name "my-instance" and specify flavor by CPU and RAM. Other parameters are set to default values
$ stackit sqlserverflex instance create --name my-instance --cpu 1 --ram 4
$ stackit beta sqlserverflex instance create --name my-instance --cpu 1 --ram 4

Create an SQLServer Flex instance with name "my-instance" and specify flavor by ID. Other parameters are set to default values
$ stackit sqlserverflex instance create --name my-instance --flavor-id xxx
$ stackit beta sqlserverflex instance create --name my-instance --flavor-id xxx

Create an SQLServer Flex instance with name "my-instance", specify flavor by CPU and RAM, set storage size to 20 GB, and restrict access to a specific range of IP addresses. Other parameters are set to default values
$ stackit sqlserverflex instance create --name my-instance --cpu 1 --ram 4 --storage-size 20 --acl 1.2.3.0/24
$ stackit beta sqlserverflex instance create --name my-instance --cpu 1 --ram 4 --storage-size 20 --acl 1.2.3.0/24
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/stackit_beta_sqlserverflex_instance_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ stackit beta sqlserverflex instance delete INSTANCE_ID [flags]

```
Delete an SQLServer Flex instance with ID "xxx"
$ stackit sqlserverflex instance delete xxx
$ stackit beta sqlserverflex instance delete xxx
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_beta_sqlserverflex_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ stackit beta sqlserverflex instance describe INSTANCE_ID [flags]

```
Get details of an SQLServer Flex instance with ID "xxx"
$ stackit sqlserverflex instance describe xxx
$ stackit beta sqlserverflex instance describe xxx

Get details of an SQLServer Flex instance with ID "xxx" in JSON format
$ stackit sqlserverflex instance describe xxx --output-format json
$ stackit beta sqlserverflex instance describe xxx --output-format json
```

### Options
Expand Down
6 changes: 3 additions & 3 deletions docs/stackit_beta_sqlserverflex_instance_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ stackit beta sqlserverflex instance list [flags]

```
List all SQLServer Flex instances
$ stackit sqlserverflex instance list
$ stackit beta sqlserverflex instance list

List all SQLServer Flex instances in JSON format
$ stackit sqlserverflex instance list --output-format json
$ stackit beta sqlserverflex instance list --output-format json

List up to 10 SQLServer Flex instances
$ stackit sqlserverflex instance list --limit 10
$ stackit beta sqlserverflex instance list --limit 10
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_beta_sqlserverflex_instance_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ stackit beta sqlserverflex instance update INSTANCE_ID [flags]

```
Update the name of an SQLServer Flex instance with ID "xxx"
$ stackit sqlserverflex instance update xxx --name my-new-name
$ stackit beta sqlserverflex instance update xxx --name my-new-name

Update the backup schedule of an SQLServer Flex instance with ID "xxx"
$ stackit sqlserverflex instance update xxx --backup-schedule "30 0 * * *"
$ stackit beta sqlserverflex instance update xxx --backup-schedule "30 0 * * *"
```

### Options
Expand Down
12 changes: 7 additions & 5 deletions internal/cmd/beta/sqlserverflex/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ func NewCmd(p *print.Printer) *cobra.Command {
Example: examples.Build(
examples.NewExample(
`Create an SQLServer Flex instance with name "my-instance" and specify flavor by CPU and RAM. Other parameters are set to default values`,
`$ stackit sqlserverflex instance create --name my-instance --cpu 1 --ram 4`),
`$ stackit beta sqlserverflex instance create --name my-instance --cpu 1 --ram 4`),
examples.NewExample(
`Create an SQLServer Flex instance with name "my-instance" and specify flavor by ID. Other parameters are set to default values`,
`$ stackit sqlserverflex instance create --name my-instance --flavor-id xxx`),
`$ stackit beta sqlserverflex instance create --name my-instance --flavor-id xxx`),
examples.NewExample(
`Create an SQLServer Flex instance with name "my-instance", specify flavor by CPU and RAM, set storage size to 20 GB, and restrict access to a specific range of IP addresses. Other parameters are set to default values`,
`$ stackit sqlserverflex instance create --name my-instance --cpu 1 --ram 4 --storage-size 20 --acl 1.2.3.0/24`),
`$ stackit beta sqlserverflex instance create --name my-instance --cpu 1 --ram 4 --storage-size 20 --acl 1.2.3.0/24`),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down Expand Up @@ -157,12 +157,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {

if flavorId == nil && (cpu == nil || ram == nil) {
return nil, &cliErr.DatabaseInputFlavorError{
Cmd: cmd,
Cmd: cmd,
Service: sqlserverflexUtils.ServiceCmd,
}
}
if flavorId != nil && (cpu != nil || ram != nil) {
return nil, &cliErr.DatabaseInputFlavorError{
Cmd: cmd,
Cmd: cmd,
Service: sqlserverflexUtils.ServiceCmd,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
Example: examples.Build(
examples.NewExample(
`Delete an SQLServer Flex instance with ID "xxx"`,
"$ stackit sqlserverflex instance delete xxx"),
"$ stackit beta sqlserverflex instance delete xxx"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func NewCmd(p *print.Printer) *cobra.Command {
Example: examples.Build(
examples.NewExample(
`Get details of an SQLServer Flex instance with ID "xxx"`,
"$ stackit sqlserverflex instance describe xxx"),
"$ stackit beta sqlserverflex instance describe xxx"),
examples.NewExample(
`Get details of an SQLServer Flex instance with ID "xxx" in JSON format`,
"$ stackit sqlserverflex instance describe xxx --output-format json"),
"$ stackit beta sqlserverflex instance describe xxx --output-format json"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/beta/sqlserverflex/instance/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func NewCmd(p *print.Printer) *cobra.Command {
Example: examples.Build(
examples.NewExample(
`List all SQLServer Flex instances`,
"$ stackit sqlserverflex instance list"),
"$ stackit beta sqlserverflex instance list"),
examples.NewExample(
`List all SQLServer Flex instances in JSON format`,
"$ stackit sqlserverflex instance list --output-format json"),
"$ stackit beta sqlserverflex instance list --output-format json"),
examples.NewExample(
`List up to 10 SQLServer Flex instances`,
"$ stackit sqlserverflex instance list --limit 10"),
"$ stackit beta sqlserverflex instance list --limit 10"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/beta/sqlserverflex/instance/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func NewCmd(p *print.Printer) *cobra.Command {
Example: examples.Build(
examples.NewExample(
`Update the name of an SQLServer Flex instance with ID "xxx"`,
"$ stackit sqlserverflex instance update xxx --name my-new-name"),
"$ stackit beta sqlserverflex instance update xxx --name my-new-name"),
examples.NewExample(
`Update the backup schedule of an SQLServer Flex instance with ID "xxx"`,
`$ stackit sqlserverflex instance update xxx --backup-schedule "30 0 * * *"`),
`$ stackit beta sqlserverflex instance update xxx --backup-schedule "30 0 * * *"`),
),
Args: args.SingleArg(instanceIdArg, utils.ValidateUUID),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -152,8 +152,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu

if flavorId != nil && (cpu != nil || ram != nil) {
return nil, &cliErr.DatabaseInputFlavorError{
Cmd: cmd,
Args: inputArgs,
Cmd: cmd,
Service: sqlserverflexUtils.ServiceCmd,
Args: inputArgs,
}
}

Expand Down
16 changes: 9 additions & 7 deletions internal/pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,23 @@ func (e *DSAInvalidPlanError) Error() string {
}

type DatabaseInputFlavorError struct {
Service string
Operation string
Cmd *cobra.Command
Args []string
Service string
Cmd *cobra.Command
Comment thread
vicentepinto98 marked this conversation as resolved.
Args []string
}

func (e *DatabaseInputFlavorError) Error() string {
fullCommandPath := e.Cmd.CommandPath()
if len(e.Args) > 0 {
fullCommandPath = fmt.Sprintf("%s %s", fullCommandPath, strings.Join(e.Args, " "))
}
// Assumes a structure of the form "stackit <service> <resource> <operation>"
service := e.Cmd.Parent().Parent().Use

return fmt.Sprintf(DATABASE_INVALID_INPUT_FLAVOR, fullCommandPath, service)
if e.Service == "" {
Comment thread
joaopalet marked this conversation as resolved.
// Assumes a structure of the form "stackit <service> <resource> <operation>"
e.Service = e.Cmd.Parent().Parent().Use
}

return fmt.Sprintf(DATABASE_INVALID_INPUT_FLAVOR, fullCommandPath, e.Service)
}

type DatabaseInvalidFlavorError struct {
Expand Down
47 changes: 40 additions & 7 deletions internal/pkg/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ func setupCmd() {
resource.AddCommand(operation)
}

func setupBetaCmd() {
cmd = &cobra.Command{
Use: "stackit",
}
beta := &cobra.Command{
Use: "beta",
}
service = &cobra.Command{
Use: "service",
}
resource = &cobra.Command{
Use: "resource",
}
operation = &cobra.Command{
Use: "operation",
}
cmd.AddCommand(beta)
beta.AddCommand(service)
service.AddCommand(resource)
resource.AddCommand(operation)
}

func TestSimpleErrors(t *testing.T) {
tests := []struct {
description string
Expand Down Expand Up @@ -220,24 +242,35 @@ func TestDatabaseInputFlavorError(t *testing.T) {
tests := []struct {
description string
args []string
operation string
service string
expectedMsg string
isBetaCmd bool
}{
{
description: "base",
description: "no service",
args: []string{"arg1", "arg2"},
operation: "operation",
expectedMsg: fmt.Sprintf(DATABASE_INVALID_INPUT_FLAVOR, "stackit service resource operation arg1 arg2", "service"),
},
{
description: "with service",
args: []string{"arg1", "arg2"},
service: "beta service",
expectedMsg: fmt.Sprintf(DATABASE_INVALID_INPUT_FLAVOR, "stackit beta service resource operation arg1 arg2", "beta service"),
isBetaCmd: true,
},
}

setupCmd()
for _, tt := range tests {
if tt.isBetaCmd {
setupBetaCmd()
} else {
setupCmd()
}
t.Run(tt.description, func(t *testing.T) {
err := &DatabaseInputFlavorError{
Cmd: operation,
Args: tt.args,
Operation: tt.operation,
Cmd: operation,
Args: tt.args,
Service: tt.service,
}

if err.Error() != tt.expectedMsg {
Expand Down
10 changes: 7 additions & 3 deletions internal/pkg/services/sqlserverflex/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex"
)

const (
ServiceCmd = "beta sqlserverflex"
)

type SQLServerFlexClient interface {
ListVersionsExecute(ctx context.Context, projectId string) (*sqlserverflex.ListVersionsResponse, error)
GetInstanceExecute(ctx context.Context, projectId, instanceId string) (*sqlserverflex.GetInstanceResponse, error)
Expand All @@ -27,7 +31,7 @@ func ValidateFlavorId(flavorId string, flavors *[]sqlserverflex.InstanceFlavorEn
}

return &errors.DatabaseInvalidFlavorError{
Service: "sqlserverflex",
Service: ServiceCmd,
Details: fmt.Sprintf("You provided flavor ID '%s', which is invalid.", flavorId),
}
}
Expand All @@ -53,7 +57,7 @@ func ValidateStorage(storageClass *string, storageSize *int64, storages *sqlserv
}
}
return &errors.DatabaseInvalidStorageError{
Service: "sqlserverflex",
Service: ServiceCmd,
Details: fmt.Sprintf("You provided storage class '%s', which is invalid.", *storageClass),
FlavorId: flavorId,
}
Expand All @@ -75,7 +79,7 @@ func LoadFlavorId(cpu, ram int64, flavors *[]sqlserverflex.InstanceFlavorEntry)
availableFlavors = fmt.Sprintf("%s\n- %d CPU, %d GB RAM", availableFlavors, *f.Cpu, *f.Cpu)
}
return nil, &errors.DatabaseInvalidFlavorError{
Service: "sqlserverflex",
Service: ServiceCmd,
Details: "You provided an invalid combination for CPU and RAM.",
}
}
Expand Down