Skip to content

Commit 678c70e

Browse files
committed
chore(serverbackup): switch to new sdk structure
relates to STACKITCLI-354
1 parent eb09bc8 commit 678c70e

37 files changed

Lines changed: 333 additions & 314 deletions

docs/stackit_server_backup_create.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ stackit server backup create [flags]
2323
### Options
2424

2525
```
26-
-h, --help Help for "stackit server backup create"
27-
-b, --name string Backup name
28-
-d, --retention-period int Backup retention period (in days) (default 14)
29-
-s, --server-id string Server ID
30-
-i, --volume-ids strings Backup volume IDs, as comma separated UUID values. (default [])
26+
-h, --help Help for "stackit server backup create"
27+
-b, --name string Backup name
28+
-d, --retention-period int32 Backup retention period (in days) (default 14)
29+
-s, --server-id string Server ID
30+
-i, --volume-ids strings Backup volume IDs, as comma separated UUID values. (default [])
3131
```
3232

3333
### Options inherited from parent commands

docs/stackit_server_backup_schedule_create.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ stackit server backup schedule create [flags]
2323
### Options
2424

2525
```
26-
-b, --backup-name string Backup name
27-
-d, --backup-retention-period int Backup retention period (in days) (default 14)
28-
-n, --backup-schedule-name string Backup schedule name
29-
-i, --backup-volume-ids strings Backup volume IDs, as comma separated UUID values. (default [])
30-
-e, --enabled Is the server backup schedule enabled (default true)
31-
-h, --help Help for "stackit server backup schedule create"
32-
-r, --rrule string Backup RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
33-
-s, --server-id string Server ID
26+
-b, --backup-name string Backup name
27+
-d, --backup-retention-period int32 Backup retention period (in days) (default 14)
28+
-n, --backup-schedule-name string Backup schedule name
29+
-i, --backup-volume-ids strings Backup volume IDs, as comma separated UUID values. (default [])
30+
-e, --enabled Is the server backup schedule enabled (default true)
31+
-h, --help Help for "stackit server backup schedule create"
32+
-r, --rrule string Backup RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
33+
-s, --server-id string Server ID
3434
```
3535

3636
### Options inherited from parent commands

docs/stackit_server_backup_schedule_update.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ stackit server backup schedule update SCHEDULE_ID [flags]
2323
### Options
2424

2525
```
26-
-b, --backup-name string Backup name
27-
-d, --backup-retention-period int Backup retention period (in days) (default 14)
28-
-n, --backup-schedule-name string Backup schedule name
29-
-i, --backup-volume-ids strings Backup volume IDs, as comma separated UUID values. (default [])
30-
-e, --enabled Is the server backup schedule enabled (default true)
31-
-h, --help Help for "stackit server backup schedule update"
32-
-r, --rrule string Backup RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
33-
-s, --server-id string Server ID
26+
-b, --backup-name string Backup name
27+
-d, --backup-retention-period int32 Backup retention period (in days) (default 14)
28+
-n, --backup-schedule-name string Backup schedule name
29+
-i, --backup-volume-ids strings Backup volume IDs, as comma separated UUID values. (default [])
30+
-e, --enabled Is the server backup schedule enabled (default true)
31+
-h, --help Help for "stackit server backup schedule update"
32+
-r, --rrule string Backup RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
33+
-s, --server-id string Server ID
3434
```
3535

