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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.13.1
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.0.0
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.2
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v0.6.0
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.0.1
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.0.0
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.6.1
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.0.0 h1:tKUyddNszci
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.0.0/go.mod h1:5n31cpeYcz2DSax4ygpZICEHDoHCTbWHrNGNYWwlRA8=
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.2 h1:SZoWUDUA8foNbu+cwRa67VxJXJJx4M8oiHeykVh8Wlg=
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.2/go.mod h1:PrD0nNG94Dd5D9pu7HJ0bAg8ccDz6/7KaIts7K9p7as=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v0.6.0 h1:cESGAkm0ftADRBfdbiyx3pp/KVQ8JgmUQdRzpwG61wE=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v0.6.0/go.mod h1:aYPLsiImzWaYXEfYIZ0wJnV56PwcR+buy8Xu9jjbfGA=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.0.1 h1:qujhShugc1290NQlPoNqsembqzot8aTToAdSsJg5WrM=
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.0.1/go.mod h1:e1fsQL24gTPXcMWptuslNscawmXv/PLUAFuw+sOofbc=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.0.0 h1:a8logPoRcMCgwa9rCtuzWF6DLiuCIdJgcacZKThFsks=
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.0.0/go.mod h1:zDdYYQVHGlju9cnMISX/Ty73Yh/qYcZGcJSOYWRZCbw=
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.6.1 h1:VKgxgjsbaUVMCnntq+MLQ/c1Emn5crVr11B3gJnyHN4=
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/backup/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) (serverbackup.ApiCreateBackupRequest, error) {
req := apiClient.CreateBackup(ctx, model.ProjectId, model.ServerId)
req := apiClient.CreateBackup(ctx, model.ProjectId, model.ServerId, model.Region)
payload := serverbackup.CreateBackupPayload{
Name: &model.BackupName,
RetentionPeriod: &model.BackupRetentionPeriod,
Expand Down
15 changes: 8 additions & 7 deletions internal/cmd/server/backup/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
Expand All @@ -24,10 +22,12 @@ var testClient = &serverbackup.APIClient{}
var testProjectId = uuid.NewString()
var testServerId = uuid.NewString()
var testBackupVolumeId = uuid.NewString()
var testRegion = "eu01"

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
projectIdFlag: testProjectId,
globalflags.ProjectIdFlag: testProjectId,
globalflags.RegionFlag: testRegion,
serverIdFlag: testServerId,
backupNameFlag: "example-backup-name",
backupRetentionPeriodFlag: "14",
Expand All @@ -43,6 +43,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Region: testRegion,
Verbosity: globalflags.VerbosityDefault,
},
ServerId: testServerId,
Expand All @@ -57,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)
request := testClient.CreateBackup(testCtx, testProjectId, testServerId, testRegion)
request = request.CreateBackupPayload(fixturePayload())
for _, mod := range mods {
mod(&request)
Expand Down Expand Up @@ -107,21 +108,21 @@ func TestParseInput(t *testing.T) {
{
description: "project id missing",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, projectIdFlag)
delete(flagValues, globalflags.ProjectIdFlag)
}),
isValid: false,
},
{
description: "project id invalid 1",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = ""
flagValues[globalflags.ProjectIdFlag] = ""
}),
isValid: false,
},
{
description: "project id invalid 2",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = "invalid-uuid"
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
}),
isValid: false,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/backup/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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.BackupId)
req := apiClient.DeleteBackup(ctx, model.ProjectId, model.ServerId, model.Region, model.BackupId)
return req
}
17 changes: 9 additions & 8 deletions internal/cmd/server/backup/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serverbackup.APIClient{}
var testProjectId = uuid.NewString()
var testServerId = uuid.NewString()
var testBackupId = uuid.NewString()
var testRegion = "eu01"

func fixtureArgValues(mods ...func(argValues []string)) []string {
argValues := []string{
Expand All @@ -35,8 +34,9 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
projectIdFlag: testProjectId,
serverIdFlag: testServerId,
globalflags.ProjectIdFlag: testProjectId,
globalflags.RegionFlag: testRegion,
serverIdFlag: testServerId,
}
for _, mod := range mods {
mod(flagValues)
Expand All @@ -48,6 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Region: testRegion,
Verbosity: globalflags.VerbosityDefault,
},
ServerId: testServerId,
Expand All @@ -60,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, testBackupId)
request := testClient.DeleteBackup(testCtx, testProjectId, testServerId, testRegion, testBackupId)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -104,23 +105,23 @@ func TestParseInput(t *testing.T) {
description: "project id missing",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, projectIdFlag)
delete(flagValues, globalflags.ProjectIdFlag)
}),
isValid: false,
},
{
description: "project id invalid 1",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = ""
flagValues[globalflags.ProjectIdFlag] = ""
}),
isValid: false,
},
{
description: "project id invalid 2",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = "invalid-uuid"
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
}),
isValid: false,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/backup/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ 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.BackupId)
req := apiClient.GetBackup(ctx, model.ProjectId, model.ServerId, model.Region, model.BackupId)
return req
}

