Skip to content

Commit 749be04

Browse files
authored
chore(serverupdate): switch to new sdk structure (#1486)
relates to STACKITCLI-354
1 parent fa62984 commit 749be04

27 files changed

Lines changed: 205 additions & 171 deletions

docs/stackit_server_os-update_create.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ stackit server os-update create [flags]
2323
### Options
2424

2525
```
26-
-h, --help Help for "stackit server os-update create"
27-
-m, --maintenance-window int Maintenance window (in hours, 1-24) (default 23)
28-
-s, --server-id string Server ID
26+
-h, --help Help for "stackit server os-update create"
27+
-m, --maintenance-window int32 Maintenance window (in hours, 1-24) (default 23)
28+
-s, --server-id string Server ID
2929
```
3030

3131
### Options inherited from parent commands

docs/stackit_server_os-update_schedule_create.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ stackit server os-update schedule create [flags]
2323
### Options
2424

2525
```
26-
-e, --enabled Is the server os-update schedule enabled (default true)
27-
-h, --help Help for "stackit server os-update schedule create"
28-
-d, --maintenance-window int os-update maintenance window (in hours, 1-24) (default 23)
29-
-n, --name string os-update schedule name
30-
-r, --rrule string os-update RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
31-
-s, --server-id string Server ID
26+
-e, --enabled Is the server os-update schedule enabled (default true)
27+
-h, --help Help for "stackit server os-update schedule create"
28+
-d, --maintenance-window int32 os-update maintenance window (in hours, 1-24) (default 23)
29+
-n, --name string os-update schedule name
30+
-r, --rrule string os-update RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
31+
-s, --server-id string Server ID
3232
```
3333

3434
### Options inherited from parent commands

docs/stackit_server_os-update_schedule_update.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ stackit server os-update schedule update SCHEDULE_ID [flags]
2020
### Options
2121

2222
```
23-
-e, --enabled Is the server os-update schedule enabled (default true)
24-
-h, --help Help for "stackit server os-update schedule update"
25-
-d, --maintenance-window int Maintenance window (in hours, 1-24) (default 23)
26-
-n, --name string os-update schedule name
27-
-r, --rrule string os-update RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
28-
-s, --server-id string Server ID
23+
-e, --enabled Is the server os-update schedule enabled (default true)
24+
-h, --help Help for "stackit server os-update schedule update"
25+
-d, --maintenance-window int32 Maintenance window (in hours, 1-24) (default 23)
26+
-n, --name string os-update schedule name
27+
-r, --rrule string os-update RRULE (recurrence rule) (default "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1")
28+
-s, --server-id string Server ID
2929
```
3030

3131
### Options inherited from parent commands

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
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
35-
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6
35+
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.2
3636
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0
3737
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7
3838
github.com/stackitcloud/stackit-sdk-go/services/ske v1.11.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.18.1 h1:U5rstX
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=
642642
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8/go.mod h1:/bmg57XZu+bGczzcoumrukiGMPGzI2mOyTT4BVIQUBs=
643-
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6 h1:sQ3fdtUjgIL2Ul8nRYVVacHOwi5aSMTGGbYVL30oQBU=
644-
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6/go.mod h1:3fjlL+9YtuI9Oocl1ZeYIK48ImtY4DwPggFhqAygr7o=
643+
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.2 h1:6C/iTPoYPCrZOc3JMmvyDNs4hm+JR5p9O3DIfFGgnbo=
644+
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.2/go.mod h1:/OHYZXQb9KXDdZK5J9C2YS6DJUD2i6ednZ1rK7zpDZ0=
645645
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 h1:l1EDIlXce2C8JcbBDHVa6nZ4SjPTqmnALTgrhms+NKI=
646646
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0/go.mod h1:EXq8/J7t9p8zPmdIq+atuxyAbnQwxrQT18fI+Qpv98k=
647647
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7 h1:M2PYLF8k3zmAwYWSKfUiCTNTXr7ROGuJganVVEQA3YI=

internal/cmd/server/os-update/create/create.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88

99
iaasClient "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
1010

11+
"github.com/spf13/cobra"
12+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
13+
1114
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1215
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1316
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
@@ -16,10 +19,6 @@ import (
1619
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1720
iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils"
1821
"github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client"
19-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
20-
21-
"github.com/spf13/cobra"
22-
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
2322
)
2423

2524
const (
@@ -32,7 +31,7 @@ type inputModel struct {
3231
*globalflags.GlobalFlagModel
3332

3433
ServerId string
35-
MaintenanceWindow int64
34+
MaintenanceWindow int32
3635
}
3736

3837
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -90,7 +89,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
9089
return fmt.Errorf("create Server os-update: %w", err)
9190
}
9291

93-
return outputResult(params.Printer, model.OutputFormat, serverLabel, *resp)
92+
return outputResult(params.Printer, model.OutputFormat, serverLabel, resp)
9493
},
9594
}
9695
configureFlags(cmd)
@@ -99,7 +98,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
9998

