Skip to content

chore(server): regional adjustment for runcommand #660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/command/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 14 additions & 10 deletions internal/cmd/server/command/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/runcommand"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/command/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 13 additions & 9 deletions internal/cmd/server/command/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -104,23 +108,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/command/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 13 additions & 9 deletions internal/cmd/server/command/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ 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()

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)
Expand All @@ -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)),
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 13 additions & 9 deletions internal/cmd/server/command/template/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -104,23 +108,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
12 changes: 5 additions & 7 deletions internal/cmd/server/command/template/list/list_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/runcommand"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
Expand All @@ -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)
Expand Down Expand Up @@ -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,
},
Expand Down
Loading