From d6992c52942f6bcfcb49dd1d1cc811d46d9572ed Mon Sep 17 00:00:00 2001 From: Ruben Hoenle Date: Fri, 21 Mar 2025 17:14:32 +0100 Subject: [PATCH 1/3] chore(server): regional adjustment for server update relates to STACKITCLI-128 --- go.mod | 2 +- go.sum | 4 +-- .../cmd/server/os-update/create/create.go | 2 +- .../server/os-update/create/create_test.go | 20 +++++++------ .../cmd/server/os-update/describe/describe.go | 2 +- .../os-update/describe/describe_test.go | 18 +++++++----- .../cmd/server/os-update/disable/disable.go | 4 +-- .../server/os-update/disable/disable_test.go | 20 +++++++------ .../cmd/server/os-update/enable/enable.go | 6 ++-- .../server/os-update/enable/enable_test.go | 20 +++++++------ internal/cmd/server/os-update/list/list.go | 2 +- .../cmd/server/os-update/list/list_test.go | 20 +++++++------ .../os-update/schedule/create/create.go | 2 +- .../os-update/schedule/create/create_test.go | 26 +++++++++-------- .../os-update/schedule/delete/delete.go | 2 +- .../os-update/schedule/delete/delete_test.go | 20 +++++++------ .../os-update/schedule/describe/describe.go | 2 +- .../schedule/describe/describe_test.go | 20 +++++++------ .../server/os-update/schedule/list/list.go | 2 +- .../os-update/schedule/list/list_test.go | 20 +++++++------ .../os-update/schedule/update/update.go | 4 +-- .../os-update/schedule/update/update_test.go | 28 +++++++++++-------- 22 files changed, 143 insertions(+), 103 deletions(-) diff --git a/go.mod b/go.mod index 422df11f7..6dc89a63d 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( 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/serverupdate v0.5.0 + 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 github.com/stackitcloud/stackit-sdk-go/services/ske v0.22.1 diff --git a/go.sum b/go.sum index 5f4cb3f28..05b13d4a3 100644 --- a/go.sum +++ b/go.sum @@ -147,8 +147,8 @@ github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.2 h1:SZoWUD 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/serverupdate v0.5.0 h1:TMUxDh8XGgWUpnWo7GsawVq2ICDsy/r8dMlfC26MR5g= -github.com/stackitcloud/stackit-sdk-go/services/serverupdate v0.5.0/go.mod h1:giHnHz3kHeLY8Av9MZLsyJlaTXYz+BuGqdP/SKB5Vo0= +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= github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.6.1/go.mod h1:vn6xmMRxYgEoBhYEy6i2SY2qbeDKjs4IVNdnQHcQpBc= github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.0.1 h1:7yY68QuntatwRG6ri65FlfeewACChLVbLp67wHCS8Go= diff --git a/internal/cmd/server/os-update/create/create.go b/internal/cmd/server/os-update/create/create.go index 9c4a1cbf9..090a39247 100644 --- a/internal/cmd/server/os-update/create/create.go +++ b/internal/cmd/server/os-update/create/create.go @@ -128,7 +128,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) (serverupdate.ApiCreateUpdateRequest, error) { - req := apiClient.CreateUpdate(ctx, model.ProjectId, model.ServerId) + req := apiClient.CreateUpdate(ctx, model.ProjectId, model.ServerId, model.Region) payload := serverupdate.CreateUpdatePayload{ MaintenanceWindow: &model.MaintenanceWindow, } diff --git a/internal/cmd/server/os-update/create/create_test.go b/internal/cmd/server/os-update/create/create_test.go index e2a38ea36..9dd635e70 100644 --- a/internal/cmd/server/os-update/create/create_test.go +++ b/internal/cmd/server/os-update/create/create_test.go @@ -14,7 +14,9 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" +) type testCtxKey struct{} @@ -26,9 +28,10 @@ var testServerId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ - projectIdFlag: testProjectId, - serverIdFlag: testServerId, - maintenanceWindowFlag: "13", + globalflags.ProjectIdFlag: testProjectId, + globalflags.RegionFlag: testRegion, + serverIdFlag: testServerId, + maintenanceWindowFlag: "13", } for _, mod := range mods { mod(flagValues) @@ -40,6 +43,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, ServerId: testServerId, @@ -52,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *serverupdate.ApiCreateUpdateRequest)) serverupdate.ApiCreateUpdateRequest { - request := testClient.CreateUpdate(testCtx, testProjectId, testServerId) + request := testClient.CreateUpdate(testCtx, testProjectId, testServerId, testRegion) request = request.CreateUpdatePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -102,21 +106,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, }, diff --git a/internal/cmd/server/os-update/describe/describe.go b/internal/cmd/server/os-update/describe/describe.go index f2f768651..7260131ff 100644 --- a/internal/cmd/server/os-update/describe/describe.go +++ b/internal/cmd/server/os-update/describe/describe.go @@ -104,7 +104,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiGetUpdateRequest { - req := apiClient.GetUpdate(ctx, model.ProjectId, model.ServerId, model.UpdateId) + req := apiClient.GetUpdate(ctx, model.ProjectId, model.ServerId, model.UpdateId, model.Region) return req } diff --git a/internal/cmd/server/os-update/describe/describe_test.go b/internal/cmd/server/os-update/describe/describe_test.go index fb345e40a..741bbe6dc 100644 --- a/internal/cmd/server/os-update/describe/describe_test.go +++ b/internal/cmd/server/os-update/describe/describe_test.go @@ -13,7 +13,9 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" +) type testCtxKey struct{} @@ -35,8 +37,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) @@ -48,6 +51,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, ServerId: testServerId, @@ -60,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *serverupdate.ApiGetUpdateRequest)) serverupdate.ApiGetUpdateRequest { - request := testClient.GetUpdate(testCtx, testProjectId, testServerId, testUpdateId) + request := testClient.GetUpdate(testCtx, testProjectId, testServerId, testUpdateId, testRegion) for _, mod := range mods { mod(&request) } @@ -104,7 +108,7 @@ 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, }, @@ -112,7 +116,7 @@ func TestParseInput(t *testing.T) { description: "project id invalid 1", argValues: fixtureArgValues(), flagValues: fixtureFlagValues(func(flagValues map[string]string) { - flagValues[projectIdFlag] = "" + flagValues[globalflags.ProjectIdFlag] = "" }), isValid: false, }, @@ -120,7 +124,7 @@ func TestParseInput(t *testing.T) { 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, }, diff --git a/internal/cmd/server/os-update/disable/disable.go b/internal/cmd/server/os-update/disable/disable.go index a55ab7e9d..f0270b0cd 100644 --- a/internal/cmd/server/os-update/disable/disable.go +++ b/internal/cmd/server/os-update/disable/disable.go @@ -115,7 +115,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { return &model, nil } -func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiDisableServiceRequest { - req := apiClient.DisableService(ctx, model.ProjectId, model.ServerId) +func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiDisableServiceResourceRequest { + req := apiClient.DisableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region) return req } diff --git a/internal/cmd/server/os-update/disable/disable_test.go b/internal/cmd/server/os-update/disable/disable_test.go index 6560a7fae..566300e33 100644 --- a/internal/cmd/server/os-update/disable/disable_test.go +++ b/internal/cmd/server/os-update/disable/disable_test.go @@ -14,7 +14,9 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" +) type testCtxKey struct{} @@ -25,7 +27,8 @@ var testServerId = uuid.NewString() 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) @@ -37,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, ServerId: testServerId, @@ -47,8 +51,8 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *serverupdate.ApiDisableServiceRequest)) serverupdate.ApiDisableServiceRequest { - request := testClient.DisableService(testCtx, testProjectId, testServerId) +func fixtureRequest(mods ...func(request *serverupdate.ApiDisableServiceResourceRequest)) serverupdate.ApiDisableServiceResourceRequest { + request := testClient.DisableServiceResource(testCtx, testProjectId, testServerId, testRegion) for _, mod := range mods { mod(&request) } @@ -78,21 +82,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, }, @@ -148,7 +152,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest serverupdate.ApiDisableServiceRequest + expectedRequest serverupdate.ApiDisableServiceResourceRequest }{ { description: "base", diff --git a/internal/cmd/server/os-update/enable/enable.go b/internal/cmd/server/os-update/enable/enable.go index 0dc7cb0f6..c255c778e 100644 --- a/internal/cmd/server/os-update/enable/enable.go +++ b/internal/cmd/server/os-update/enable/enable.go @@ -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 *serverupdate.APIClient) serverupdate.ApiEnableServiceRequest { - payload := serverupdate.EnableServicePayload{} - req := apiClient.EnableService(ctx, model.ProjectId, model.ServerId).EnableServicePayload(payload) +func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiEnableServiceResourceRequest { + payload := serverupdate.EnableServiceResourcePayload{} + req := apiClient.EnableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region).EnableServiceResourcePayload(payload) return req } diff --git a/internal/cmd/server/os-update/enable/enable_test.go b/internal/cmd/server/os-update/enable/enable_test.go index 6e55c1c77..d35251a70 100644 --- a/internal/cmd/server/os-update/enable/enable_test.go +++ b/internal/cmd/server/os-update/enable/enable_test.go @@ -14,7 +14,9 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" +) type testCtxKey struct{} @@ -25,7 +27,8 @@ var testServerId = uuid.NewString() 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) @@ -37,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, ServerId: testServerId, @@ -47,8 +51,8 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func fixtureRequest(mods ...func(request *serverupdate.ApiEnableServiceRequest)) serverupdate.ApiEnableServiceRequest { - request := testClient.EnableService(testCtx, testProjectId, testServerId).EnableServicePayload(serverupdate.EnableServicePayload{}) +func fixtureRequest(mods ...func(request *serverupdate.ApiEnableServiceResourceRequest)) serverupdate.ApiEnableServiceResourceRequest { + request := testClient.EnableServiceResource(testCtx, testProjectId, testServerId, testRegion).EnableServiceResourcePayload(serverupdate.EnableServiceResourcePayload{}) for _, mod := range mods { mod(&request) } @@ -78,21 +82,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, }, @@ -148,7 +152,7 @@ func TestBuildRequest(t *testing.T) { tests := []struct { description string model *inputModel - expectedRequest serverupdate.ApiEnableServiceRequest + expectedRequest serverupdate.ApiEnableServiceResourceRequest }{ { description: "base", diff --git a/internal/cmd/server/os-update/list/list.go b/internal/cmd/server/os-update/list/list.go index af4f15030..e1435badc 100644 --- a/internal/cmd/server/os-update/list/list.go +++ b/internal/cmd/server/os-update/list/list.go @@ -135,7 +135,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiListUpdatesRequest { - req := apiClient.ListUpdates(ctx, model.ProjectId, model.ServerId) + req := apiClient.ListUpdates(ctx, model.ProjectId, model.ServerId, model.Region) return req } diff --git a/internal/cmd/server/os-update/list/list_test.go b/internal/cmd/server/os-update/list/list_test.go index 4b6df9161..36205f88d 100644 --- a/internal/cmd/server/os-update/list/list_test.go +++ b/internal/cmd/server/os-update/list/list_test.go @@ -14,7 +14,9 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" +) type testCtxKey struct{} @@ -25,9 +27,10 @@ var testServerId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ - projectIdFlag: testProjectId, - limitFlag: "10", - serverIdFlag: testServerId, + globalflags.ProjectIdFlag: testProjectId, + globalflags.RegionFlag: testRegion, + limitFlag: "10", + serverIdFlag: testServerId, } for _, mod := range mods { mod(flagValues) @@ -39,6 +42,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), @@ -51,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *serverupdate.ApiListUpdatesRequest)) serverupdate.ApiListUpdatesRequest { - request := testClient.ListUpdates(testCtx, testProjectId, testServerId) + request := testClient.ListUpdates(testCtx, testProjectId, testServerId, testRegion) for _, mod := range mods { mod(&request) } @@ -79,21 +83,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, }, diff --git a/internal/cmd/server/os-update/schedule/create/create.go b/internal/cmd/server/os-update/schedule/create/create.go index e61003a95..2f30e876f 100644 --- a/internal/cmd/server/os-update/schedule/create/create.go +++ b/internal/cmd/server/os-update/schedule/create/create.go @@ -146,7 +146,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) (serverupdate.ApiCreateUpdateScheduleRequest, error) { - req := apiClient.CreateUpdateSchedule(ctx, model.ProjectId, model.ServerId) + req := apiClient.CreateUpdateSchedule(ctx, model.ProjectId, model.ServerId, model.Region) req = req.CreateUpdateSchedulePayload(serverupdate.CreateUpdateSchedulePayload{ Enabled: &model.Enabled, Name: &model.ScheduleName, diff --git a/internal/cmd/server/os-update/schedule/create/create_test.go b/internal/cmd/server/os-update/schedule/create/create_test.go index 169167532..7d084516e 100644 --- a/internal/cmd/server/os-update/schedule/create/create_test.go +++ b/internal/cmd/server/os-update/schedule/create/create_test.go @@ -14,7 +14,9 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" +) type testCtxKey struct{} @@ -26,12 +28,13 @@ var testServerId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ - projectIdFlag: testProjectId, - serverIdFlag: testServerId, - nameFlag: "example-schedule-name", - enabledFlag: "true", - rruleFlag: defaultRrule, - maintenanceWindowFlag: "23", + globalflags.ProjectIdFlag: testProjectId, + globalflags.RegionFlag: testRegion, + serverIdFlag: testServerId, + nameFlag: "example-schedule-name", + enabledFlag: "true", + rruleFlag: defaultRrule, + maintenanceWindowFlag: "23", } for _, mod := range mods { mod(flagValues) @@ -43,6 +46,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, ServerId: testServerId, @@ -58,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *serverupdate.ApiCreateUpdateScheduleRequest)) serverupdate.ApiCreateUpdateScheduleRequest { - request := testClient.CreateUpdateSchedule(testCtx, testProjectId, testServerId) + request := testClient.CreateUpdateSchedule(testCtx, testProjectId, testServerId, testRegion) request = request.CreateUpdateSchedulePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -109,21 +113,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, }, diff --git a/internal/cmd/server/os-update/schedule/delete/delete.go b/internal/cmd/server/os-update/schedule/delete/delete.go index 3c9813a98..855690fa4 100644 --- a/internal/cmd/server/os-update/schedule/delete/delete.go +++ b/internal/cmd/server/os-update/schedule/delete/delete.go @@ -108,6 +108,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiDeleteUpdateScheduleRequest { - req := apiClient.DeleteUpdateSchedule(ctx, model.ProjectId, model.ServerId, model.ScheduleId) + req := apiClient.DeleteUpdateSchedule(ctx, model.ProjectId, model.ServerId, model.ScheduleId, model.Region) return req } diff --git a/internal/cmd/server/os-update/schedule/delete/delete_test.go b/internal/cmd/server/os-update/schedule/delete/delete_test.go index 60b00b97c..040aa61f7 100644 --- a/internal/cmd/server/os-update/schedule/delete/delete_test.go +++ b/internal/cmd/server/os-update/schedule/delete/delete_test.go @@ -13,7 +13,10 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" + testUpdateScheduleId = "5" +) type testCtxKey struct{} @@ -21,7 +24,6 @@ var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &serverupdate.APIClient{} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() -var testUpdateScheduleId = "5" func fixtureArgValues(mods ...func(argValues []string)) []string { argValues := []string{ @@ -35,8 +37,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) @@ -48,6 +51,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, ServerId: testServerId, @@ -60,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *serverupdate.ApiDeleteUpdateScheduleRequest)) serverupdate.ApiDeleteUpdateScheduleRequest { - request := testClient.DeleteUpdateSchedule(testCtx, testProjectId, testServerId, testUpdateScheduleId) + request := testClient.DeleteUpdateSchedule(testCtx, testProjectId, testServerId, testUpdateScheduleId, testRegion) for _, mod := range mods { mod(&request) } @@ -104,7 +108,7 @@ 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, }, @@ -112,7 +116,7 @@ func TestParseInput(t *testing.T) { description: "project id invalid 1", argValues: fixtureArgValues(), flagValues: fixtureFlagValues(func(flagValues map[string]string) { - flagValues[projectIdFlag] = "" + flagValues[globalflags.ProjectIdFlag] = "" }), isValid: false, }, @@ -120,7 +124,7 @@ func TestParseInput(t *testing.T) { 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, }, diff --git a/internal/cmd/server/os-update/schedule/describe/describe.go b/internal/cmd/server/os-update/schedule/describe/describe.go index 98aa50f37..60aa9431c 100644 --- a/internal/cmd/server/os-update/schedule/describe/describe.go +++ b/internal/cmd/server/os-update/schedule/describe/describe.go @@ -104,7 +104,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiGetUpdateScheduleRequest { - req := apiClient.GetUpdateSchedule(ctx, model.ProjectId, model.ServerId, model.ScheduleId) + req := apiClient.GetUpdateSchedule(ctx, model.ProjectId, model.ServerId, model.ScheduleId, model.Region) return req } diff --git a/internal/cmd/server/os-update/schedule/describe/describe_test.go b/internal/cmd/server/os-update/schedule/describe/describe_test.go index 411148262..5928e712b 100644 --- a/internal/cmd/server/os-update/schedule/describe/describe_test.go +++ b/internal/cmd/server/os-update/schedule/describe/describe_test.go @@ -13,7 +13,10 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" + testScheduleId = "5" +) type testCtxKey struct{} @@ -21,7 +24,6 @@ var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &serverupdate.APIClient{} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() -var testScheduleId = "5" func fixtureArgValues(mods ...func(argValues []string)) []string { argValues := []string{ @@ -35,8 +37,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) @@ -48,6 +51,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, ServerId: testServerId, @@ -60,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *serverupdate.ApiGetUpdateScheduleRequest)) serverupdate.ApiGetUpdateScheduleRequest { - request := testClient.GetUpdateSchedule(testCtx, testProjectId, testServerId, testScheduleId) + request := testClient.GetUpdateSchedule(testCtx, testProjectId, testServerId, testScheduleId, testRegion) for _, mod := range mods { mod(&request) } @@ -104,7 +108,7 @@ 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, }, @@ -112,7 +116,7 @@ func TestParseInput(t *testing.T) { description: "project id invalid 1", argValues: fixtureArgValues(), flagValues: fixtureFlagValues(func(flagValues map[string]string) { - flagValues[projectIdFlag] = "" + flagValues[globalflags.ProjectIdFlag] = "" }), isValid: false, }, @@ -120,7 +124,7 @@ func TestParseInput(t *testing.T) { 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, }, diff --git a/internal/cmd/server/os-update/schedule/list/list.go b/internal/cmd/server/os-update/schedule/list/list.go index 339f23fea..562b30665 100644 --- a/internal/cmd/server/os-update/schedule/list/list.go +++ b/internal/cmd/server/os-update/schedule/list/list.go @@ -133,7 +133,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiListUpdateSchedulesRequest { - req := apiClient.ListUpdateSchedules(ctx, model.ProjectId, model.ServerId) + req := apiClient.ListUpdateSchedules(ctx, model.ProjectId, model.ServerId, model.Region) return req } diff --git a/internal/cmd/server/os-update/schedule/list/list_test.go b/internal/cmd/server/os-update/schedule/list/list_test.go index 61a3ca5ca..d29d3dd5f 100644 --- a/internal/cmd/server/os-update/schedule/list/list_test.go +++ b/internal/cmd/server/os-update/schedule/list/list_test.go @@ -14,7 +14,9 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" +) type testCtxKey struct{} @@ -25,9 +27,10 @@ var testServerId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ - projectIdFlag: testProjectId, - limitFlag: "10", - serverIdFlag: testServerId, + globalflags.ProjectIdFlag: testProjectId, + globalflags.RegionFlag: testRegion, + limitFlag: "10", + serverIdFlag: testServerId, } for _, mod := range mods { mod(flagValues) @@ -39,6 +42,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), @@ -51,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *serverupdate.ApiListUpdateSchedulesRequest)) serverupdate.ApiListUpdateSchedulesRequest { - request := testClient.ListUpdateSchedules(testCtx, testProjectId, testServerId) + request := testClient.ListUpdateSchedules(testCtx, testProjectId, testServerId, testRegion) for _, mod := range mods { mod(&request) } @@ -79,21 +83,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, }, diff --git a/internal/cmd/server/os-update/schedule/update/update.go b/internal/cmd/server/os-update/schedule/update/update.go index 25f110415..e698f21f7 100644 --- a/internal/cmd/server/os-update/schedule/update/update.go +++ b/internal/cmd/server/os-update/schedule/update/update.go @@ -68,7 +68,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return err } - currentSchedule, err := apiClient.GetUpdateScheduleExecute(ctx, model.ProjectId, model.ServerId, model.ScheduleId) + currentSchedule, err := apiClient.GetUpdateScheduleExecute(ctx, model.ProjectId, model.ServerId, model.ScheduleId, model.Region) if err != nil { p.Debug(print.ErrorLevel, "get current server os-update schedule: %v", err) return err @@ -142,7 +142,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient, old serverupdate.UpdateSchedule) (serverupdate.ApiUpdateUpdateScheduleRequest, error) { - req := apiClient.UpdateUpdateSchedule(ctx, model.ProjectId, model.ServerId, model.ScheduleId) + req := apiClient.UpdateUpdateSchedule(ctx, model.ProjectId, model.ServerId, model.ScheduleId, model.Region) if model.MaintenanceWindow != nil { old.MaintenanceWindow = model.MaintenanceWindow diff --git a/internal/cmd/server/os-update/schedule/update/update_test.go b/internal/cmd/server/os-update/schedule/update/update_test.go index a821be003..63ab21239 100644 --- a/internal/cmd/server/os-update/schedule/update/update_test.go +++ b/internal/cmd/server/os-update/schedule/update/update_test.go @@ -15,7 +15,10 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) -var projectIdFlag = globalflags.ProjectIdFlag +const ( + testRegion = "eu02" + testScheduleId = "5" +) type testCtxKey struct{} @@ -23,7 +26,6 @@ var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &serverupdate.APIClient{} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() -var testScheduleId = "5" func fixtureArgValues(mods ...func(argValues []string)) []string { argValues := []string{ @@ -37,12 +39,13 @@ 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, - nameFlag: "example-schedule-name", - enabledFlag: "true", - rruleFlag: defaultRrule, - maintenanceWindowFlag: "23", + globalflags.ProjectIdFlag: testProjectId, + globalflags.RegionFlag: testRegion, + serverIdFlag: testServerId, + nameFlag: "example-schedule-name", + enabledFlag: "true", + rruleFlag: defaultRrule, + maintenanceWindowFlag: "23", } for _, mod := range mods { mod(flagValues) @@ -54,6 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, ScheduleId: testScheduleId, @@ -98,7 +102,7 @@ func fixturePayload(mods ...func(payload *serverupdate.UpdateUpdateSchedulePaylo } func fixtureRequest(mods ...func(request *serverupdate.ApiUpdateUpdateScheduleRequest)) serverupdate.ApiUpdateUpdateScheduleRequest { - request := testClient.UpdateUpdateSchedule(testCtx, testProjectId, testServerId, testScheduleId) + request := testClient.UpdateUpdateSchedule(testCtx, testProjectId, testServerId, testScheduleId, testRegion) request = request.UpdateUpdateSchedulePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -138,7 +142,7 @@ 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, }, @@ -146,7 +150,7 @@ func TestParseInput(t *testing.T) { description: "project id invalid 1", argValues: fixtureArgValues(), flagValues: fixtureFlagValues(func(flagValues map[string]string) { - flagValues[projectIdFlag] = "" + flagValues[globalflags.ProjectIdFlag] = "" }), isValid: false, }, @@ -154,7 +158,7 @@ func TestParseInput(t *testing.T) { 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, }, From 5ccfbed9e58d5ef396c9627f3388ebff8a826141 Mon Sep 17 00:00:00 2001 From: Ruben Hoenle Date: Mon, 24 Mar 2025 09:32:21 +0100 Subject: [PATCH 2/3] remove region configuration from serverupdate client --- internal/pkg/services/serverosupdate/client/client.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/pkg/services/serverosupdate/client/client.go b/internal/pkg/services/serverosupdate/client/client.go index 8b46d6f1d..1f1f2033e 100644 --- a/internal/pkg/services/serverosupdate/client/client.go +++ b/internal/pkg/services/serverosupdate/client/client.go @@ -12,7 +12,6 @@ import ( ) func ConfigureClient(p *print.Printer) (*serverupdate.APIClient, error) { - var err error var apiClient *serverupdate.APIClient var cfgOptions []sdkConfig.ConfigurationOption @@ -27,7 +26,7 @@ func ConfigureClient(p *print.Printer) (*serverupdate.APIClient, error) { if customEndpoint != "" { cfgOptions = append(cfgOptions, sdkConfig.WithEndpoint(customEndpoint)) } else { - cfgOptions = append(cfgOptions, authCfgOption, sdkConfig.WithRegion("eu01")) + cfgOptions = append(cfgOptions, authCfgOption) } if p.IsVerbosityDebug() { From 221e360d34585855c16a8c6eee94cff5fc8a3457 Mon Sep 17 00:00:00 2001 From: Ruben Hoenle Date: Mon, 24 Mar 2025 13:22:40 +0100 Subject: [PATCH 3/3] chore(docs): remove unimplemented name flag from examples --- docs/stackit_server_os-update_create.md | 4 ++-- internal/cmd/server/os-update/create/create.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/stackit_server_os-update_create.md b/docs/stackit_server_os-update_create.md index f84cb6d77..4d110f8bc 100644 --- a/docs/stackit_server_os-update_create.md +++ b/docs/stackit_server_os-update_create.md @@ -14,10 +14,10 @@ stackit server os-update create [flags] ``` Create a Server os-update with name "myupdate" - $ stackit server os-update create --server-id xxx --name=myupdate + $ stackit server os-update create --server-id xxx Create a Server os-update with name "myupdate" and maintenance window for 13 o'clock. - $ stackit server os-update create --server-id xxx --name=mybupdate --maintenance-window=13 + $ stackit server os-update create --server-id xxx --maintenance-window=13 ``` ### Options diff --git a/internal/cmd/server/os-update/create/create.go b/internal/cmd/server/os-update/create/create.go index 090a39247..71845bc2a 100644 --- a/internal/cmd/server/os-update/create/create.go +++ b/internal/cmd/server/os-update/create/create.go @@ -43,10 +43,10 @@ func NewCmd(p *print.Printer) *cobra.Command { Example: examples.Build( examples.NewExample( `Create a Server os-update with name "myupdate"`, - `$ stackit server os-update create --server-id xxx --name=myupdate`), + `$ stackit server os-update create --server-id xxx`), examples.NewExample( `Create a Server os-update with name "myupdate" and maintenance window for 13 o'clock.`, - `$ stackit server os-update create --server-id xxx --name=mybupdate --maintenance-window=13`), + `$ stackit server os-update create --server-id xxx --maintenance-window=13`), ), RunE: func(cmd *cobra.Command, _ []string) error { ctx := context.Background()