10099
func configureFlags(cmd *cobra.Command) {
101100
cmd.Flags().VarP(flags.UUIDFlag(), serverIdFlag, "s", "Server ID")
102-
cmd.Flags().Int64P(maintenanceWindowFlag, "m", defaultMaintenanceWindow, "Maintenance window (in hours, 1-24)")
101+
cmd.Flags().Int32P(maintenanceWindowFlag, "m", defaultMaintenanceWindow, "Maintenance window (in hours, 1-24)")
103102
}
104103

105104
func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
@@ -111,25 +110,29 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
111110
model := inputModel{
112111
GlobalFlagModel: globalFlags,
113112
ServerId: flags.FlagToStringValue(p, cmd, serverIdFlag),
114-
MaintenanceWindow: flags.FlagWithDefaultToInt64Value(p, cmd, maintenanceWindowFlag),
113+
MaintenanceWindow: flags.FlagWithDefaultToInt32Value(p, cmd, maintenanceWindowFlag),
115114
}
116115

117116
p.DebugInputModel(model)
118117
return &model, nil
119118
}
120119

121120
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) (serverupdate.ApiCreateUpdateRequest, error) {
122-
req := apiClient.CreateUpdate(ctx, model.ProjectId, model.ServerId, model.Region)
121+
req := apiClient.DefaultAPI.CreateUpdate(ctx, model.ProjectId, model.ServerId, model.Region)
123122
payload := serverupdate.CreateUpdatePayload{
124-
MaintenanceWindow: &model.MaintenanceWindow,
123+
MaintenanceWindow: model.MaintenanceWindow,
125124
}
126125
req = req.CreateUpdatePayload(payload)
127126
return req, nil
128127
}
129128

130-
func outputResult(p *print.Printer, outputFormat, serverLabel string, resp serverupdate.Update) error {
129+
func outputResult(p *print.Printer, outputFormat, serverLabel string, resp *serverupdate.Update) error {
131130
return p.OutputResult(outputFormat, resp, func() error {
132-
p.Outputf("Triggered creation of server os-update for server %s. Update ID: %s\n", serverLabel, utils.PtrString(resp.Id))
131+
if resp == nil {
132+
return fmt.Errorf("response is nil")
133+
}
134+
135+
p.Outputf("Triggered creation of server os-update for server %s. Update ID: %d\n", serverLabel, resp.Id)
133136
return nil
134137
})
135138
}

internal/cmd/server/os-update/create/create_test.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ 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/serverupdate"
10+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
11+
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1616
)
1717

