Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/stackit_server_backup_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ stackit server backup create [flags]
### Options

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

### Options inherited from parent commands
Expand Down
16 changes: 8 additions & 8 deletions docs/stackit_server_backup_schedule_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ stackit server backup schedule create [flags]
### Options

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

### Options inherited from parent commands
Expand Down
16 changes: 8 additions & 8 deletions docs/stackit_server_backup_schedule_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ stackit server backup schedule update SCHEDULE_ID [flags]
### Options

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

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.8.0
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.7.0
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.2
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,8 @@ github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.8.0 h1:T5gy5i+Nxrp
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.8.0/go.mod h1:iB27HtF0UcAugURc9w+nlNrtbAj7Mukw/ptAz+7p2WE=
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1 h1:U5rstX5e6Am2t+Ukv5K1Sbftzxt5aFALMa9YS4jCJoo=
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1/go.mod h1:2XA8PE05Qg6BL2YXO4XgfGI9qskJ3cicLE5Qq0aqDdY=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8 h1:LLyANBzE8sQa0/49tQBqq4sVLhNgwdqCeQm76srJHWw=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8/go.mod h1:/bmg57XZu+bGczzcoumrukiGMPGzI2mOyTT4BVIQUBs=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.7.0 h1:U3bm+RVHD1USpB6Fk9WNfPQxK0x0DY7ubusmRSh/A/8=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.7.0/go.mod h1:BJeafbecuocdirGCAJ2Vz/rPSK/LRrB5lPBEacqd1eU=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.2 h1:6C/iTPoYPCrZOc3JMmvyDNs4hm+JR5p9O3DIfFGgnbo=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.2/go.mod h1:/OHYZXQb9KXDdZK5J9C2YS6DJUD2i6ednZ1rK7zpDZ0=
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 h1:l1EDIlXce2C8JcbBDHVa6nZ4SjPTqmnALTgrhms+NKI=
Expand Down
23 changes: 11 additions & 12 deletions internal/cmd/server/backup/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (

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

"github.com/spf13/cobra"
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
Expand All @@ -16,10 +19,6 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/serverbackup/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
)

