Skip to content
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.11.0
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ github.com/stackitcloud/stackit-sdk-go/services/observability v0.24.0 h1:KhuWPXr
github.com/stackitcloud/stackit-sdk-go/services/observability v0.24.0/go.mod h1:0fEZQHm729mBdvg4sNrAhM6KmHROHJSeS2FwCMRk46k=
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0 h1:hooc/E9Qabn8xno1NUd3uJQfUbW5KoY6mgURlnd776c=
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0/go.mod h1:L+NlfC1hilLOqlLLukCj/UDnxlnNrc/oMikcw3Ansyw=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 h1:H67e3KnHQx954yI8fuQmxXwRf/myqAdLg2KvxImp00g=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5/go.mod h1:xmAWk9eom8wznvLuLfm0F4xyeiBX8LaggXsKFmos+dw=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.11.0 h1:cuI4NhuFhaZ3tTkBpUM7nt2odKFJkyCcphT/3gGb9CE=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.11.0/go.mod h1:yzlakB+f8ur4yAHR6lyCABO+HcEtZG3G2Faj6m5/uW8=
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v1.1.0 h1:HRJwodJX4aOn/487zaqJIKw13yIj4T6dn7/kEHLxeTg=
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v1.1.0/go.mod h1:TwfVVynB/+AKbccSOLk2qZpPL1tdK43BBAiACP6EtSg=
github.com/stackitcloud/stackit-sdk-go/services/redis v1.1.0 h1:ckYMRXAGE2/vaxPeNGEuun9AGcFn/8xuu0ytfsiqfWU=
Expand Down
11 changes: 7 additions & 4 deletions internal/cmd/postgresflex/backup/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
Expand Down Expand Up @@ -73,7 +73,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return fmt.Errorf("describe backup for PostgreSQL Flex instance: %w", err)
}

return outputResult(params.Printer, model.OutputFormat, *resp.Item)
return outputResult(params.Printer, model.OutputFormat, resp.Item)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -103,11 +103,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiGetBackupRequest {
req := apiClient.GetBackup(ctx, model.ProjectId, model.Region, model.InstanceId, model.BackupId)
req := apiClient.DefaultAPI.GetBackup(ctx, model.ProjectId, model.Region, model.InstanceId, model.BackupId)
return req
}

