Skip to content

Commit c46e1b2

Browse files
feat(postgresflex): migrate to V2 api (#1476)
relates to STACKITCLI-374
1 parent 632876f commit c46e1b2

37 files changed

Lines changed: 889 additions & 887 deletions

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2
2828
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0
2929
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0
30-
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5
30+
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.11.0
3131
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0
3232
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3
3333
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ github.com/stackitcloud/stackit-sdk-go/services/observability v0.24.0 h1:KhuWPXr
626626
github.com/stackitcloud/stackit-sdk-go/services/observability v0.24.0/go.mod h1:0fEZQHm729mBdvg4sNrAhM6KmHROHJSeS2FwCMRk46k=
627627
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0 h1:hooc/E9Qabn8xno1NUd3uJQfUbW5KoY6mgURlnd776c=
628628
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0/go.mod h1:L+NlfC1hilLOqlLLukCj/UDnxlnNrc/oMikcw3Ansyw=
629-
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 h1:H67e3KnHQx954yI8fuQmxXwRf/myqAdLg2KvxImp00g=
630-
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5/go.mod h1:xmAWk9eom8wznvLuLfm0F4xyeiBX8LaggXsKFmos+dw=
629+
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.11.0 h1:cuI4NhuFhaZ3tTkBpUM7nt2odKFJkyCcphT/3gGb9CE=
630+
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.11.0/go.mod h1:yzlakB+f8ur4yAHR6lyCABO+HcEtZG3G2Faj6m5/uW8=
631631
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v1.1.0 h1:HRJwodJX4aOn/487zaqJIKw13yIj4T6dn7/kEHLxeTg=
632632
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v1.1.0/go.mod h1:TwfVVynB/+AKbccSOLk2qZpPL1tdK43BBAiACP6EtSg=
633633
github.com/stackitcloud/stackit-sdk-go/services/redis v1.1.0 h1:ckYMRXAGE2/vaxPeNGEuun9AGcFn/8xuu0ytfsiqfWU=

internal/cmd/postgresflex/backup/describe/describe.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
99

1010
"github.com/spf13/cobra"
11-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
11+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
1212

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

76-
return outputResult(params.Printer, model.OutputFormat, *resp.Item)
76+
return outputResult(params.Printer, model.OutputFormat, resp.Item)
7777
},
7878
}
7979
configureFlags(cmd)
@@ -103,11 +103,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
103103
}
104104

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