const (
Expand All @@ -36,7 +35,7 @@ type inputModel struct {

ServerId string
BackupName string
BackupRetentionPeriod int64
BackupRetentionPeriod int32
BackupVolumeIds []string
}

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

err := flags.MarkFlagsRequired(cmd, serverIdFlag, backupNameFlag)
Expand All @@ -121,7 +120,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
model := inputModel{
GlobalFlagModel: globalFlags,
ServerId: flags.FlagToStringValue(p, cmd, serverIdFlag),
BackupRetentionPeriod: flags.FlagWithDefaultToInt64Value(p, cmd, backupRetentionPeriodFlag),
BackupRetentionPeriod: flags.FlagWithDefaultToInt32Value(p, cmd, backupRetentionPeriodFlag),
BackupName: flags.FlagToStringValue(p, cmd, backupNameFlag),
BackupVolumeIds: flags.FlagToStringSliceValue(p, cmd, backupVolumeIdsFlag),
}
Expand All @@ -131,11 +130,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) (serverbackup.ApiCreateBackupRequest, error) {
req := apiClient.CreateBackup(ctx, model.ProjectId, model.ServerId, model.Region)
req := apiClient.DefaultAPI.CreateBackup(ctx, model.ProjectId, model.ServerId, model.Region)
payload := serverbackup.CreateBackupPayload{
Name: &model.BackupName,
RetentionPeriod: &model.BackupRetentionPeriod,
VolumeIds: &model.BackupVolumeIds,
Name: model.BackupName,
RetentionPeriod: model.BackupRetentionPeriod,
VolumeIds: model.BackupVolumeIds,
}
if model.BackupVolumeIds == nil {
payload.VolumeIds = nil
Expand All @@ -146,7 +145,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbacku

func outputResult(p *print.Printer, outputFormat, serverLabel string, resp serverbackup.BackupJob) error {
return p.OutputResult(outputFormat, resp, func() error {
p.Outputf("Triggered creation of server backup for server %s. Backup ID: %s\n", serverLabel, utils.PtrString(resp.Id))
p.Outputf("Triggered creation of server backup for server %s. Backup ID: %s\n", serverLabel, resp.Id)
return nil
})
}
25 changes: 12 additions & 13 deletions internal/cmd/server/backup/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import (
"context"
"testing"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
)

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serverbackup.APIClient{}
var testClient = &serverbackup.APIClient{DefaultAPI: &serverbackup.DefaultAPIService{}}

var testProjectId = uuid.NewString()
var testServerId = uuid.NewString()
Expand Down Expand Up @@ -49,7 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
},
ServerId: testServerId,
BackupName: "example-backup-name",
BackupRetentionPeriod: int64(14),
BackupRetentionPeriod: int32(14),
BackupVolumeIds: []string{testBackupVolumeId},
}
for _, mod := range mods {
Expand All @@ -59,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *serverbackup.ApiCreateBackupRequest)) serverbackup.ApiCreateBackupRequest {
request := testClient.CreateBackup(testCtx, testProjectId, testServerId, testRegion)
request := testClient.DefaultAPI.CreateBackup(testCtx, testProjectId, testServerId, testRegion)
request = request.CreateBackupPayload(fixturePayload())
for _, mod := range mods {
mod(&request)
Expand All @@ -69,9 +68,9 @@ func fixtureRequest(mods ...func(request *serverbackup.ApiCreateBackupRequest))

func fixturePayload(mods ...func(payload *serverbackup.CreateBackupPayload)) serverbackup.CreateBackupPayload {
payload := serverbackup.CreateBackupPayload{
Name: utils.Ptr("example-backup-name"),
RetentionPeriod: utils.Ptr(int64(14)),
VolumeIds: utils.Ptr([]string{testBackupVolumeId}),
Name: "example-backup-name",
RetentionPeriod: int32(14),
VolumeIds: []string{testBackupVolumeId},
}
for _, mod := range mods {
mod(&payload)
Expand Down Expand Up @@ -164,7 +163,7 @@ func TestBuildRequest(t *testing.T) {

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, serverbackup.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/server/backup/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"
)

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

func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) serverbackup.ApiDeleteBackupRequest {
req := apiClient.DeleteBackup(ctx, model.ProjectId, model.ServerId, model.Region, model.BackupId)
req := apiClient.DefaultAPI.DeleteBackup(ctx, model.ProjectId, model.ServerId, model.Region, model.BackupId)
return req
}
8 changes: 4 additions & 4 deletions internal/cmd/server/backup/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"
)

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serverbackup.APIClient{}
var testClient = &serverbackup.APIClient{DefaultAPI: &serverbackup.DefaultAPIService{}}
var testProjectId = uuid.NewString()
var testServerId = uuid.NewString()
var testBackupId = uuid.NewString()
Expand Down Expand Up @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

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

diff := cmp.Diff(request, tt.expectedRequest,
cmp.AllowUnexported(tt.expectedRequest),
cmpopts.EquateComparable(testCtx),
cmpopts.EquateComparable(testCtx, serverbackup.DefaultAPIService{}),
)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
Expand Down
24 changes: 14 additions & 10 deletions internal/cmd/server/backup/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api"
)

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

return outputResult(params.Printer, model.OutputFormat, *resp)
return outputResult(params.Printer, model.OutputFormat, resp)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -98,32 +98,36 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
}

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

func outputResult(p *print.Printer, outputFormat string, backup serverbackup.Backup) error {
func outputResult(p *print.Printer, outputFormat string, backup *serverbackup.Backup) error {
return p.OutputResult(outputFormat, backup, func() error {
if backup == nil {
return fmt.Errorf("backup is nil")
}

table := tables.NewTable()
table.AddRow("ID", utils.PtrString(backup.Id))
table.AddRow("ID", backup.Id)
table.AddSeparator()
table.AddRow("NAME", utils.PtrString(backup.Name))
table.AddRow("NAME", backup.Name)
table.AddSeparator()
table.AddRow("SIZE (GB)", utils.PtrString(backup.Size))
table.AddSeparator()
table.AddRow("STATUS", utils.PtrString(backup.Status))
table.AddRow("STATUS", backup.Status)
table.AddSeparator()
table.AddRow("CREATED AT", utils.PtrString(backup.CreatedAt))
table.AddRow("CREATED AT", backup.CreatedAt)
table.AddSeparator()
table.AddRow("EXPIRES AT", utils.PtrString(backup.ExpireAt))
table.AddRow("EXPIRES AT", backup.ExpireAt)
table.AddSeparator()

lastRestored := utils.PtrStringDefault(backup.LastRestoredAt, "")
table.AddRow("LAST RESTORED AT", lastRestored)
table.AddSeparator()
volBackups := ""
if backups := backup.VolumeBackups; backups != nil {
volBackups = strconv.Itoa(len(*backups))
volBackups = strconv.Itoa(len(backups))
}
table.AddRow("VOLUME BACKUPS", volBackups)
table.AddSeparator()
Expand Down
Loading
Loading