Skip to content

Commit f4e5858

Browse files
feat(mongodbflex): migrate to v2 API (#1467)
relates to STACKITCLI-379
1 parent 82f6b96 commit f4e5858

43 files changed

Lines changed: 694 additions & 673 deletions

Some content is hidden

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

docs/stackit_mongodbflex_instance_create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ stackit mongodbflex instance create [flags]
2828
```
2929
--acl strings The access control list (ACL). Must contain at least one valid subnet, for instance '0.0.0.0/0' for open access (discouraged), '1.2.3.0/24 for a public IP range of an organization, '1.2.3.4/32' for a single IP range, etc. (default [])
3030
--backup-schedule string Backup schedule (default "0 0/6 * * *")
31-
--cpu int Number of CPUs
31+
--cpu int32 Number of CPUs
3232
--flavor-id string ID of the flavor
3333
-h, --help Help for "stackit mongodbflex instance create"
3434
-n, --name string Instance name
35-
--ram int Amount of RAM (in GB)
35+
--ram int32 Amount of RAM (in GB)
3636
--storage-class string Storage class (default "premium-perf2-mongodb")
3737
--storage-size int Storage size (in GB) (default 10)
3838
--type string Instance type, (one of: [Replica, Sharded, Single]) (default "Replica")

docs/stackit_mongodbflex_instance_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ stackit mongodbflex instance update INSTANCE_ID [flags]
2525
```
2626
--acl strings Lists of IP networks in CIDR notation which are allowed to access this instance (default [])
2727
--backup-schedule string Backup schedule
28-
--cpu int Number of CPUs
28+
--cpu int32 Number of CPUs
2929
--flavor-id string ID of the flavor
3030
-h, --help Help for "stackit mongodbflex instance update"
3131
-n, --name string Instance name
32-
--ram int Amount of RAM (in GB)
32+
--ram int32 Amount of RAM (in GB)
3333
--storage-class string Storage class
3434
--storage-size int Storage size (in GB)
3535
--type string Instance type, (one of: [Replica, Sharded, Single])

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
@@ -618,8 +618,8 @@ github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2 h1:vr4atxFRT+EL+DqON
618618
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2/go.mod h1:CAPsiTX7osAImfrG5RnIjaJ/Iz3QpoBKuH2fS346wuQ=
619619
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.30.0 h1:LFIH1wAp633ZAJw/7H3F4nq1DZe0Qu3rlDeXhobZEZA=
620620
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.30.0/go.mod h1:joa89Y1dyn0j22FstRcIKfW2ada3FDxNfttxSvq27uY=
621-
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8 h1:S7t4wcT6SN8ZzdoY8d6VbF903zFpGjzqrU0FN27rJPg=
622-
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8/go.mod h1:CdrhFUsBO7/iJleCc2yQjDChIbG6YaxKNBQRNCjgcF4=
621+
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0 h1:SVd3WMmLAE0Jxk2SaRuM85DTOOXHycyMpZGx9vzqNkI=
622+
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0/go.mod h1:0hHEPiOEMAA23EzEl42Rm3FlyKIzkW+LWLvDkuFTZ+Q=
623623
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.9.0 h1:T+ll3lS0Kn18d8hTOrVAMKcQrXiab+Cuj0cTnAYHmj0=
624624
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.9.0/go.mod h1:QsPtoqAYvumyPU6ToX/5j1PbudN+VSTuvh6mp154ecM=
625625
github.com/stackitcloud/stackit-sdk-go/services/observability v0.24.0 h1:KhuWPXr1hl8BFLGLSi6wjxh5o6OQXH9amfquMhYQROU=

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

Lines changed: 9 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,12 +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 {
122122
return p.OutputResult(outputFormat, backup, func() error {
123+
if backup == nil {
124+
return fmt.Errorf("API response is nil")
125+
}
123126
table := tables.NewTable()
124127
table.AddRow("ID", utils.PtrString(backup.Id))
125128
table.AddSeparator()

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

Lines changed: 7 additions & 7 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 {
@@ -210,12 +210,12 @@ func TestOutputResult(t *testing.T) {
210210
{
211211
name: "empty",
212212
args: args{},
213-
wantErr: false,
213+
wantErr: true,
214214
},
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: 11 additions & 10 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,18 +75,15 @@ 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 {
79-
cmd.Printf("No restore jobs found for instance %q\n", instanceLabel)
80-
return nil
81-
}
82-
restoreJobs := *resp.Items
78+
79+
restoreJobs := resp.GetItems()
8380

8481
// Truncate output
8582
if model.Limit != nil && len(restoreJobs) > int(*model.Limit) {
8683
restoreJobs = restoreJobs[:*model.Limit]
8784
}
8885

89-
return outputResult(params.Printer, model.OutputFormat, restoreJobs)
86+
return outputResult(params.Printer, model.OutputFormat, instanceLabel, restoreJobs)
9087
},
9188
}
9289

@@ -127,12 +124,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
127124
}
128125

129126
func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex.APIClient) mongodbflex.ApiListRestoreJobsRequest {
130-
req := apiClient.ListRestoreJobs(ctx, model.ProjectId, *model.InstanceId, model.Region)
127+
req := apiClient.DefaultAPI.ListRestoreJobs(ctx, model.ProjectId, *model.InstanceId, model.Region)
131128
return req
132129
}
133130

134-
func outputResult(p *print.Printer, outputFormat string, restoreJobs []mongodbflex.RestoreInstanceStatus) error {
131+
func outputResult(p *print.Printer, outputFormat, instanceLabel string, restoreJobs []mongodbflex.RestoreInstanceStatus) error {
135132
return p.OutputResult(outputFormat, restoreJobs, func() error {
133+
if len(restoreJobs) == 0 {
134+
p.Outputf("No restore jobs found for instance %q\n", instanceLabel)
135+
return nil
136+
}
136137
table := tables.NewTable()
137138
table.SetHeader("ID", "BACKUP ID", "BACKUP INSTANCE ID", "DATE", "STATUS")
138139
for i := range restoreJobs {

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

Lines changed: 8 additions & 7 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)
@@ -177,8 +177,9 @@ func TestBuildRequest(t *testing.T) {
177177

178178
func TestOutputResult(t *testing.T) {
179179
type args struct {
180-
outputFormat string
181-
restoreJobs []mongodbflex.RestoreInstanceStatus
180+
outputFormat string
181+
instanceLabel string
182+
restoreJobs []mongodbflex.RestoreInstanceStatus
182183
}
183184
tests := []struct {
184185
name string
@@ -208,7 +209,7 @@ func TestOutputResult(t *testing.T) {
208209
params := testparams.NewTestParams()
209210
for _, tt := range tests {
210211
t.Run(tt.name, func(t *testing.T) {
211-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.restoreJobs); (err != nil) != tt.wantErr {
212+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.instanceLabel, tt.args.restoreJobs); (err != nil) != tt.wantErr {
212213
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
213214
}
214215
})

0 commit comments

Comments
 (0)