110-
func outputResult(p *print.Printer, outputFormat string, backup postgresflex.Backup) error {
110+
func outputResult(p *print.Printer, outputFormat string, backup *postgresflex.Backup) error {
111+
if backup == nil {
112+
return fmt.Errorf("backup is nil")
113+
}
111114
if backup.StartTime == nil || *backup.StartTime == "" {
112115
return fmt.Errorf("start time not defined")
113116
}

internal/cmd/postgresflex/backup/describe/describe_test.go

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/google/go-cmp/cmp"
99
"github.com/google/go-cmp/cmp/cmpopts"
1010
"github.com/google/uuid"
11-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
11+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
1212

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

2020
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
var testClient = &postgresflex.APIClient{}
21+
var testClient = &postgresflex.APIClient{DefaultAPI: &postgresflex.DefaultAPIService{}}
2222
var testProjectId = uuid.NewString()
2323
var testInstanceId = uuid.NewString()
2424
var testBackupId = "backupID"
@@ -63,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6363
}
6464

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

232232
diff := cmp.Diff(request, tt.expectedRequest,
233233
cmp.AllowUnexported(tt.expectedRequest),
234-
cmpopts.EquateComparable(testCtx),
234+
cmpopts.EquateComparable(testCtx, postgresflex.DefaultAPIService{}),
235235
)
236236
if diff != "" {
237237
t.Fatalf("Data does not match: %s", diff)
@@ -243,24 +243,47 @@ func TestBuildRequest(t *testing.T) {
243243
func Test_outputResult(t *testing.T) {
244244
type args struct {
245245
outputFormat string
246-
backup postgresflex.Backup
246+
backup *postgresflex.Backup
247247
}
248248
tests := []struct {
249249
name string
250250
args args
251251
wantErr bool
252252
}{
253-
{"empty", args{}, true},
254-
{"standard", args{outputFormat: "", backup: postgresflex.Backup{StartTime: utils.Ptr(time.Now().Format(time.RFC3339))}}, false},
255-
{"complete", args{outputFormat: "", backup: postgresflex.Backup{
256-
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
257-
Id: utils.Ptr("id"),
258-
Labels: &[]string{"foo", "bar", "baz"},
259-
Name: utils.Ptr("name"),
260-
Options: &map[string]string{"test1": "test1", "test2": "test2"},
261-
Size: utils.Ptr(int64(42)),
262-
StartTime: utils.Ptr(time.Now().Format(time.RFC3339)),
263-
}}, false},
253+
{
254+
name: "empty",
255+
args: args{},
256+
wantErr: true,
257+
},
258+
{
259+
name: "standard",
260+
args: args{
261+
outputFormat: "",
262+
backup: &postgresflex.Backup{
263+
StartTime: utils.Ptr(time.Now().Format(time.RFC3339)),
264+
},
265+
},
266+
wantErr: false,
267+
},
268+
{
269+
name: "complete",
270+
args: args{
271+
outputFormat: "",
272+
backup: &postgresflex.Backup{
273+
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
274+
Id: utils.Ptr("id"),
275+
Labels: []string{"foo",
276+
"bar",
277+
"baz",
278+
},
279+
Name: utils.Ptr("name"),
280+
Options: &map[string]string{"test1": "test1", "test2": "test2"},
281+
Size: utils.Ptr(int64(42)),
282+
StartTime: utils.Ptr(time.Now().Format(time.RFC3339)),
283+
},
284+
},
285+
wantErr: false,
286+
},
264287
}
265288
params := testparams.NewTestParams()
266289
for _, tt := range tests {

internal/cmd/postgresflex/backup/list/list.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"time"
2121

2222
"github.com/spf13/cobra"
23-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
23+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
2424
)
2525

2626
const (
@@ -68,7 +68,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6868
return err
6969
}
7070

71-
instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, *model.InstanceId)
71+
instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *model.InstanceId)
7272
if err != nil {
7373
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
7474
instanceLabel = *model.InstanceId
@@ -80,18 +80,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8080
if err != nil {
8181
return fmt.Errorf("get backups for PostgreSQL Flex instance %q: %w", instanceLabel, err)
8282
}
83-
if resp.Items == nil || len(*resp.Items) == 0 {
84-
params.Printer.Outputf("No backups found for instance %q", instanceLabel)
85-
return nil
86-
}
87-
backups := *resp.Items
83+
backups := resp.Items
8884

8985
// Truncate output
9086
if model.Limit != nil && len(backups) > int(*model.Limit) {
9187
backups = backups[:*model.Limit]
9288
}
9389

94-
return outputResult(params.Printer, model.OutputFormat, backups)
90+
return outputResult(params.Printer, model.OutputFormat, instanceLabel, backups)
9591
},
9692
}
9793

@@ -129,12 +125,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
129125
}
130126

131127
func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiListBackupsRequest {
132-
req := apiClient.ListBackups(ctx, model.ProjectId, model.Region, *model.InstanceId)
128+
req := apiClient.DefaultAPI.ListBackups(ctx, model.ProjectId, model.Region, *model.InstanceId)
133129
return req
134130
}
135131