1818
const (
@@ -22,7 +22,7 @@ const (
2222
type testCtxKey struct{}
2323

2424
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
25-
var testClient = &serverupdate.APIClient{}
25+
var testClient = &serverupdate.APIClient{DefaultAPI: &serverupdate.DefaultAPIService{}}
2626

2727
var testProjectId = uuid.NewString()
2828
var testServerId = uuid.NewString()
@@ -48,7 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4848
Verbosity: globalflags.VerbosityDefault,
4949
},
5050
ServerId: testServerId,
51-
MaintenanceWindow: int64(13),
51+
MaintenanceWindow: int32(13),
5252
}
5353
for _, mod := range mods {
5454
mod(model)
@@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5757
}
5858

5959
func fixtureRequest(mods ...func(request *serverupdate.ApiCreateUpdateRequest)) serverupdate.ApiCreateUpdateRequest {
60-
request := testClient.CreateUpdate(testCtx, testProjectId, testServerId, testRegion)
60+
request := testClient.DefaultAPI.CreateUpdate(testCtx, testProjectId, testServerId, testRegion)
6161
request = request.CreateUpdatePayload(fixturePayload())
6262
for _, mod := range mods {
6363
mod(&request)
@@ -67,7 +67,7 @@ func fixtureRequest(mods ...func(request *serverupdate.ApiCreateUpdateRequest))
6767

6868
func fixturePayload(mods ...func(payload *serverupdate.CreateUpdatePayload)) serverupdate.CreateUpdatePayload {
6969
payload := serverupdate.CreateUpdatePayload{
70-
MaintenanceWindow: utils.Ptr(int64(13)),
70+
MaintenanceWindow: int32(13),
7171
}
7272
for _, mod := range mods {
7373
mod(&payload)
@@ -162,7 +162,7 @@ func TestBuildRequest(t *testing.T) {
162162

163163
diff := cmp.Diff(request, tt.expectedRequest,
164164
cmp.AllowUnexported(tt.expectedRequest),
165-
cmpopts.EquateComparable(testCtx),
165+
cmpopts.EquateComparable(testCtx, serverupdate.DefaultAPIService{}),
166166
)
167167
if diff != "" {
168168
t.Fatalf("Data does not match: %s", diff)
@@ -175,18 +175,29 @@ func TestOutputResult(t *testing.T) {
175175
type args struct {
176176
outputFormat string
177177
serverLabel string
178-
resp serverupdate.Update
178+
resp *serverupdate.Update
179179
}
180180
tests := []struct {
181181
name string
182182
args args
183183
wantErr bool
184184
}{
185185
{
186-
name: "empty",
187-
args: args{},
186+
name: "empty",
187+
args: args{
188+
outputFormat: print.PrettyOutputFormat,
189+
resp: &serverupdate.Update{},
190+
},
188191
wantErr: false,
189192
},
193+
{
194+
name: "nil",
195+
args: args{
196+
outputFormat: print.PrettyOutputFormat,
197+
resp: nil,
198+
},
199+
wantErr: true,
200+
},
190201
}
191202
params := testparams.NewTestParams()
192203
for _, tt := range tests {

internal/cmd/server/os-update/describe/describe.go

Lines changed: 11 additions & 7 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/serverupdate"
10+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/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 os-update: %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,24 +97,28 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
9797
}
9898

9999
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiGetUpdateRequest {
100-
req := apiClient.GetUpdate(ctx, model.ProjectId, model.ServerId, model.UpdateId, model.Region)
100+
req := apiClient.DefaultAPI.GetUpdate(ctx, model.ProjectId, model.ServerId, model.UpdateId, model.Region)
101101
return req
102102
}
103103

104-
func outputResult(p *print.Printer, outputFormat string, update serverupdate.Update) error {
104+
func outputResult(p *print.Printer, outputFormat string, update *serverupdate.Update) error {
105105
return p.OutputResult(outputFormat, update, func() error {
106+
if update == nil {
107+
return fmt.Errorf("update is nil")
108+
}
109+
106110
table := tables.NewTable()
107-
table.AddRow("ID", utils.PtrString(update.Id))
111+
table.AddRow("ID", update.Id)
108112
table.AddSeparator()
109-
table.AddRow("STATUS", utils.PtrString(update.Status))
113+
table.AddRow("STATUS", update.Status)
110114
table.AddSeparator()
111115
installedUpdates := utils.PtrStringDefault(update.InstalledUpdates, "n/a")
112116
table.AddRow("INSTALLED UPDATES", installedUpdates)
113117
table.AddSeparator()
114118
failedUpdates := utils.PtrStringDefault(update.FailedUpdates, "n/a")
115119
table.AddRow("FAILED UPDATES", failedUpdates)
116120

117-
table.AddRow("START DATE", utils.PtrString(update.StartDate))
121+
table.AddRow("START DATE", update.StartDate)
118122
table.AddSeparator()
119123
table.AddRow("END DATE", utils.PtrString(update.EndDate))
120124
table.AddSeparator()

internal/cmd/server/os-update/describe/describe_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ 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/serverupdate"
14+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
15+
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1517
)
1618

1719
const (
@@ -21,7 +23,7 @@ const (
2123
type testCtxKey struct{}
2224

2325
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
24-
var testClient = &serverupdate.APIClient{}
26+
var testClient = &serverupdate.APIClient{DefaultAPI: &serverupdate.DefaultAPIService{}}
2527
var testProjectId = uuid.NewString()
2628
var testServerId = uuid.NewString()
2729
var testUpdateId = uuid.NewString()
@@ -65,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6567
}
6668

6769
func fixtureRequest(mods ...func(request *serverupdate.ApiGetUpdateRequest)) serverupdate.ApiGetUpdateRequest {
68-
request := testClient.GetUpdate(testCtx, testProjectId, testServerId, testUpdateId, testRegion)
70+
request := testClient.DefaultAPI.GetUpdate(testCtx, testProjectId, testServerId, testUpdateId, testRegion)
6971
for _, mod := range mods {
7072
mod(&request)
7173
}
@@ -159,7 +161,7 @@ func TestBuildRequest(t *testing.T) {
159161

160162
diff := cmp.Diff(request, tt.expectedRequest,
161163
cmp.AllowUnexported(tt.expectedRequest),
162-
cmpopts.EquateComparable(testCtx),
164+
cmpopts.EquateComparable(testCtx, serverupdate.DefaultAPIService{}),
163165
)
164166
if diff != "" {
165167
t.Fatalf("Data does not match: %s", diff)
@@ -171,18 +173,29 @@ func TestBuildRequest(t *testing.T) {
171173
func TestOutputResult(t *testing.T) {
172174
type args struct {
173175
outputFormat string
174-
update serverupdate.Update
176+
update *serverupdate.Update
175177
}
176178
tests := []struct {
177179
name string
178180
args args
179181
wantErr bool
180182
}{
181183
{
182-
name: "empty",
183-
args: args{},
184+
name: "empty",
185+
args: args{
186+
outputFormat: print.PrettyOutputFormat,
187+
update: &serverupdate.Update{},
188+
},
184189
wantErr: false,
185190
},
191+
{
192+
name: "nil",
193+
args: args{
194+
outputFormat: print.PrettyOutputFormat,
195+
update: nil,
196+
},
197+
wantErr: true,
198+
},
186199
}
187200
params := testparams.NewTestParams()
188201
for _, tt := range tests {

internal/cmd/server/os-update/disable/disable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client"
1818

1919
"github.com/spf13/cobra"
20-
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
20+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
2121
)
2222

2323
const (
@@ -108,6 +108,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
108108
}
109109

110110
func buildRequest(ctx context.Context, model *inputModel, apiClient *serverupdate.APIClient) serverupdate.ApiDisableServiceResourceRequest {
111-
req := apiClient.DisableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region)
111+
req := apiClient.DefaultAPI.DisableServiceResource(ctx, model.ProjectId, model.ServerId, model.Region)
112112
return req
113113
}

0 commit comments

Comments
 (0)