From 011b11a725a29118282f2e4c10d9a2dd69e853f2 Mon Sep 17 00:00:00 2001 From: Ruben Hoenle Date: Thu, 20 Mar 2025 16:43:59 +0100 Subject: [PATCH] chore(server): regional adjustment for runcommand relates to STACKITTPR-135 --- go.mod | 2 +- go.sum | 4 ++-- internal/cmd/server/command/create/create.go | 2 +- .../cmd/server/command/create/create_test.go | 24 +++++++++++-------- .../cmd/server/command/describe/describe.go | 2 +- .../server/command/describe/describe_test.go | 22 ++++++++++------- internal/cmd/server/command/list/list.go | 2 +- internal/cmd/server/command/list/list_test.go | 22 ++++++++++------- .../command/template/describe/describe.go | 2 +- .../template/describe/describe_test.go | 22 ++++++++++------- .../server/command/template/list/list_test.go | 12 ++++------ .../pkg/services/runcommand/client/client.go | 3 +-- 12 files changed, 66 insertions(+), 53 deletions(-) diff --git a/go.mod b/go.mod index cfcc88591..5a55a1a1e 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.20.0 github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.0.1 github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.13.0 - github.com/stackitcloud/stackit-sdk-go/services/runcommand v0.3.0 + github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.0.0 github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.0 github.com/stackitcloud/stackit-sdk-go/services/serverbackup v0.6.0 github.com/stackitcloud/stackit-sdk-go/services/serverupdate v0.5.0 diff --git a/go.sum b/go.sum index a91110037..24551dfe7 100644 --- a/go.sum +++ b/go.sum @@ -141,8 +141,8 @@ github.com/stackitcloud/stackit-sdk-go/services/redis v0.21.0 h1:UDIRWwiZ2/2ukmn github.com/stackitcloud/stackit-sdk-go/services/redis v0.21.0/go.mod h1:ErMQspxm7+XmtOsEM6lTD73oALPq3lUC5s+JQkm6Y/s= github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.13.0 h1:fPCdQOsdPB1QqwcgytrROk+h5va49CAnp5YSCIrKZWY= github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.13.0/go.mod h1:Hs8RwANfF2ZKqOowPBqMQqLoRHcMobiKAihWWirAdEU= -github.com/stackitcloud/stackit-sdk-go/services/runcommand v0.3.0 h1:S1DFVy2wwSiAFgNPpB527Q/YDQpSaduIFOMX988sZOE= -github.com/stackitcloud/stackit-sdk-go/services/runcommand v0.3.0/go.mod h1:1bANbviG6h5XaD3bBnC3v+eDWf5LBYLtLEF/ih+U4kA= +github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.0.0 h1:tKUyddNszcif4j2yL6lJd4tDAykcU3shMkAPoM9EzV8= +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.0 h1:PwfpDFGUUJ8+Go5hJf+/hA5CHfY+DPS1cqIUYH+zWtE= github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.0/go.mod h1:Hb21FmYP95q0fzOb9jk4/9CIxTsHzrSYDQZh6e82XUg= github.com/stackitcloud/stackit-sdk-go/services/serverbackup v0.6.0 h1:cESGAkm0ftADRBfdbiyx3pp/KVQ8JgmUQdRzpwG61wE= diff --git a/internal/cmd/server/command/create/create.go b/internal/cmd/server/command/create/create.go index cc258aa81..ed65528ac 100644 --- a/internal/cmd/server/command/create/create.go +++ b/internal/cmd/server/command/create/create.go @@ -142,7 +142,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *runcommand.APIClient) (runcommand.ApiCreateCommandRequest, error) { - req := apiClient.CreateCommand(ctx, model.ProjectId, model.ServerId) + req := apiClient.CreateCommand(ctx, model.ProjectId, model.ServerId, model.Region) req = req.CreateCommandPayload(runcommand.CreateCommandPayload{ CommandTemplateName: &model.CommandTemplateName, Parameters: model.Params, diff --git a/internal/cmd/server/command/create/create_test.go b/internal/cmd/server/command/create/create_test.go index c1a72f8b6..b7b3657ca 100644 --- a/internal/cmd/server/command/create/create_test.go +++ b/internal/cmd/server/command/create/create_test.go @@ -14,8 +14,6 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) -var projectIdFlag = globalflags.ProjectIdFlag - type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") @@ -24,12 +22,17 @@ var testClient = &runcommand.APIClient{} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() +const ( + testRegion = "eu02" +) + func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ - projectIdFlag: testProjectId, - serverIdFlag: testServerId, - commandTemplateNameFlag: "RunShellScript", - paramsFlag: `script='echo hello'`, + globalflags.ProjectIdFlag: testProjectId, + globalflags.RegionFlag: testRegion, + serverIdFlag: testServerId, + commandTemplateNameFlag: "RunShellScript", + paramsFlag: `script='echo hello'`, } for _, mod := range mods { mod(flagValues) @@ -41,6 +44,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, ServerId: testServerId, @@ -54,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *runcommand.ApiCreateCommandRequest)) runcommand.ApiCreateCommandRequest { - request := testClient.CreateCommand(testCtx, testProjectId, testServerId) + request := testClient.CreateCommand(testCtx, testProjectId, testServerId, testRegion) request = request.CreateCommandPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -100,21 +104,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/command/describe/describe.go b/internal/cmd/server/command/describe/describe.go index dfd6beba4..6eb4359c7 100644 --- a/internal/cmd/server/command/describe/describe.go +++ b/internal/cmd/server/command/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 *runcommand.APIClient) runcommand.ApiGetCommandRequest { - req := apiClient.GetCommand(ctx, model.ProjectId, model.ServerId, model.CommandId) + req := apiClient.GetCommand(ctx, model.ProjectId, model.Region, model.ServerId, model.CommandId) return req } diff --git a/internal/cmd/server/command/describe/describe_test.go b/internal/cmd/server/command/describe/describe_test.go index 0d0b76f25..c9d1f3d86 100644 --- a/internal/cmd/server/command/describe/describe_test.go +++ b/internal/cmd/server/command/describe/describe_test.go @@ -13,15 +13,17 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) -var projectIdFlag = globalflags.ProjectIdFlag - type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &runcommand.APIClient{} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() -var testCommandId = "5" + +const ( + testRegion = "eu02" + testCommandId = "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 *runcommand.ApiGetCommandRequest)) runcommand.ApiGetCommandRequest { - request := testClient.GetCommand(testCtx, testProjectId, testServerId, testCommandId) + request := testClient.GetCommand(testCtx, testProjectId, testRegion, testServerId, testCommandId) 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/command/list/list.go b/internal/cmd/server/command/list/list.go index 3ee9fd364..4a00abf57 100644 --- a/internal/cmd/server/command/list/list.go +++ b/internal/cmd/server/command/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 *runcommand.APIClient) runcommand.ApiListCommandsRequest { - req := apiClient.ListCommands(ctx, model.ProjectId, model.ServerId) + req := apiClient.ListCommands(ctx, model.ProjectId, model.ServerId, model.Region) return req } diff --git a/internal/cmd/server/command/list/list_test.go b/internal/cmd/server/command/list/list_test.go index 3d8ced5f2..6740fac38 100644 --- a/internal/cmd/server/command/list/list_test.go +++ b/internal/cmd/server/command/list/list_test.go @@ -14,8 +14,6 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) -var projectIdFlag = globalflags.ProjectIdFlag - type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") @@ -23,11 +21,16 @@ var testClient = &runcommand.APIClient{} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() +const ( + testRegion = "eu02" +) + 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 *runcommand.ApiListCommandsRequest)) runcommand.ApiListCommandsRequest { - request := testClient.ListCommands(testCtx, testProjectId, testServerId) + request := testClient.ListCommands(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/command/template/describe/describe.go b/internal/cmd/server/command/template/describe/describe.go index d549e8752..816bfa8be 100644 --- a/internal/cmd/server/command/template/describe/describe.go +++ b/internal/cmd/server/command/template/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 *runcommand.APIClient) runcommand.ApiGetCommandTemplateRequest { - req := apiClient.GetCommandTemplate(ctx, model.ProjectId, model.ServerId, model.CommandTemplateName) + req := apiClient.GetCommandTemplate(ctx, model.ProjectId, model.ServerId, model.CommandTemplateName, model.Region) return req } diff --git a/internal/cmd/server/command/template/describe/describe_test.go b/internal/cmd/server/command/template/describe/describe_test.go index b01268ae6..85b97a8ea 100644 --- a/internal/cmd/server/command/template/describe/describe_test.go +++ b/internal/cmd/server/command/template/describe/describe_test.go @@ -13,15 +13,17 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) -var projectIdFlag = globalflags.ProjectIdFlag - type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &runcommand.APIClient{} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() -var testCommandTemplateName = "RunShellScript" + +const ( + testCommandTemplateName = "RunShellScript" + testRegion = "eu02" +) 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 *runcommand.ApiGetCommandTemplateRequest)) runcommand.ApiGetCommandTemplateRequest { - request := testClient.GetCommandTemplate(testCtx, testProjectId, testServerId, testCommandTemplateName) + request := testClient.GetCommandTemplate(testCtx, testProjectId, testServerId, testCommandTemplateName, 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/command/template/list/list_test.go b/internal/cmd/server/command/template/list/list_test.go index 5c6cb12c8..309716c16 100644 --- a/internal/cmd/server/command/template/list/list_test.go +++ b/internal/cmd/server/command/template/list/list_test.go @@ -14,8 +14,6 @@ import ( "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) -var projectIdFlag = globalflags.ProjectIdFlag - type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") @@ -24,8 +22,8 @@ var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ - projectIdFlag: testProjectId, - limitFlag: "10", + globalflags.ProjectIdFlag: testProjectId, + limitFlag: "10", } for _, mod := range mods { mod(flagValues) @@ -76,21 +74,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/pkg/services/runcommand/client/client.go b/internal/pkg/services/runcommand/client/client.go index 5c43e3223..254978f4d 100644 --- a/internal/pkg/services/runcommand/client/client.go +++ b/internal/pkg/services/runcommand/client/client.go @@ -27,8 +27,7 @@ func ConfigureClient(p *print.Printer) (*runcommand.APIClient, error) { if customEndpoint != "" { cfgOptions = append(cfgOptions, sdkConfig.WithEndpoint(customEndpoint)) } else { - region := viper.GetString(config.RegionKey) - cfgOptions = append(cfgOptions, authCfgOption, sdkConfig.WithRegion(region)) + cfgOptions = append(cfgOptions, authCfgOption) } if p.IsVerbosityDebug() {