Skip to content

Commit fa62984

Browse files
authored
chore(runcommand): switch to new sdk structure (#1484)
relates to STACKITCLI-354
1 parent 521b57d commit fa62984

13 files changed

Lines changed: 65 additions & 52 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0
3030
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.11.0
3131
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0
32-
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3
32+
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.8.0
3333
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1
3434
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8
3535
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ github.com/stackitcloud/stackit-sdk-go/services/redis v1.1.0 h1:ckYMRXAGE2/vaxPe
634634
github.com/stackitcloud/stackit-sdk-go/services/redis v1.1.0/go.mod h1:yjej6QfYoYdRIyKXlmbVz8fZYxbuUdl+QBkvLDPgA4k=
635635
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0 h1:JPP6a0ME1tZXr4iB69d/LtJsCAr58ENBadFaK9f48/c=
636636
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0/go.mod h1:NEz3f+GV5G++BE9/MmZCsXJyCih7jtg0pZuSyG2sLEs=
637-
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3 h1:AiGNJmpQ/f9cglaIQQ4SyePbtCI3K1DQLNvqVN9jKSo=
638-
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3/go.mod h1:U/q0V89fvCF2O1ZJfi68/Chie9YY/5s7xBHI1Klq7wA=
637+
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.8.0 h1:T5gy5i+NxrpJPYDEJNjGjljhfD7PWTFia7us8A4mL/c=
638+
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.8.0/go.mod h1:iB27HtF0UcAugURc9w+nlNrtbAj7Mukw/ptAz+7p2WE=
639639
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1 h1:U5rstX5e6Am2t+Ukv5K1Sbftzxt5aFALMa9YS4jCJoo=
640640
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1/go.mod h1:2XA8PE05Qg6BL2YXO4XgfGI9qskJ3cicLE5Qq0aqDdY=
641641
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8 h1:LLyANBzE8sQa0/49tQBqq4sVLhNgwdqCeQm76srJHWw=

internal/cmd/server/command/create/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
iaasClient "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
1010

1111
"github.com/spf13/cobra"
12-
"github.com/stackitcloud/stackit-sdk-go/services/runcommand"
12+
runcommand "github.com/stackitcloud/stackit-sdk-go/services/runcommand/v2api"
1313

1414
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1515
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -135,9 +135,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
135135
}
136136

137137
func buildRequest(ctx context.Context, model *inputModel, apiClient *runcommand.APIClient) (runcommand.ApiCreateCommandRequest, error) {
138-
req := apiClient.CreateCommand(ctx, model.ProjectId, model.ServerId, model.Region)
138+
req := apiClient.DefaultAPI.CreateCommand(ctx, model.ProjectId, model.ServerId, model.Region)
139139
req = req.CreateCommandPayload(runcommand.CreateCommandPayload{
140-
CommandTemplateName: &model.CommandTemplateName,
140+
CommandTemplateName: model.CommandTemplateName,
141141
Parameters: model.Params,
142142
})
143143
return req, nil

internal/cmd/server/command/create/create_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
8-
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
9-
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
10-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
11-
127
"github.com/google/go-cmp/cmp"
138
"github.com/google/go-cmp/cmp/cmpopts"
149
"github.com/google/uuid"
15-
"github.com/stackitcloud/stackit-sdk-go/services/runcommand"
10+
runcommand "github.com/stackitcloud/stackit-sdk-go/services/runcommand/v2api"
11+
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1615
)
1716

1817
type testCtxKey struct{}
1918

2019
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
var testClient = &runcommand.APIClient{}
20+
var testClient = &runcommand.APIClient{DefaultAPI: &runcommand.DefaultAPIService{}}
2221

2322
var testProjectId = uuid.NewString()
2423
var testServerId = uuid.NewString()
@@ -59,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5958
}
6059