3636
### Options inherited from parent commands

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
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
34-
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8
34+
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.7.0
3535
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6
3636
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0
3737
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3 h1:AiGNJmpQ/f9
638638
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3/go.mod h1:U/q0V89fvCF2O1ZJfi68/Chie9YY/5s7xBHI1Klq7wA=
639639
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1 h1:U5rstX5e6Am2t+Ukv5K1Sbftzxt5aFALMa9YS4jCJoo=
640640
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1/go.mod h1:2XA8PE05Qg6BL2YXO4XgfGI9qskJ3cicLE5Qq0aqDdY=
641-
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8 h1:LLyANBzE8sQa0/49tQBqq4sVLhNgwdqCeQm76srJHWw=
642-
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8/go.mod h1:/bmg57XZu+bGczzcoumrukiGMPGzI2mOyTT4BVIQUBs=
641+
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.7.0 h1:U3bm+RVHD1USpB6Fk9WNfPQxK0x0DY7ubusmRSh/A/8=
642+
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.7.0/go.mod h1:BJeafbecuocdirGCAJ2Vz/rPSK/LRrB5lPBEacqd1eU=
643643
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6 h1:sQ3fdtUjgIL2Ul8nRYVVacHOwi5aSMTGGbYVL30oQBU=
644644
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6/go.mod h1:3fjlL+9YtuI9Oocl1ZeYIK48ImtY4DwPggFhqAygr7o=
645645
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 h1:l1EDIlXce2C8JcbBDHVa6nZ4SjPTqmnALTgrhms+NKI=

internal/cmd/server/backup/create/create.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88

99
iaasClient "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
1010

11+
"github.com/spf13/cobra"
12+
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"
13+
1114
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1215
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1316
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
@@ -16,10 +19,6 @@ import (
1619
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1720
iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils"
1821
"github.com/stackitcloud/stackit-cli/internal/pkg/services/serverbackup/client"
19-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
20-
21-
"github.com/spf13/cobra"
22-
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
2322
)
2423

2524
const (
@@ -36,7 +35,7 @@ type inputModel struct {
3635

3736
ServerId string
3837
BackupName string
39-
BackupRetentionPeriod int64
38+
BackupRetentionPeriod int32
4039
BackupVolumeIds []string
4140
}
4241

@@ -105,7 +104,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
105104
func configureFlags(cmd *cobra.Command) {
106105
cmd.Flags().VarP(flags.UUIDFlag(), serverIdFlag, "s", "Server ID")
107106
cmd.Flags().StringP(backupNameFlag, "b", "", "Backup name")
108-
cmd.Flags().Int64P(backupRetentionPeriodFlag, "d", defaultRetentionPeriod, "Backup retention period (in days)")
107+
cmd.Flags().Int32P(backupRetentionPeriodFlag, "d", defaultRetentionPeriod, "Backup retention period (in days)")
109108
cmd.Flags().VarP(flags.UUIDSliceFlag(), backupVolumeIdsFlag, "i", "Backup volume IDs, as comma separated UUID values.")
110109

111110
err := flags.MarkFlagsRequired(cmd, serverIdFlag, backupNameFlag)
@@ -121,7 +120,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
121120
model := inputModel{
122121
GlobalFlagModel: globalFlags,
123122
ServerId: flags.FlagToStringValue(p, cmd, serverIdFlag),
124-
BackupRetentionPeriod: flags.FlagWithDefaultToInt64Value(p, cmd, backupRetentionPeriodFlag),
123+
BackupRetentionPeriod: flags.FlagWithDefaultToInt32Value(p, cmd, backupRetentionPeriodFlag),
125124
BackupName: flags.FlagToStringValue(p, cmd, backupNameFlag),
126125
BackupVolumeIds: flags.FlagToStringSliceValue(p, cmd, backupVolumeIdsFlag),
127126
}
@@ -131,11 +130,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
131130
}
132131

133132
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) (serverbackup.ApiCreateBackupRequest, error) {
134-
req := apiClient.CreateBackup(ctx, model.ProjectId, model.ServerId, model.Region)
133+
req := apiClient.DefaultAPI.CreateBackup(ctx, model.ProjectId, model.ServerId, model.Region)
135134
payload := serverbackup.CreateBackupPayload{
136-
Name: &model.BackupName,
137-
RetentionPeriod: &model.BackupRetentionPeriod,
138-
VolumeIds: &model.BackupVolumeIds,
135+
Name: model.BackupName,
136+
RetentionPeriod: model.BackupRetentionPeriod,
137+
VolumeIds: model.BackupVolumeIds,
139138
}
140139
if model.BackupVolumeIds == nil {
141140
payload.VolumeIds = nil
@@ -146,7 +145,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbacku
146145

147146
func outputResult(p *print.Printer, outputFormat, serverLabel string, resp serverbackup.BackupJob) error {
148147
return p.OutputResult(outputFormat, resp, func() error {
149-
p.Outputf("Triggered creation of server backup for server %s. Backup ID: %s\n", serverLabel, utils.PtrString(resp.Id))
148+
p.Outputf("Triggered creation of server backup for server %s. Backup ID: %s\n", serverLabel, resp.Id)
150149
return nil
151150
})
152151
}

internal/cmd/server/backup/create/create_test.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
8-
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
9-
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
10-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
11-
127
"github.com/google/go-cmp/cmp"
138
"github.com/google/go-cmp/cmp/cmpopts"
149
"github.com/google/uuid"
15-
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
10+
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"
11+
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1615
)
1716

1817
type testCtxKey struct{}
1918

2019
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
var testClient = &serverbackup.APIClient{}
20+
var testClient = &serverbackup.APIClient{DefaultAPI: &serverbackup.DefaultAPIService{}}
2221

2322
var testProjectId = uuid.NewString()
2423
var testServerId = uuid.NewString()
@@ -49,7 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4948
},
5049
ServerId: testServerId,
5150
BackupName: "example-backup-name",
52-
BackupRetentionPeriod: int64(14),
51+
BackupRetentionPeriod: int32(14),
5352
BackupVolumeIds: []string{testBackupVolumeId},
5453
}
5554
for _, mod := range mods {
@@ -59,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5958
}
6059

