Skip to content

Commit d64ea5b

Browse files
feat(postgresflex): migrate to V2 api
Relates to STACKITCLI-374
1 parent 8c9edfa commit d64ea5b

37 files changed

Lines changed: 819 additions & 844 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: 8 additions & 8 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,19 +243,19 @@ 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
}{
253253
{"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{
254+
{"standard", args{outputFormat: "", backup: &postgresflex.Backup{StartTime: utils.Ptr(time.Now().Format(time.RFC3339))}}, false},
255+
{"complete", args{outputFormat: "", backup: &postgresflex.Backup{
256256
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
257257
Id: utils.Ptr("id"),
258-
Labels: &[]string{"foo", "bar", "baz"},
258+
Labels: []string{"foo", "bar", "baz"},
259259
Name: utils.Ptr("name"),
260260
Options: &map[string]string{"test1": "test1", "test2": "test2"},
261261
Size: utils.Ptr(int64(42)),

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

Lines changed: 5 additions & 5 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,11 +80,11 @@ 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 {
83+
if len(resp.Items) == 0 {
8484
params.Printer.Outputf("No backups found for instance %q", instanceLabel)
8585
return nil
8686
}
87-
backups := *resp.Items
87+
backups := resp.Items
8888

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

131131
func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiListBackupsRequest {
132-
req := apiClient.ListBackups(ctx, model.ProjectId, model.Region, *model.InstanceId)
132+
req := apiClient.DefaultAPI.ListBackups(ctx, model.ProjectId, model.Region, *model.InstanceId)
133133
return req
134134
}
135135

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/google/go-cmp/cmp"
1212
"github.com/google/go-cmp/cmp/cmpopts"
1313
"github.com/google/uuid"
14-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
14+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
1515

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

2222
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
23-
var testClient = &postgresflex.APIClient{}
23+
var testClient = &postgresflex.APIClient{DefaultAPI: &postgresflex.DefaultAPIService{}}
2424
var testProjectId = uuid.NewString()
2525
var testInstanceId = uuid.NewString()
2626
var testRegion = "eu01"
@@ -55,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5555
}
5656

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

166166
diff := cmp.Diff(request, tt.expectedRequest,
167167
cmp.AllowUnexported(tt.expectedRequest),
168-
cmpopts.EquateComparable(testCtx),
168+
cmpopts.EquateComparable(testCtx, postgresflex.DefaultAPIService{}),
169169
)
170170
if diff != "" {
171171
t.Fatalf("Data does not match: %s", diff)
@@ -190,7 +190,7 @@ func Test_outputResult(t *testing.T) {
190190
{
191191
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
192192
Id: utils.Ptr("id"),
193-
Labels: &[]string{"foo", "bar", "baz"},
193+
Labels: []string{"foo", "bar", "baz"},
194194
Name: utils.Ptr("name"),
195195
Options: &map[string]string{"test1": "test1", "test2": "test2"},
196196
Size: utils.Ptr(int64(42)),
@@ -199,7 +199,7 @@ func Test_outputResult(t *testing.T) {
199199
{
200200
EndTime: utils.Ptr(time.Now().Format(time.RFC3339)),
201201
Id: utils.Ptr("id"),
202-
Labels: &[]string{"foo", "bar", "baz"},
202+
Labels: []string{"foo", "bar", "baz"},
203203
Name: utils.Ptr("name"),
204204
Options: &map[string]string{"test1": "test1", "test2": "test2"},
205205
Size: utils.Ptr(int64(42)),

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
})

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ import (
66

77
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
88
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
9-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
109

1110
"github.com/google/go-cmp/cmp"
1211
"github.com/google/go-cmp/cmp/cmpopts"
1312
"github.com/google/uuid"
14-
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
13+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
1514
)
1615

1716
type testCtxKey struct{}
1817

1918
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
20-
var testClient = &postgresflex.APIClient{}
19+
var testClient = &postgresflex.APIClient{DefaultAPI: &postgresflex.DefaultAPIService{}}
2120
var testProjectId = uuid.NewString()
2221
var testInstanceId = uuid.NewString()
2322
var testSchedule = "0 0 * * *"
@@ -43,8 +42,8 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4342
Region: testRegion,
4443
Verbosity: globalflags.VerbosityDefault,
4544
},
46-
InstanceId: utils.Ptr(testInstanceId),
47-
BackupSchedule: &testSchedule,
45+
InstanceId: testInstanceId,
46+
BackupSchedule: testSchedule,
4847
}
4948
for _, mod := range mods {
5049
mod(model)
@@ -54,7 +53,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5453

5554
func fixturePayload(mods ...func(payload *postgresflex.UpdateBackupSchedulePayload)) postgresflex.UpdateBackupSchedulePayload {
5655
payload := postgresflex.UpdateBackupSchedulePayload{
57-
BackupSchedule: utils.Ptr(testSchedule),
56+
BackupSchedule: testSchedule,
5857
}
5958
for _, mod := range mods {
6059
mod(&payload)
@@ -63,7 +62,7 @@ func fixturePayload(mods ...func(payload *postgresflex.UpdateBackupSchedulePaylo
6362
}
6463

6564
func fixtureRequest(mods ...func(request *postgresflex.ApiUpdateBackupScheduleRequest)) postgresflex.ApiUpdateBackupScheduleRequest {
66-
request := testClient.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId)
65+
request := testClient.DefaultAPI.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId)
6766
request = request.UpdateBackupSchedulePayload(fixturePayload())
6867
for _, mod := range mods {
6968
mod(&request)
@@ -167,9 +166,9 @@ func TestBuildRequest(t *testing.T) {
167166
ProjectId: testProjectId,
168167
Region: testRegion,
169168
},
170-
InstanceId: utils.Ptr(testInstanceId),
169+
InstanceId: testInstanceId,
171170
},
172-
expectedRequest: testClient.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId).
171+
expectedRequest: testClient.DefaultAPI.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId).
173172
UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{}),
174173
},
175174
}
@@ -180,7 +179,7 @@ func TestBuildRequest(t *testing.T) {
180179

181180
diff := cmp.Diff(request, tt.expectedRequest,
182181
cmp.AllowUnexported(tt.expectedRequest),
183-
cmpopts.EquateComparable(testCtx),
182+
cmpopts.EquateComparable(testCtx, postgresflex.DefaultAPIService{}),
184183
)
185184
if diff != "" {
186185
t.Fatalf("Data does not match: %s", diff)

0 commit comments

Comments
 (0)