func outputResult(p *print.Printer, outputFormat string, backup postgresflex.Backup) error {
func outputResult(p *print.Printer, outputFormat string, backup *postgresflex.Backup) error {
if backup == nil {
return fmt.Errorf("backup is nil")
}
if backup.StartTime == nil || *backup.StartTime == "" {
return fmt.Errorf("start time not defined")
}
Expand Down
16 changes: 8 additions & 8 deletions internal/cmd/postgresflex/backup/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
Expand All @@ -18,7 +18,7 @@ import (
type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &postgresflex.APIClient{}
var testClient = &postgresflex.APIClient{DefaultAPI: &postgresflex.DefaultAPIService{}}
var testProjectId = uuid.NewString()
var testInstanceId = uuid.NewString()
var testBackupId = "backupID"
Expand Down Expand Up @@ -63,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *postgresflex.ApiGetBackupRequest)) postgresflex.ApiGetBackupRequest {
request := testClient.GetBackup(testCtx, testProjectId, testRegion, testInstanceId, testBackupId)
request := testClient.DefaultAPI.GetBackup(testCtx, testProjectId, testRegion, testInstanceId, testBackupId)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, postgresflex.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand All @@ -243,19 +243,19 @@ func TestBuildRequest(t *testing.T) {
func Test_outputResult(t *testing.T) {
type args struct {
outputFormat string
backup postgresflex.Backup
backup *postgresflex.Backup
}
tests := []struct {
name string
args args
wantErr bool
}{
{"empty", args{}, true},
{"standard", args{outputFormat: "", backup: postgresflex.Backup{StartTime: utils.Ptr(time.Now().Format(time.RFC3339))}}, false},
{"complete", args{outputFormat: "", backup: postgresflex.Backup{
{"standard", args{outputFormat: "", backup: &postgresflex.Backup{StartTime: utils.Ptr(time.Now().Format(time.RFC3339))}}, false},
{"complete", args{outputFormat: "", backup: &postgresflex.Backup{
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
Id: utils.Ptr("id"),
Labels: &[]string{"foo", "bar", "baz"},
Labels: []string{"foo", "bar", "baz"},
Name: utils.Ptr("name"),
Options: &map[string]string{"test1": "test1", "test2": "test2"},
Size: utils.Ptr(int64(42)),
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/postgresflex/backup/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"time"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
)

const (
Expand Down Expand Up @@ -68,7 +68,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return err
}

instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, *model.InstanceId)
instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *model.InstanceId)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
instanceLabel = *model.InstanceId
Expand All @@ -80,11 +80,11 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
if err != nil {
return fmt.Errorf("get backups for PostgreSQL Flex instance %q: %w", instanceLabel, err)
}
if resp.Items == nil || len(*resp.Items) == 0 {
if len(resp.Items) == 0 {
params.Printer.Outputf("No backups found for instance %q", instanceLabel)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

invalid JSON/YAML output

return nil
}
backups := *resp.Items
backups := resp.Items

// Truncate output
if model.Limit != nil && len(backups) > int(*model.Limit) {
Expand Down Expand Up @@ -129,7 +129,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiListBackupsRequest {
req := apiClient.ListBackups(ctx, model.ProjectId, model.Region, *model.InstanceId)
req := apiClient.DefaultAPI.ListBackups(ctx, model.ProjectId, model.Region, *model.InstanceId)
return req
}

Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/postgresflex/backup/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
Expand All @@ -20,7 +20,7 @@ import (
type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &postgresflex.APIClient{}
var testClient = &postgresflex.APIClient{DefaultAPI: &postgresflex.DefaultAPIService{}}
var testProjectId = uuid.NewString()
var testInstanceId = uuid.NewString()
var testRegion = "eu01"
Expand Down Expand Up @@ -55,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *postgresflex.ApiListBackupsRequest)) postgresflex.ApiListBackupsRequest {
request := testClient.ListBackups(testCtx, testProjectId, testRegion, testInstanceId)
request := testClient.DefaultAPI.ListBackups(testCtx, testProjectId, testRegion, testInstanceId)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, postgresflex.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand All @@ -190,7 +190,7 @@ func Test_outputResult(t *testing.T) {
{
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
Id: utils.Ptr("id"),
Labels: &[]string{"foo", "bar", "baz"},
Labels: []string{"foo", "bar", "baz"},
Name: utils.Ptr("name"),
Options: &map[string]string{"test1": "test1", "test2": "test2"},
Size: utils.Ptr(int64(42)),
Expand All @@ -199,7 +199,7 @@ func Test_outputResult(t *testing.T) {
{
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
Id: utils.Ptr("id"),
Labels: &[]string{"foo", "bar", "baz"},
Labels: []string{"foo", "bar", "baz"},
Name: utils.Ptr("name"),
Options: &map[string]string{"test1": "test1", "test2": "test2"},
Size: utils.Ptr(int64(42)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
Expand All @@ -27,8 +27,8 @@ const (
type inputModel struct {
*globalflags.GlobalFlagModel

InstanceId *string
BackupSchedule *string
InstanceId string
BackupSchedule string
}

func NewCmd(params *types.CmdParams) *cobra.Command {
Expand Down Expand Up @@ -57,10 +57,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return err
}

instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, *model.InstanceId)
instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
instanceLabel = *model.InstanceId
instanceLabel = model.InstanceId
}

prompt := fmt.Sprintf("Are you sure you want to update backup schedule of instance %q?", instanceLabel)
Expand Down Expand Up @@ -100,13 +100,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,

return &inputModel{
GlobalFlagModel: globalFlags,
InstanceId: flags.FlagToStringPointer(p, cmd, instanceIdFlag),
BackupSchedule: flags.FlagToStringPointer(p, cmd, scheduleFlag),
InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag),
BackupSchedule: flags.FlagToStringValue(p, cmd, scheduleFlag),
}, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiUpdateBackupScheduleRequest {
req := apiClient.UpdateBackupSchedule(ctx, model.ProjectId, model.Region, *model.InstanceId)
req := apiClient.DefaultAPI.UpdateBackupSchedule(ctx, model.ProjectId, model.Region, model.InstanceId)
req = req.UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{
BackupSchedule: model.BackupSchedule,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import (

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
)

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &postgresflex.APIClient{}
var testClient = &postgresflex.APIClient{DefaultAPI: &postgresflex.DefaultAPIService{}}
var testProjectId = uuid.NewString()
var testInstanceId = uuid.NewString()
var testSchedule = "0 0 * * *"
Expand All @@ -43,8 +42,8 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
Region: testRegion,
Verbosity: globalflags.VerbosityDefault,
},
InstanceId: utils.Ptr(testInstanceId),
BackupSchedule: &testSchedule,
InstanceId: testInstanceId,
BackupSchedule: testSchedule,
}
for _, mod := range mods {
mod(model)
Expand All @@ -54,7 +53,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {

func fixturePayload(mods ...func(payload *postgresflex.UpdateBackupSchedulePayload)) postgresflex.UpdateBackupSchedulePayload {
payload := postgresflex.UpdateBackupSchedulePayload{
BackupSchedule: utils.Ptr(testSchedule),
BackupSchedule: testSchedule,
}
for _, mod := range mods {
mod(&payload)
Expand All @@ -63,7 +62,7 @@ func fixturePayload(mods ...func(payload *postgresflex.UpdateBackupSchedulePaylo
}

func fixtureRequest(mods ...func(request *postgresflex.ApiUpdateBackupScheduleRequest)) postgresflex.ApiUpdateBackupScheduleRequest {
request := testClient.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId)
request := testClient.DefaultAPI.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId)
request = request.UpdateBackupSchedulePayload(fixturePayload())
for _, mod := range mods {
mod(&request)
Expand Down Expand Up @@ -167,9 +166,9 @@ func TestBuildRequest(t *testing.T) {
ProjectId: testProjectId,
Region: testRegion,
},
InstanceId: utils.Ptr(testInstanceId),
InstanceId: testInstanceId,
},
expectedRequest: testClient.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId).
expectedRequest: testClient.DefaultAPI.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId).
UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{}),
},
}
Expand All @@ -180,7 +179,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, postgresflex.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
Loading
Loading