6160
func fixtureRequest(mods ...func(request *serverbackup.ApiCreateBackupRequest)) serverbackup.ApiCreateBackupRequest {
62-
request := testClient.CreateBackup(testCtx, testProjectId, testServerId, testRegion)
61+
request := testClient.DefaultAPI.CreateBackup(testCtx, testProjectId, testServerId, testRegion)
6362
request = request.CreateBackupPayload(fixturePayload())
6463
for _, mod := range mods {
6564
mod(&request)
@@ -69,9 +68,9 @@ func fixtureRequest(mods ...func(request *serverbackup.ApiCreateBackupRequest))
6968

7069
func fixturePayload(mods ...func(payload *serverbackup.CreateBackupPayload)) serverbackup.CreateBackupPayload {
7170
payload := serverbackup.CreateBackupPayload{
72-
Name: utils.Ptr("example-backup-name"),
73-
RetentionPeriod: utils.Ptr(int64(14)),
74-
VolumeIds: utils.Ptr([]string{testBackupVolumeId}),
71+
Name: "example-backup-name",
72+
RetentionPeriod: int32(14),
73+
VolumeIds: []string{testBackupVolumeId},
7574
}
7675
for _, mod := range mods {
7776
mod(&payload)
@@ -164,7 +163,7 @@ func TestBuildRequest(t *testing.T) {
164163

165164
diff := cmp.Diff(request, tt.expectedRequest,
166165
cmp.AllowUnexported(tt.expectedRequest),
167-
cmpopts.EquateComparable(testCtx),
166+
cmpopts.EquateComparable(testCtx, serverbackup.DefaultAPIService{}),
168167
)
169168
if diff != "" {
170169
t.Fatalf("Data does not match: %s", diff)

internal/cmd/server/backup/delete/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1717

1818
"github.com/spf13/cobra"
19-
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
19+
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"
2020
)
2121

2222
const (
@@ -101,6 +101,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
101101
}
102102

103103
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) serverbackup.ApiDeleteBackupRequest {
104-
req := apiClient.DeleteBackup(ctx, model.ProjectId, model.ServerId, model.Region, model.BackupId)
104+
req := apiClient.DefaultAPI.DeleteBackup(ctx, model.ProjectId, model.ServerId, model.Region, model.BackupId)
105105
return req
106106
}

internal/cmd/server/backup/delete/delete_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
"github.com/google/go-cmp/cmp"
1111
"github.com/google/go-cmp/cmp/cmpopts"
1212
"github.com/google/uuid"
13-
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
13+
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"
1414
)
1515

1616
type testCtxKey struct{}
1717

1818
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
19-
var testClient = &serverbackup.APIClient{}
19+
var testClient = &serverbackup.APIClient{DefaultAPI: &serverbackup.DefaultAPIService{}}
2020
var testProjectId = uuid.NewString()
2121
var testServerId = uuid.NewString()
2222
var testBackupId = uuid.NewString()
@@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6161
}
6262

6363
func fixtureRequest(mods ...func(request *serverbackup.ApiDeleteBackupRequest)) serverbackup.ApiDeleteBackupRequest {
64-
request := testClient.DeleteBackup(testCtx, testProjectId, testServerId, testRegion, testBackupId)
64+
request := testClient.DefaultAPI.DeleteBackup(testCtx, testProjectId, testServerId, testRegion, testBackupId)
6565
for _, mod := range mods {
6666
mod(&request)
6767
}
@@ -153,7 +153,7 @@ func TestBuildRequest(t *testing.T) {
153153

154154
diff := cmp.Diff(request, tt.expectedRequest,
155155
cmp.AllowUnexported(tt.expectedRequest),
156-
cmpopts.EquateComparable(testCtx),
156+
cmpopts.EquateComparable(testCtx, serverbackup.DefaultAPIService{}),
157157
)
158158
if diff != "" {
159159
t.Fatalf("Data does not match: %s", diff)

internal/cmd/server/backup/describe/describe.go

Lines changed: 14 additions & 10 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/serverbackup"
21+
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"
2222
)
2323

2424
const (
@@ -65,7 +65,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6565
return fmt.Errorf("read server backup: %w", err)
6666
}
6767

68-
return outputResult(params.Printer, model.OutputFormat, *resp)
68+
return outputResult(params.Printer, model.OutputFormat, resp)
6969
},
7070
}
7171
configureFlags(cmd)
@@ -98,32 +98,36 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
9898
}
9999

100100
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) serverbackup.ApiGetBackupRequest {
101-
req := apiClient.GetBackup(ctx, model.ProjectId, model.ServerId, model.Region, model.BackupId)
101+
req := apiClient.DefaultAPI.GetBackup(ctx, model.ProjectId, model.ServerId, model.Region, model.BackupId)
102102
return req
103103
}
104104

