Skip to content

Commit 8d75edc

Browse files
committed
fix: iaas update
1 parent 2483bb9 commit 8d75edc

File tree

10 files changed

+38
-32
lines changed

10 files changed

+38
-32
lines changed

internal/cmd/image/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
141141
if !ok {
142142
return fmt.Errorf("create image: no upload URL has been provided")
143143
}
144-
if err := uploadAsync(ctx, p, model, file, *url); err != nil {
144+
if err := uploadAsync(ctx, p, model, file, url); err != nil {
145145
return err
146146
}
147147

internal/cmd/image/list/list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ func NewCmd(p *print.Printer) *cobra.Command {
8080
return fmt.Errorf("list images: %w", err)
8181
}
8282

83-
if items := response.GetItems(); items == nil || len(*items) == 0 {
83+
if items := response.GetItems(); len(items) == 0 {
8484
p.Info("No images found for project %q", projectLabel)
8585
} else {
86-
if model.Limit != nil && len(*items) > int(*model.Limit) {
87-
*items = (*items)[:*model.Limit]
86+
if model.Limit != nil && len(items) > int(*model.Limit) {
87+
items = (items)[:*model.Limit]
8888
}
89-
if err := outputResult(p, model.OutputFormat, *items); err != nil {
89+
if err := outputResult(p, model.OutputFormat, items); err != nil {
9090
return fmt.Errorf("output images: %w", err)
9191
}
9292
}

internal/cmd/observability/credentials/create/create_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
88
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
9-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
109
"github.com/stackitcloud/stackit-sdk-go/services/observability"
1110

1211
"github.com/google/go-cmp/cmp"
@@ -218,7 +217,7 @@ func TestOutputResult(t *testing.T) {
218217
name: "set response with credentials",
219218
args: args{
220219
resp: &observability.CreateCredentialsResponse{
221-
Credentials: observability.NewCredentials(utils.Ptr("dummy-pw"), utils.Ptr("dummy-user")),
220+
Credentials: observability.NewCredentials("dummy-pw", "dummy-user"),
222221
},
223222
},
224223
wantErr: false,

internal/cmd/quota/list/list.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,40 +133,40 @@ func outputResult(p *print.Printer, outputFormat string, quotas *iaas.QuotaList)
133133
table := tables.NewTable()
134134
table.SetHeader("NAME", "LIMIT", "CURRENT USAGE", "PERCENT")
135135
if val := quotas.BackupGigabytes; val != nil {
136-
table.AddRow("Total size in GiB of backups [GiB]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
136+
table.AddRow("Total size in GiB of backups [GiB]", conv(val.Limit), conv(val.Usage), percentage(val))
137137
}
138138
if val := quotas.Backups; val != nil {
139-
table.AddRow("Number of backups [Count]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
139+
table.AddRow("Number of backups [Count]", conv(val.Limit), conv(val.Usage), percentage(val))
140140
}
141141
if val := quotas.Gigabytes; val != nil {
142-
table.AddRow("Total size in GiB of volumes and snapshots [GiB]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
142+
table.AddRow("Total size in GiB of volumes and snapshots [GiB]", conv(val.Limit), conv(val.Usage), percentage(val))
143143
}
144144
if val := quotas.Networks; val != nil {
145-
table.AddRow("Number of networks [Count]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
145+
table.AddRow("Number of networks [Count]", conv(val.Limit), conv(val.Usage), percentage(val))
146146
}
147147
if val := quotas.Nics; val != nil {
148-
table.AddRow("Number of network interfaces (nics) [Count]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
148+
table.AddRow("Number of network interfaces (nics) [Count]", conv(val.Limit), conv(val.Usage), percentage(val))
149149
}
150150
if val := quotas.PublicIps; val != nil {
151-
table.AddRow("Number of public IP addresses [Count]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
151+
table.AddRow("Number of public IP addresses [Count]", conv(val.Limit), conv(val.Usage), percentage(val))
152152
}
153153
if val := quotas.Ram; val != nil {
154-
table.AddRow("Amount of server RAM in MiB [MiB]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
154+
table.AddRow("Amount of server RAM in MiB [MiB]", conv(val.Limit), conv(val.Usage), percentage(val))
155155
}
156156
if val := quotas.SecurityGroupRules; val != nil {
157-
table.AddRow("Number of security group rules [Count]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
157+
table.AddRow("Number of security group rules [Count]", conv(val.Limit), conv(val.Usage), percentage(val))
158158
}
159159
if val := quotas.SecurityGroups; val != nil {
160-
table.AddRow("Number of security groups [Count]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
160+
table.AddRow("Number of security groups [Count]", conv(val.Limit), conv(val.Usage), percentage(val))
161161
}
162162
if val := quotas.Snapshots; val != nil {
163-
table.AddRow("Number of snapshots [Count]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
163+
table.AddRow("Number of snapshots [Count]", conv(val.Limit), conv(val.Usage), percentage(val))
164164
}
165165
if val := quotas.Vcpu; val != nil {
166-
table.AddRow("Number of server cores (vcpu) [Count]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
166+
table.AddRow("Number of server cores (vcpu) [Count]", conv(val.Limit), conv(val.Usage), percentage(val))
167167
}
168168
if val := quotas.Volumes; val != nil {
169-
table.AddRow("Number of volumes [Count]", conv(val.GetLimit()), conv(val.GetUsage()), percentage(val))
169+
table.AddRow("Number of volumes [Count]", conv(val.Limit), conv(val.Usage), percentage(val))
170170
}
171171
err := table.Display(p)
172172
if err != nil {
@@ -185,11 +185,13 @@ func conv(n *int64) string {
185185
}
186186

187187
func percentage(val interface {
188-
GetLimit() *int64
189-
GetUsage() *int64
188+
GetLimitOk() (int64, bool)
189+
GetUsageOk() (int64, bool)
190190
}) string {
191-
if a, b := val.GetLimit(), val.GetUsage(); a != nil && b != nil {
192-
return fmt.Sprintf("%3.1f%%", 100.0/float64(*a)*float64(*b))
191+
a, aOk := val.GetLimitOk()
192+
b, bOk := val.GetUsageOk()
193+
if aOk && bOk {
194+
return fmt.Sprintf("%3.1f%%", 100.0/float64(a)*float64(b))
193195
}
194196
return "n/a"
195197
}

internal/cmd/security-group/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ func NewCmd(p *print.Printer) *cobra.Command {
6767
return fmt.Errorf("list security group: %w", err)
6868
}
6969

70-
if items := response.GetItems(); items == nil || len(*items) == 0 {
70+
if items := response.GetItems(); len(items) == 0 {
7171
p.Info("No security groups found for project %q", projectLabel)
7272
} else {
73-
if err := outputResult(p, model.OutputFormat, *items); err != nil {
73+
if err := outputResult(p, model.OutputFormat, items); err != nil {
7474
return fmt.Errorf("output security groups: %w", err)
7575
}
7676
}

internal/cmd/server/console/console.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ func outputResult(p *print.Printer, outputFormat, serverLabel string, serverUrl
127127

128128
return nil
129129
default:
130-
if serverUrl.GetUrl() == nil {
130+
if _, ok := serverUrl.GetUrlOk(); !ok {
131131
return fmt.Errorf("server url is nil")
132132
}
133133
// unescape url in order to get rid of e.g. %40
134-
unescapedURL, err := url.PathUnescape(*serverUrl.GetUrl())
134+
unescapedURL, err := url.PathUnescape(serverUrl.GetUrl())
135135
if err != nil {
136136
return fmt.Errorf("unescape url: %w", err)
137137
}

internal/cmd/server/create/create.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
289289
}
290290
}
291291

292+
var userData *[]byte
293+
if model.UserData != nil {
294+
userData = utils.Ptr([]byte(*model.UserData))
295+
}
296+
292297
payload := iaas.CreateServerPayload{
293298
Name: model.Name,
294299
MachineType: model.MachineType,
@@ -299,7 +304,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
299304
KeypairName: model.KeypairName,
300305
SecurityGroups: model.SecurityGroups,
301306
ServiceAccountMails: model.ServiceAccountMails,
302-
UserData: model.UserData,
307+
UserData: userData,
303308
Volumes: model.Volumes,
304309
Labels: labelsMap,
305310
}

internal/cmd/server/create/create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func fixturePayload(mods ...func(payload *iaas.CreateServerPayload)) iaas.Create
120120
KeypairName: utils.Ptr("test-keypair-name"),
121121
SecurityGroups: utils.Ptr([]string{"test-security-groups"}),
122122
ServiceAccountMails: utils.Ptr([]string{"test-service-account"}),
123-
UserData: utils.Ptr("test-user-data"),
123+
UserData: utils.Ptr([]byte("test-user-data")),
124124
Volumes: utils.Ptr([]string{testVolumeId}),
125125
BootVolume: &iaas.CreateServerPayloadBootVolume{
126126
PerformanceClass: utils.Ptr("test-perf-class"),

internal/cmd/server/log/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
8282
return fmt.Errorf("server log: %w", err)
8383
}
8484

85-
log := *resp.GetOutput()
85+
log := resp.GetOutput()
8686
lines := strings.Split(log, "\n")
8787

8888
if len(lines) > int(*model.Length) {

internal/cmd/server/machine-type/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ func outputResult(p *print.Printer, outputFormat string, machineTypes iaas.Machi
155155
table.SetTitle("Machine-Types")
156156

157157
table.SetHeader("NAME", "DESCRIPTION")
158-
if items := machineTypes.GetItems(); items != nil && len(*items) > 0 {
159-
for _, machineType := range *items {
158+
if items := machineTypes.GetItems(); len(items) > 0 {
159+
for _, machineType := range items {
160160
table.AddRow(*machineType.Name, utils.PtrString(machineType.Description))
161161
}
162162
}

0 commit comments

Comments
 (0)