Skip to content

Commit 1d3dcd9

Browse files
feat(mongodbflex): migrate to v2 API
1 parent e52e822 commit 1d3dcd9

41 files changed

Lines changed: 535 additions & 515 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0
2626
github.com/stackitcloud/stackit-sdk-go/services/intake v0.7.1
2727
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2
28-
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8
28+
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0
2929
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6
3030
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5
3131
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,8 @@ github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2 h1:vr4atxFRT+EL+DqON
622622
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2/go.mod h1:CAPsiTX7osAImfrG5RnIjaJ/Iz3QpoBKuH2fS346wuQ=
623623
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.30.0 h1:LFIH1wAp633ZAJw/7H3F4nq1DZe0Qu3rlDeXhobZEZA=
624624
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.30.0/go.mod h1:joa89Y1dyn0j22FstRcIKfW2ada3FDxNfttxSvq27uY=
625-
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8 h1:S7t4wcT6SN8ZzdoY8d6VbF903zFpGjzqrU0FN27rJPg=
626-
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8/go.mod h1:CdrhFUsBO7/iJleCc2yQjDChIbG6YaxKNBQRNCjgcF4=
625+
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0 h1:SVd3WMmLAE0Jxk2SaRuM85DTOOXHycyMpZGx9vzqNkI=
626+
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0/go.mod h1:0hHEPiOEMAA23EzEl42Rm3FlyKIzkW+LWLvDkuFTZ+Q=
627627
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0 h1:UxnbsKm6PQV8Gudw/EhySaEh9q1xSaTG8mzJz1EvhnE=
628628
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0/go.mod h1:RFL4h6JZvpsyFYbdJ3+eINEkletzJQTfrPdd+yPT/fU=
629629
github.com/stackitcloud/stackit-sdk-go/services/observability v0.17.0 h1:LGwCvvST0fwUgZ6bOxYIfu45qqTgv421ZS07UhKjZL8=

internal/cmd/mongodbflex/backup/describe/describe.go

Lines changed: 10 additions & 6 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/mongodbflex"
10+
mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -61,7 +61,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6161
return err
6262
}
6363

64-
instanceLabel, err := mongoUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.InstanceId, model.Region)
64+
instanceLabel, err := mongoUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId, model.Region)
6565
if err != nil {
6666
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
6767
instanceLabel = model.InstanceId
@@ -75,13 +75,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7575
return fmt.Errorf("describe backup for MongoDB Flex instance: %w", err)
7676
}
7777

78-
restoreJobs, err := apiClient.ListRestoreJobs(ctx, model.ProjectId, model.InstanceId, model.Region).Execute()
78+
restoreJobs, err := apiClient.DefaultAPI.ListRestoreJobs(ctx, model.ProjectId, model.InstanceId, model.Region).Execute()
7979
if err != nil {
8080
return fmt.Errorf("get restore jobs for MongoDB Flex instance %q: %w", instanceLabel, err)
8181
}
8282

8383
restoreJobState := mongoUtils.GetRestoreStatus(model.BackupId, restoreJobs)
84-
return outputResult(params.Printer, model.OutputFormat, restoreJobState, *resp.Item)
84+
return outputResult(params.Printer, model.OutputFormat, restoreJobState, resp.Item)
8585
},
8686
}
8787
configureFlags(cmd)
@@ -114,11 +114,15 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
114114
}
115115

116116
func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex.APIClient) mongodbflex.ApiGetBackupRequest {
117-
req := apiClient.GetBackup(ctx, model.ProjectId, model.InstanceId, model.BackupId, model.Region)
117+
req := apiClient.DefaultAPI.GetBackup(ctx, model.ProjectId, model.InstanceId, model.BackupId, model.Region)
118118
return req
119119
}
120120