105-
func outputResult(p *print.Printer, outputFormat string, backup serverbackup.Backup) error {
105+
func outputResult(p *print.Printer, outputFormat string, backup *serverbackup.Backup) error {
106106
return p.OutputResult(outputFormat, backup, func() error {
107+
if backup == nil {
108+
return fmt.Errorf("backup is nil")
109+
}
110+
107111
table := tables.NewTable()
108-
table.AddRow("ID", utils.PtrString(backup.Id))
112+
table.AddRow("ID", backup.Id)
109113
table.AddSeparator()
110-
table.AddRow("NAME", utils.PtrString(backup.Name))
114+
table.AddRow("NAME", backup.Name)
111115
table.AddSeparator()
112116
table.AddRow("SIZE (GB)", utils.PtrString(backup.Size))
113117
table.AddSeparator()
114-
table.AddRow("STATUS", utils.PtrString(backup.Status))
118+
table.AddRow("STATUS", backup.Status)
115119
table.AddSeparator()
116-
table.AddRow("CREATED AT", utils.PtrString(backup.CreatedAt))
120+
table.AddRow("CREATED AT", backup.CreatedAt)
117121
table.AddSeparator()
118-
table.AddRow("EXPIRES AT", utils.PtrString(backup.ExpireAt))
122+
table.AddRow("EXPIRES AT", backup.ExpireAt)
119123
table.AddSeparator()
120124

121125
lastRestored := utils.PtrStringDefault(backup.LastRestoredAt, "")
122126
table.AddRow("LAST RESTORED AT", lastRestored)
123127
table.AddSeparator()
124128
volBackups := ""
125129
if backups := backup.VolumeBackups; backups != nil {
126-
volBackups = strconv.Itoa(len(*backups))
130+
volBackups = strconv.Itoa(len(backups))
127131
}
128132
table.AddRow("VOLUME BACKUPS", volBackups)
129133
table.AddSeparator()

0 commit comments

Comments
 (0)