6160
func fixtureRequest(mods ...func(request *runcommand.ApiCreateCommandRequest)) runcommand.ApiCreateCommandRequest {
62-
request := testClient.CreateCommand(testCtx, testProjectId, testServerId, testRegion)
61+
request := testClient.DefaultAPI.CreateCommand(testCtx, testProjectId, testServerId, testRegion)
6362
request = request.CreateCommandPayload(fixturePayload())
6463
for _, mod := range mods {
6564
mod(&request)
@@ -69,7 +68,7 @@ func fixtureRequest(mods ...func(request *runcommand.ApiCreateCommandRequest)) r
6968

7069
func fixturePayload(mods ...func(payload *runcommand.CreateCommandPayload)) runcommand.CreateCommandPayload {
7170
payload := runcommand.CreateCommandPayload{
72-
CommandTemplateName: utils.Ptr("RunShellScript"),
71+
CommandTemplateName: "RunShellScript",
7372
Parameters: &map[string]string{"script": "'echo hello'"},
7473
}
7574
for _, mod := range mods {
@@ -170,7 +169,7 @@ func TestBuildRequest(t *testing.T) {
170169

171170
diff := cmp.Diff(request, tt.expectedRequest,
172171
cmp.AllowUnexported(tt.expectedRequest),
173-
cmpopts.EquateComparable(testCtx),
172+
cmpopts.EquateComparable(testCtx, runcommand.DefaultAPIService{}),
174173
)
175174
if diff != "" {
176175
t.Fatalf("Data does not match: %s", diff)

internal/cmd/server/command/describe/describe.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
88

99
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-sdk-go/services/runcommand"
10+
runcommand "github.com/stackitcloud/stackit-sdk-go/services/runcommand/v2api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -64,7 +64,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6464
return fmt.Errorf("read server command: %w", err)
6565
}
6666

67-
return outputResult(params.Printer, model.OutputFormat, *resp)
67+
return outputResult(params.Printer, model.OutputFormat, resp)
6868
},
6969
}
7070
configureFlags(cmd)
@@ -97,12 +97,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
9797
}
9898

9999
func buildRequest(ctx context.Context, model *inputModel, apiClient *runcommand.APIClient) runcommand.ApiGetCommandRequest {
100-
req := apiClient.GetCommand(ctx, model.ProjectId, model.Region, model.ServerId, model.CommandId)
100+
req := apiClient.DefaultAPI.GetCommand(ctx, model.ProjectId, model.Region, model.ServerId, model.CommandId)
101101
return req
102102
}
103103

104-
func outputResult(p *print.Printer, outputFormat string, command runcommand.CommandDetails) error {
104+
func outputResult(p *print.Printer, outputFormat string, command *runcommand.CommandDetails) error {
105105
return p.OutputResult(outputFormat, command, func() error {
106+
if command == nil {
107+
return fmt.Errorf("command is nil")
108+
}
109+
106110
table := tables.NewTable()
107111
table.AddRow("ID", utils.PtrString(command.Id))
108112
table.AddSeparator()

internal/cmd/server/command/describe/describe_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ import (
55
"testing"
66

77
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
8+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
89
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
910
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1011

1112
"github.com/google/go-cmp/cmp"
1213
"github.com/google/go-cmp/cmp/cmpopts"
1314
"github.com/google/uuid"
14-
"github.com/stackitcloud/stackit-sdk-go/services/runcommand"
15+
runcommand "github.com/stackitcloud/stackit-sdk-go/services/runcommand/v2api"
1516
)
1617

1718
type testCtxKey struct{}
1819

1920
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
20-
var testClient = &runcommand.APIClient{}
21+
var testClient = &runcommand.APIClient{DefaultAPI: &runcommand.DefaultAPIService{}}
2122
var testProjectId = uuid.NewString()
2223
var testServerId = uuid.NewString()
2324

@@ -65,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6566
}
6667

6768
func fixtureRequest(mods ...func(request *runcommand.ApiGetCommandRequest)) runcommand.ApiGetCommandRequest {
68-
request := testClient.GetCommand(testCtx, testProjectId, testRegion, testServerId, testCommandId)
69+
request := testClient.DefaultAPI.GetCommand(testCtx, testProjectId, testRegion, testServerId, testCommandId)
6970
for _, mod := range mods {
7071
mod(&request)
7172
}
@@ -189,7 +190,7 @@ func TestBuildRequest(t *testing.T) {
189190

190191
diff := cmp.Diff(request, tt.expectedRequest,
191192
cmp.AllowUnexported(tt.expectedRequest),
192-
cmpopts.EquateComparable(testCtx),
193+
cmpopts.EquateComparable(testCtx, runcommand.DefaultAPIService{}),
193194
)
194195
if diff != "" {
195196
t.Fatalf("Data does not match: %s", diff)
@@ -201,18 +202,29 @@ func TestBuildRequest(t *testing.T) {
201202
func TestOutputResult(t *testing.T) {
202203
type args struct {
203204
outputFormat string
204-
command runcommand.CommandDetails
205+
command *runcommand.CommandDetails
205206
}
206207
tests := []struct {
207208
name string
208209
args args
209210
wantErr bool
210211
}{
211212
{
212-
name: "empty",
213-
args: args{},
213+
name: "empty",
214+
args: args{
215+
outputFormat: print.PrettyOutputFormat,
216+
command: &runcommand.CommandDetails{},
217+
},
214218
wantErr: false,
215219
},
220+
{
221+
name: "command is nil",
222+
args: args{
223+
outputFormat: print.PrettyOutputFormat,
224+
command: nil,
225+
},
226+
wantErr: true,
227+
},
216228
}
217229
params := testparams.NewTestParams()
218230
for _, tt := range tests {

internal/cmd/server/command/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
iaasClient "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
1010

1111
"github.com/spf13/cobra"
12-
"github.com/stackitcloud/stackit-sdk-go/services/runcommand"
12+
runcommand "github.com/stackitcloud/stackit-sdk-go/services/runcommand/v2api"
1313

1414
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1515
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -125,7 +125,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
125125
}
126126

127127
func buildRequest(ctx context.Context, model *inputModel, apiClient *runcommand.APIClient) runcommand.ApiListCommandsRequest {
128-
req := apiClient.ListCommands(ctx, model.ProjectId, model.ServerId, model.Region)
128+
req := apiClient.DefaultAPI.ListCommands(ctx, model.ProjectId, model.ServerId, model.Region)
129129
return req
130130
}
131131

internal/cmd/server/command/list/list_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
"github.com/google/go-cmp/cmp"
1313
"github.com/google/go-cmp/cmp/cmpopts"
1414
"github.com/google/uuid"
15-
"github.com/stackitcloud/stackit-sdk-go/services/runcommand"
15+
runcommand "github.com/stackitcloud/stackit-sdk-go/services/runcommand/v2api"
1616
)
1717

1818
type testCtxKey struct{}
1919

2020
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
var testClient = &runcommand.APIClient{}
21+
var testClient = &runcommand.APIClient{DefaultAPI: &runcommand.DefaultAPIService{}}
2222
var testProjectId = uuid.NewString()
2323
var testServerId = uuid.NewString()
2424

@@ -56,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5656
}
5757

5858
func fixtureRequest(mods ...func(request *runcommand.ApiListCommandsRequest)) runcommand.ApiListCommandsRequest {
59-
request := testClient.ListCommands(testCtx, testProjectId, testServerId, testRegion)
59+
request := testClient.DefaultAPI.ListCommands(testCtx, testProjectId, testServerId, testRegion)
6060
for _, mod := range mods {
6161
mod(&request)
6262
}
@@ -145,7 +145,7 @@ func TestBuildRequest(t *testing.T) {
145145

146146
diff := cmp.Diff(request, tt.expectedRequest,
147147
cmp.AllowUnexported(tt.expectedRequest),
148-
cmpopts.EquateComparable(testCtx),
148+
cmpopts.EquateComparable(testCtx, runcommand.DefaultAPIService{}),
149149
)
150150
if diff != "" {
151151
t.Fatalf("Data does not match: %s", diff)

internal/cmd/server/command/template/describe/describe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
88

99
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-sdk-go/services/runcommand"
10+
runcommand "github.com/stackitcloud/stackit-sdk-go/services/runcommand/v2api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -97,7 +97,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
9797
}
9898

9999
func buildRequest(ctx context.Context, model *inputModel, apiClient *runcommand.APIClient) runcommand.ApiGetCommandTemplateRequest {
100-
req := apiClient.GetCommandTemplate(ctx, model.ProjectId, model.ServerId, model.CommandTemplateName, model.Region)
100+
req := apiClient.DefaultAPI.GetCommandTemplate(ctx, model.ProjectId, model.ServerId, model.CommandTemplateName, model.Region)
101101
return req
102102
}
103103

@@ -111,7 +111,7 @@ func outputResult(p *print.Printer, outputFormat string, commandTemplate runcomm
111111
table.AddRow("DESCRIPTION", utils.PtrString(commandTemplate.Description))
112112
table.AddSeparator()
113113
if commandTemplate.OsType != nil {
114-
table.AddRow("OS TYPE", utils.JoinStringPtr(commandTemplate.OsType, "\n"))
114+
table.AddRow("OS TYPE", utils.JoinStringPtr(&commandTemplate.OsType, "\n"))
115115
table.AddSeparator()
116116
}
117117
if commandTemplate.ParametersSchema != nil {

internal/cmd/server/command/template/describe/describe_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
"github.com/google/go-cmp/cmp"
1212
"github.com/google/go-cmp/cmp/cmpopts"
1313
"github.com/google/uuid"
14-
"github.com/stackitcloud/stackit-sdk-go/services/runcommand"
14+
runcommand "github.com/stackitcloud/stackit-sdk-go/services/runcommand/v2api"
1515
)
1616

1717
type testCtxKey struct{}
1818

1919
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
20-
var testClient = &runcommand.APIClient{}
20+
var testClient = &runcommand.APIClient{DefaultAPI: &runcommand.DefaultAPIService{}}
2121
var testProjectId = uuid.NewString()
2222
var testServerId = uuid.NewString()
2323

@@ -65,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6565
}
6666

6767
func fixtureRequest(mods ...func(request *runcommand.ApiGetCommandTemplateRequest)) runcommand.ApiGetCommandTemplateRequest {
68-
request := testClient.GetCommandTemplate(testCtx, testProjectId, testServerId, testCommandTemplateName, testRegion)
68+
request := testClient.DefaultAPI.GetCommandTemplate(testCtx, testProjectId, testServerId, testCommandTemplateName, testRegion)
6969
for _, mod := range mods {
7070
mod(&request)
7171
}
@@ -189,7 +189,7 @@ func TestBuildRequest(t *testing.T) {
189189

190190
diff := cmp.Diff(request, tt.expectedRequest,
191191
cmp.AllowUnexported(tt.expectedRequest),
192-
cmpopts.EquateComparable(testCtx),
192+
cmpopts.EquateComparable(testCtx, runcommand.DefaultAPIService{}),
193193
)
194194
if diff != "" {
195195
t.Fatalf("Data does not match: %s", diff)

0 commit comments

Comments
 (0)