121-
func outputResult(p *print.Printer, outputFormat, restoreStatus string, backup mongodbflex.Backup) error {
121+
func outputResult(p *print.Printer, outputFormat, restoreStatus string, backup *mongodbflex.Backup) error {
122+
// allows passing empty backups but avoids having to pass large backup by value
123+
if backup == nil {
124+
backup = &mongodbflex.Backup{}
125+
}
122126
return p.OutputResult(outputFormat, backup, func() error {
123127
table := tables.NewTable()
124128
table.AddRow("ID", utils.PtrString(backup.Id))

internal/cmd/mongodbflex/backup/describe/describe_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/mongodbflex"
14+
mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api"
1515
)
1616

1717
const (
@@ -22,7 +22,7 @@ const (
2222
type testCtxKey struct{}
2323

2424
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
25-
var testClient = &mongodbflex.APIClient{}
25+
var testClient = &mongodbflex.APIClient{DefaultAPI: &mongodbflex.DefaultAPIService{}}
2626
var testProjectId = uuid.NewString()
2727
var testInstanceId = uuid.NewString()
2828

@@ -65,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6565
}
6666

6767
func fixtureRequest(mods ...func(request *mongodbflex.ApiGetBackupRequest)) mongodbflex.ApiGetBackupRequest {
68-
request := testClient.GetBackup(testCtx, testProjectId, testInstanceId, testBackupId, testRegion)
68+
request := testClient.DefaultAPI.GetBackup(testCtx, testProjectId, testInstanceId, testBackupId, testRegion)
6969
for _, mod := range mods {
7070
mod(&request)
7171
}
@@ -187,7 +187,7 @@ func TestBuildRequest(t *testing.T) {
187187

188188
diff := cmp.Diff(request, tt.expectedRequest,
189189
cmp.AllowUnexported(tt.expectedRequest),
190-
cmpopts.EquateComparable(testCtx),
190+
cmpopts.EquateComparable(testCtx, mongodbflex.DefaultAPIService{}),
191191
)
192192
if diff != "" {
193193
t.Fatalf("Data does not match: %s", diff)
@@ -199,7 +199,7 @@ func TestBuildRequest(t *testing.T) {
199199
func TestOutputResult(t *testing.T) {
200200
type args struct {
201201
outputFormat string
202-
backup mongodbflex.Backup
202+
backup *mongodbflex.Backup
203203
restoreStatus string
204204
}
205205
tests := []struct {
@@ -215,7 +215,7 @@ func TestOutputResult(t *testing.T) {
215215
{
216216
name: "set backup",
217217
args: args{
218-
backup: mongodbflex.Backup{},
218+
backup: &mongodbflex.Backup{},
219219
},
220220
wantErr: false,
221221
},

internal/cmd/mongodbflex/backup/list/list.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1919

2020
"github.com/spf13/cobra"
21-
"github.com/stackitcloud/stackit-sdk-go/services/mongodbflex"
21+
mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api"
2222
)
2323

2424
const (
@@ -63,7 +63,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6363
return err
6464
}
6565

66-
instanceLabel, err := mongodbflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, *model.InstanceId, model.Region)
66+
instanceLabel, err := mongodbflexUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, *model.InstanceId, model.Region)
6767
if err != nil {
6868
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
6969
instanceLabel = *model.InstanceId
@@ -75,9 +75,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7575
if err != nil {
7676
return fmt.Errorf("get backups for MongoDB Flex instance %q: %w", instanceLabel, err)
7777
}
78-
backups := utils.GetSliceFromPointer(resp.Items)
78+
backups := resp.Items
7979

80-
restoreJobs, err := apiClient.ListRestoreJobs(ctx, model.ProjectId, *model.InstanceId, model.Region).Execute()
80+
restoreJobs, err := apiClient.DefaultAPI.ListRestoreJobs(ctx, model.ProjectId, *model.InstanceId, model.Region).Execute()
8181
if err != nil {
8282
return fmt.Errorf("get restore jobs for MongoDB Flex instance %q: %w", instanceLabel, err)
8383
}
@@ -128,7 +128,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
128128
}
129129

130130
func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex.APIClient) mongodbflex.ApiListBackupsRequest {
131-
req := apiClient.ListBackups(ctx, model.ProjectId, *model.InstanceId, model.Region)
131+
req := apiClient.DefaultAPI.ListBackups(ctx, model.ProjectId, *model.InstanceId, model.Region)
132132
return req
133133
}
134134

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/google/go-cmp/cmp"
1313
"github.com/google/go-cmp/cmp/cmpopts"
1414
"github.com/google/uuid"
15-
"github.com/stackitcloud/stackit-sdk-go/services/mongodbflex"
15+
mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api"
1616
)
1717

1818
const (
@@ -22,7 +22,7 @@ const (
2222
type testCtxKey struct{}
2323

2424
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
25-
var testClient = &mongodbflex.APIClient{}
25+
var testClient = &mongodbflex.APIClient{DefaultAPI: &mongodbflex.DefaultAPIService{}}
2626
var testProjectId = uuid.NewString()
2727
var testInstanceId = uuid.NewString()
2828

@@ -56,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5656
}
5757

5858
func fixtureRequest(mods ...func(request *mongodbflex.ApiListBackupsRequest)) mongodbflex.ApiListBackupsRequest {
59-
request := testClient.ListBackups(testCtx, testProjectId, testInstanceId, testRegion)
59+
request := testClient.DefaultAPI.ListBackups(testCtx, testProjectId, testInstanceId, testRegion)
6060
for _, mod := range mods {
6161
mod(&request)
6262
}
@@ -166,7 +166,7 @@ func TestBuildRequest(t *testing.T) {
166166

167167
diff := cmp.Diff(request, tt.expectedRequest,
168168
cmp.AllowUnexported(tt.expectedRequest),
169-
cmpopts.EquateComparable(testCtx),
169+
cmpopts.EquateComparable(testCtx, mongodbflex.DefaultAPIService{}),
170170
)
171171
if diff != "" {
172172
t.Fatalf("Data does not match: %s", diff)

internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go

Lines changed: 5 additions & 5 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/mongodbflex"
10+
mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -63,7 +63,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6363
return err
6464
}
6565

66-
instanceLabel, err := mongodbflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, *model.InstanceId, model.Region)
66+
instanceLabel, err := mongodbflexUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, *model.InstanceId, model.Region)
6767
if err != nil {
6868
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
6969
instanceLabel = *model.InstanceId
@@ -75,11 +75,11 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7575
if err != nil {
7676
return fmt.Errorf("get restore jobs for MongoDB Flex instance %q: %w", instanceLabel, err)
7777
}
78-
if resp.Items == nil || len(*resp.Items) == 0 {
78+
if len(resp.Items) == 0 {
7979
cmd.Printf("No restore jobs found for instance %q\n", instanceLabel)
8080
return nil
8181
}
82-
restoreJobs := *resp.Items
82+
restoreJobs := resp.Items
8383

8484
// Truncate output
8585
if model.Limit != nil && len(restoreJobs) > int(*model.Limit) {
@@ -127,7 +127,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
127127
}
128128

129129
func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex.APIClient) mongodbflex.ApiListRestoreJobsRequest {
130-
req := apiClient.ListRestoreJobs(ctx, model.ProjectId, *model.InstanceId, model.Region)
130+
req := apiClient.DefaultAPI.ListRestoreJobs(ctx, model.ProjectId, *model.InstanceId, model.Region)
131131
return req
132132
}
133133

internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/google/go-cmp/cmp"
1313
"github.com/google/go-cmp/cmp/cmpopts"
1414
"github.com/google/uuid"
15-
"github.com/stackitcloud/stackit-sdk-go/services/mongodbflex"
15+
mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api"
1616
)
1717

1818
const (
@@ -22,7 +22,7 @@ const (
2222
type testCtxKey struct{}
2323

2424
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
25-
var testClient = &mongodbflex.APIClient{}
25+
var testClient = &mongodbflex.APIClient{DefaultAPI: &mongodbflex.DefaultAPIService{}}
2626
var testProjectId = uuid.NewString()
2727
var testInstanceId = uuid.NewString()
2828

@@ -56,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5656
}
5757

5858
func fixtureRequest(mods ...func(request *mongodbflex.ApiListRestoreJobsRequest)) mongodbflex.ApiListRestoreJobsRequest {
59-
request := testClient.ListRestoreJobs(testCtx, testProjectId, testInstanceId, testRegion)
59+
request := testClient.DefaultAPI.ListRestoreJobs(testCtx, testProjectId, testInstanceId, testRegion)
6060
for _, mod := range mods {
6161
mod(&request)
6262
}
@@ -166,7 +166,7 @@ func TestBuildRequest(t *testing.T) {
166166

167167
diff := cmp.Diff(request, tt.expectedRequest,
168168
cmp.AllowUnexported(tt.expectedRequest),
169-
cmpopts.EquateComparable(testCtx),
169+
cmpopts.EquateComparable(testCtx, mongodbflex.DefaultAPIService{}),
170170
)
171171
if diff != "" {
172172
t.Fatalf("Data does not match: %s", diff)

internal/cmd/mongodbflex/backup/restore/restore.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
1818

1919
"github.com/spf13/cobra"
20-
"github.com/stackitcloud/stackit-sdk-go/services/mongodbflex"
21-
"github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/wait"
20+
mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api"
21+
wait "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api/wait"
2222
)
2323

2424
const (
@@ -71,7 +71,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7171
return err
7272
}
7373

74-
instanceLabel, err := mongodbUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.InstanceId, model.Region)
74+
instanceLabel, err := mongodbUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId, model.Region)
7575
if err != nil {
7676
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
7777
instanceLabel = model.ProjectId
@@ -100,7 +100,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
100100

101101
if !model.Async {
102102
err := spinner.Run(params.Printer, "Restoring instance", func() error {
103-
_, err = wait.RestoreInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId, model.BackupId, model.Region).WaitWithContext(ctx)
103+
_, err = wait.RestoreInstanceWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId, model.BackupId, model.Region).WaitWithContext(ctx)
104104
return err
105105
})
106106
if err != nil {
@@ -125,7 +125,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
125125

126126
if !model.Async {
127127
err := spinner.Run(params.Printer, "Cloning instance", func() error {
128-
_, err = wait.CloneInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId, model.Region).WaitWithContext(ctx)
128+
_, err = wait.CloneInstanceWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId, model.Region).WaitWithContext(ctx)
129129
return err
130130
})
131131
if err != nil {
@@ -183,19 +183,19 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
183183
}
184184

185185
func buildRestoreRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex.APIClient) mongodbflex.ApiRestoreInstanceRequest {
186-
req := apiClient.RestoreInstance(ctx, model.ProjectId, model.InstanceId, model.Region)
186+
req := apiClient.DefaultAPI.RestoreInstance(ctx, model.ProjectId, model.InstanceId, model.Region)
187187
req = req.RestoreInstancePayload(mongodbflex.RestoreInstancePayload{
188-
BackupId: &model.BackupId,
189-
InstanceId: &model.BackupInstanceId,
188+
BackupId: model.BackupId,
189+
InstanceId: model.BackupInstanceId,
190190
})
191191
return req
192192
}
193193

194194
func buildCloneRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex.APIClient) mongodbflex.ApiCloneInstanceRequest {
195-
req := apiClient.CloneInstance(ctx, model.ProjectId, model.InstanceId, model.Region)
195+
req := apiClient.DefaultAPI.CloneInstance(ctx, model.ProjectId, model.InstanceId, model.Region)
196196
req = req.CloneInstancePayload(mongodbflex.CloneInstancePayload{
197197
Timestamp: &model.Timestamp,
198-
InstanceId: &model.BackupInstanceId,
198+
InstanceId: model.BackupInstanceId,
199199
})
200200
return req
201201
}

0 commit comments

Comments
 (0)