136-
func outputResult(p *print.Printer, outputFormat string, backups []postgresflex.Backup) error {
132+
func outputResult(p *print.Printer, outputFormat, instanceLabel string, backups []postgresflex.Backup) error {
137133
return p.OutputResult(outputFormat, backups, func() error {
134+
if len(backups) == 0 {
135+
p.Outputf("No backups found for instance %q", instanceLabel)
136+
return nil
137+
}
138138
table := tables.NewTable()
139139
table.SetHeader("ID", "CREATED AT", "EXPIRES AT", "BACKUP SIZE")
140140
for i := range backups {

internal/cmd/postgresflex/backup/list/list_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"time"
77

88
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
9+
910
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1011

1112
"github.com/google/go-cmp/cmp"
1213
"github.com/google/go-cmp/cmp/cmpopts"
1314
"github.com/google/uuid"
14-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
15+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
1516

1617
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1718
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
@@ -20,7 +21,7 @@ import (
2021
type testCtxKey struct{}
2122

2223
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
23-
var testClient = &postgresflex.APIClient{}
24+
var testClient = &postgresflex.APIClient{DefaultAPI: &postgresflex.DefaultAPIService{}}
2425
var testProjectId = uuid.NewString()
2526
var testInstanceId = uuid.NewString()
2627
var testRegion = "eu01"
@@ -55,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5556
}
5657

5758
func fixtureRequest(mods ...func(request *postgresflex.ApiListBackupsRequest)) postgresflex.ApiListBackupsRequest {
58-
request := testClient.ListBackups(testCtx, testProjectId, testRegion, testInstanceId)
59+
request := testClient.DefaultAPI.ListBackups(testCtx, testProjectId, testRegion, testInstanceId)
5960
for _, mod := range mods {
6061
mod(&request)
6162
}
@@ -165,7 +166,7 @@ func TestBuildRequest(t *testing.T) {
165166

166167
diff := cmp.Diff(request, tt.expectedRequest,
167168
cmp.AllowUnexported(tt.expectedRequest),
168-
cmpopts.EquateComparable(testCtx),
169+
cmpopts.EquateComparable(testCtx, postgresflex.DefaultAPIService{}),
169170
)
170171
if diff != "" {
171172
t.Fatalf("Data does not match: %s", diff)
@@ -176,21 +177,22 @@ func TestBuildRequest(t *testing.T) {
176177

177178
func Test_outputResult(t *testing.T) {
178179
type args struct {
179-
outputFormat string
180-
backups []postgresflex.Backup
180+
outputFormat string
181+
instanceLabel string
182+
backups []postgresflex.Backup
181183
}
182184
tests := []struct {
183185
name string
184186
args args
185187
wantErr bool
186188
}{
187189
{"empty", args{}, false},
188-
{"standard", args{outputFormat: "", backups: []postgresflex.Backup{}}, false},
189-
{"complete", args{outputFormat: "", backups: []postgresflex.Backup{
190+
{"standard", args{outputFormat: "", instanceLabel: "label", backups: []postgresflex.Backup{}}, false},
191+
{"complete", args{outputFormat: "", instanceLabel: "label", backups: []postgresflex.Backup{
190192
{
191193
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
192194
Id: utils.Ptr("id"),
193-
Labels: &[]string{"foo", "bar", "baz"},
195+
Labels: []string{"foo", "bar", "baz"},
194196
Name: utils.Ptr("name"),
195197
Options: &map[string]string{"test1": "test1", "test2": "test2"},
196198
Size: utils.Ptr(int64(42)),
@@ -199,7 +201,7 @@ func Test_outputResult(t *testing.T) {
199201
{
200202
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
201203
Id: utils.Ptr("id"),
202-
Labels: &[]string{"foo", "bar", "baz"},
204+
Labels: []string{"foo", "bar", "baz"},
203205
Name: utils.Ptr("name"),
204206
Options: &map[string]string{"test1": "test1", "test2": "test2"},
205207
Size: utils.Ptr(int64(42)),
@@ -211,7 +213,7 @@ func Test_outputResult(t *testing.T) {
211213
params := testparams.NewTestParams()
212214
for _, tt := range tests {
213215
t.Run(tt.name, func(t *testing.T) {
214-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.backups); (err != nil) != tt.wantErr {
216+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.instanceLabel, tt.args.backups); (err != nil) != tt.wantErr {
215217
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
216218
}
217219
})

internal/cmd/postgresflex/backup/update-schedule/update_schedule.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
88

99
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
10+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
1111

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

30-
InstanceId *string
31-
BackupSchedule *string
30+
InstanceId string
31+
BackupSchedule string
3232
}
3333

3434
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -57,10 +57,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5757
return err
5858
}
5959

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

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

101101
return &inputModel{
102102
GlobalFlagModel: globalFlags,
103-
InstanceId: flags.FlagToStringPointer(p, cmd, instanceIdFlag),
104-
BackupSchedule: flags.FlagToStringPointer(p, cmd, scheduleFlag),
103+
InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag),
104+
BackupSchedule: flags.FlagToStringValue(p, cmd, scheduleFlag),
105105
}, nil
106106
}
107107

108108
func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiUpdateBackupScheduleRequest {
109-
req := apiClient.UpdateBackupSchedule(ctx, model.ProjectId, model.Region, *model.InstanceId)
109+
req := apiClient.DefaultAPI.UpdateBackupSchedule(ctx, model.ProjectId, model.Region, model.InstanceId)
110110
req = req.UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{
111111
BackupSchedule: model.BackupSchedule,
112112
})

0 commit comments

Comments
 (0)