Expand Down
17 changes: 9 additions & 8 deletions internal/cmd/server/backup/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serverbackup.APIClient{}
var testProjectId = uuid.NewString()
var testServerId = uuid.NewString()
var testBackupId = uuid.NewString()
var testRegion = "eu01"

func fixtureArgValues(mods ...func(argValues []string)) []string {
argValues := []string{
Expand All @@ -35,8 +34,9 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
projectIdFlag: testProjectId,
serverIdFlag: testServerId,
globalflags.ProjectIdFlag: testProjectId,
globalflags.RegionFlag: testRegion,
serverIdFlag: testServerId,
}
for _, mod := range mods {
mod(flagValues)
Expand All @@ -48,6 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Region: testRegion,
Verbosity: globalflags.VerbosityDefault,
},
ServerId: testServerId,
Expand All @@ -60,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *serverbackup.ApiGetBackupRequest)) serverbackup.ApiGetBackupRequest {
request := testClient.GetBackup(testCtx, testProjectId, testServerId, testBackupId)
request := testClient.GetBackup(testCtx, testProjectId, testServerId, testRegion, testBackupId)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -104,23 +105,23 @@ func TestParseInput(t *testing.T) {
description: "project id missing",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, projectIdFlag)
delete(flagValues, globalflags.ProjectIdFlag)
}),
isValid: false,
},
{
description: "project id invalid 1",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = ""
flagValues[globalflags.ProjectIdFlag] = ""
}),
isValid: false,
},
{
description: "project id invalid 2",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = "invalid-uuid"
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
}),
isValid: false,
},
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/server/backup/disable/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
}
}

canDisable, err := serverbackupUtils.CanDisableBackupService(ctx, apiClient, model.ProjectId, model.ServerId)
canDisable, err := serverbackupUtils.CanDisableBackupService(ctx, apiClient, model.ProjectId, model.ServerId, model.Region)
if err != nil {
return err
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
return &model, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) serverbackup.ApiDisableServiceRequest {
req := apiClient.DisableService(ctx, model.ProjectId, model.ServerId)
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) serverbackup.ApiDisableServiceResourceRequest {
req := apiClient.DisableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region)
return req
}
19 changes: 10 additions & 9 deletions internal/cmd/server/backup/disable/disable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/serverbackup"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &serverbackup.APIClient{}
var testProjectId = uuid.NewString()
var testServerId = uuid.NewString()
var testRegion = "eu01"

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
projectIdFlag: testProjectId,
globalflags.ProjectIdFlag: testProjectId,
globalflags.RegionFlag: testRegion,
}
for _, mod := range mods {
mod(flagValues)
Expand All @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Region: testRegion,
Verbosity: globalflags.VerbosityDefault,
},
ServerId: testServerId,
Expand All @@ -47,8 +48,8 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
return model
}

func fixtureRequest(mods ...func(request *serverbackup.ApiDisableServiceRequest)) serverbackup.ApiDisableServiceRequest {
request := testClient.DisableService(testCtx, testProjectId, testServerId)
func fixtureRequest(mods ...func(request *serverbackup.ApiDisableServiceResourceRequest)) serverbackup.ApiDisableServiceResourceRequest {
request := testClient.DisableServiceResource(testCtx, testProjectId, testServerId, testRegion)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -78,21 +79,21 @@ func TestParseInput(t *testing.T) {
{
description: "project id missing",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, projectIdFlag)
delete(flagValues, globalflags.ProjectIdFlag)
}),
isValid: false,
},
{
description: "project id invalid 1",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = ""
flagValues[globalflags.ProjectIdFlag] = ""
}),
isValid: false,
},
{
description: "project id invalid 2",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = "invalid-uuid"
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
}),
isValid: false,
},
Expand Down Expand Up @@ -148,7 +149,7 @@ func TestBuildRequest(t *testing.T) {
tests := []struct {
description string
model *inputModel
expectedRequest serverbackup.ApiDisableServiceRequest
expectedRequest serverbackup.ApiDisableServiceResourceRequest
}{
{
description: "base",
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/server/backup/enable/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
return &model, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) serverbackup.ApiEnableServiceRequest {
payload := serverbackup.EnableServicePayload{}
req := apiClient.EnableService(ctx, model.ProjectId, model.ServerId).EnableServicePayload(payload)
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbackup.APIClient) serverbackup.ApiEnableServiceResourceRequest {
payload := serverbackup.EnableServiceResourcePayload{}
req := apiClient.EnableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region).EnableServiceResourcePayload(payload)
return req
}
Loading