Skip to content

Commit 39f6590

Browse files
committed
describe commands
1 parent 1548bad commit 39f6590

42 files changed

Lines changed: 232 additions & 267 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/cmd/affinity-groups/describe/describe.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package describe
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
89

@@ -70,7 +71,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7071
}
7172

7273
func buildRequest(ctx context.Context, model inputModel, apiClient *iaas.APIClient) iaas.ApiGetAffinityGroupRequest {
73-
return apiClient.GetAffinityGroup(ctx, model.ProjectId, model.Region, model.AffinityGroupId)
74+
return apiClient.DefaultAPI.GetAffinityGroup(ctx, model.ProjectId, model.Region, model.AffinityGroupId)
7475
}
7576

7677
func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputModel, error) {
@@ -101,16 +102,12 @@ func outputResult(p *print.Printer, model inputModel, resp iaas.AffinityGroup) e
101102
table.AddRow("ID", utils.PtrString(resp.Id))
102103
table.AddSeparator()
103104
}
104-
if resp.Name != nil {
105-
table.AddRow("NAME", utils.PtrString(resp.Name))
106-
table.AddSeparator()
107-
}
108-
if resp.Policy != nil {
109-
table.AddRow("POLICY", utils.PtrString(resp.Policy))
110-
table.AddSeparator()
111-
}
105+
table.AddRow("NAME", resp.Name)
106+
table.AddSeparator()
107+
table.AddRow("POLICY", resp.Policy)
108+
table.AddSeparator()
112109
if resp.HasMembers() {
113-
table.AddRow("Members", utils.JoinStringPtr(resp.Members, ", "))
110+
table.AddRow("Members", strings.Join(resp.Members, ", "))
114111
table.AddSeparator()
115112
}
116113

internal/cmd/affinity-groups/describe/describe_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6565
}
6666

6767
func fixtureRequest(mods ...func(request *iaas.ApiGetAffinityGroupRequest)) iaas.ApiGetAffinityGroupRequest {
68-
request := testClient.GetAffinityGroup(testCtx, testProjectId, testRegion, testAffinityGroupId)
68+
request := testClient.DefaultAPI.GetAffinityGroup(testCtx, testProjectId, testRegion, testAffinityGroupId)
6969
for _, mod := range mods {
7070
mod(&request)
7171
}
@@ -173,7 +173,7 @@ func TestBuildRequest(t *testing.T) {
173173

174174
diff := cmp.Diff(request, tt.expectedRequest,
175175
cmp.AllowUnexported(tt.expectedRequest),
176-
cmpopts.EquateComparable(testCtx),
176+
cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}),
177177
)
178178
if diff != "" {
179179
t.Fatalf("Data does not match: %s", diff)

internal/cmd/image/describe/describe.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6969
}
7070

7171
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetImageRequest {
72-
request := apiClient.GetImage(ctx, model.ProjectId, model.Region, model.ImageId)
72+
request := apiClient.DefaultAPI.GetImage(ctx, model.ProjectId, model.Region, model.ImageId)
7373
return request
7474
}
7575

@@ -99,18 +99,14 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.Image) error
9999
table.AddRow("ID", *id)
100100
table.AddSeparator()
101101
}
102-
if name := resp.Name; name != nil {
103-
table.AddRow("NAME", *name)
104-
table.AddSeparator()
105-
}
102+
table.AddRow("NAME", resp.Name)
103+
table.AddSeparator()
106104
if status := resp.Status; status != nil {
107105
table.AddRow("STATUS", *status)
108106
table.AddSeparator()
109107
}
110-
if format := resp.DiskFormat; format != nil {
111-
table.AddRow("FORMAT", *format)
112-
table.AddSeparator()
113-
}
108+
table.AddRow("FORMAT", resp.DiskFormat)
109+
table.AddSeparator()
114110
if diskSize := resp.MinDiskSize; diskSize != nil {
115111
table.AddRow("DISK SIZE", *diskSize)
116112
table.AddSeparator()
@@ -128,11 +124,11 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.Image) error
128124
table.AddRow("OPERATING SYSTEM", *os)
129125
table.AddSeparator()
130126
}
131-
if distro := config.OperatingSystemDistro; distro != nil && distro.IsSet() {
127+
if distro := config.OperatingSystemDistro; distro.IsSet() {
132128
table.AddRow("OPERATING SYSTEM DISTRIBUTION", *distro.Get())
133129
table.AddSeparator()
134130
}
135-
if version := config.OperatingSystemVersion; version != nil && version.IsSet() {
131+
if version := config.OperatingSystemVersion; version.IsSet() {
136132
table.AddRow("OPERATING SYSTEM VERSION", *version.Get())
137133
table.AddSeparator()
138134
}
@@ -142,9 +138,9 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.Image) error
142138
}
143139
}
144140

145-
if resp.Labels != nil && len(*resp.Labels) > 0 {
141+
if resp.Labels != nil && len(resp.Labels) > 0 {
146142
labels := []string{}
147-
for key, value := range *resp.Labels {
143+
for key, value := range resp.Labels {
148144
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
149145
}
150146
table.AddRow("LABELS", strings.Join(labels, "\n"))

internal/cmd/image/describe/describe_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5555
}
5656

5757
func fixtureRequest(mods ...func(request *iaas.ApiGetImageRequest)) iaas.ApiGetImageRequest {
58-
request := testClient.GetImage(testCtx, testProjectId, testRegion, testImageId[0])
58+
request := testClient.DefaultAPI.GetImage(testCtx, testProjectId, testRegion, testImageId[0])
5959
for _, mod := range mods {
6060
mod(&request)
6161
}
@@ -194,7 +194,7 @@ func TestBuildRequest(t *testing.T) {
194194
request := buildRequest(testCtx, tt.model, testClient)
195195
diff := cmp.Diff(request, tt.expectedRequest,
196196
cmp.AllowUnexported(tt.expectedRequest),
197-
cmpopts.EquateComparable(testCtx),
197+
cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}),
198198
)
199199
if diff != "" {
200200
t.Fatalf("Data does not match: %s", diff)
@@ -230,24 +230,24 @@ func TestOutputResult(t *testing.T) {
230230
args: args{
231231
resp: &iaas.Image{
232232
Id: utils.Ptr(uuid.NewString()),
233-
Name: utils.Ptr("Image"),
233+
Name: "Image",
234234
Status: utils.Ptr("STATUS"),
235-
DiskFormat: utils.Ptr("format"),
235+
DiskFormat: "format",
236236
MinDiskSize: utils.Ptr(int64(0)),
237237
MinRam: utils.Ptr(int64(0)),
238238
Config: &iaas.ImageConfig{
239239
Architecture: utils.Ptr("architecture"),
240240
OperatingSystem: utils.Ptr("os"),
241-
OperatingSystemDistro: iaas.NewNullableString(utils.Ptr("os distro")),
242-
OperatingSystemVersion: iaas.NewNullableString(utils.Ptr("0.00.0")),
241+
OperatingSystemDistro: *iaas.NewNullableString(utils.Ptr("os distro")),
242+
OperatingSystemVersion: *iaas.NewNullableString(utils.Ptr("0.00.0")),
243243
Uefi: utils.Ptr(true),
244244
},
245-
Labels: utils.Ptr(map[string]any{
245+
Labels: map[string]any{
246246
"label1": true,
247247
"label2": false,
248248
"label3": 42,
249249
"foo": "bar",
250-
}),
250+
},
251251
},
252252
},
253253
wantErr: false,

internal/cmd/key-pair/describe/describe.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
104104
}
105105

106106
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetKeyPairRequest {
107-
return apiClient.GetKeyPair(ctx, model.KeyPairName)
107+
return apiClient.DefaultAPI.GetKeyPair(ctx, model.KeyPairName)
108108
}
109109

110110
func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, keyPair iaas.Keypair) error {
@@ -113,7 +113,7 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool,
113113
details, err := json.MarshalIndent(keyPair, "", " ")
114114
if showOnlyPublicKey {
115115
onlyPublicKey := map[string]string{
116-
"publicKey": *keyPair.PublicKey,
116+
"publicKey": keyPair.PublicKey,
117117
}
118118
details, err = json.MarshalIndent(onlyPublicKey, "", " ")
119119
}
@@ -128,7 +128,7 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool,
128128
details, err := yaml.MarshalWithOptions(keyPair, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
129129
if showOnlyPublicKey {
130130
onlyPublicKey := map[string]string{
131-
"publicKey": *keyPair.PublicKey,
131+
"publicKey": keyPair.PublicKey,
132132
}
133133
details, err = yaml.MarshalWithOptions(onlyPublicKey, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
134134
}
@@ -141,16 +141,16 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool,
141141
return nil
142142
default:
143143
if showOnlyPublicKey {
144-
p.Outputln(*keyPair.PublicKey)
144+
p.Outputln(keyPair.PublicKey)
145145
return nil
146146
}
147147
table := tables.NewTable()
148148
table.AddRow("KEY PAIR NAME", utils.PtrString(keyPair.Name))
149149
table.AddSeparator()
150150

151-
if keyPair.Labels != nil && len(*keyPair.Labels) > 0 {
151+
if keyPair.Labels != nil && len(keyPair.Labels) > 0 {
152152
var labels []string
153-
for key, value := range *keyPair.Labels {
153+
for key, value := range keyPair.Labels {
154154
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
155155
}
156156
table.AddRow("LABELS", strings.Join(labels, "\n"))
@@ -160,9 +160,9 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool,
160160
table.AddRow("FINGERPRINT", utils.PtrString(keyPair.Fingerprint))
161161
table.AddSeparator()
162162

163-
truncatedPublicKey := ""
164-
if keyPair.PublicKey != nil {
165-
truncatedPublicKey = (*keyPair.PublicKey)[:maxLengthPublicKey] + "..."
163+
truncatedPublicKey := keyPair.PublicKey
164+
if len(keyPair.PublicKey) > maxLengthPublicKey {
165+
truncatedPublicKey = truncatedPublicKey[:maxLengthPublicKey] + "..."
166166
}
167167

168168
table.AddRow("PUBLIC KEY", truncatedPublicKey)

internal/cmd/key-pair/describe/describe_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5252
}
5353

5454
func fixtureRequest(mods ...func(request *iaas.ApiGetKeyPairRequest)) iaas.ApiGetKeyPairRequest {
55-
request := testClient.GetKeyPair(testCtx, testKeyPairName)
55+
request := testClient.DefaultAPI.GetKeyPair(testCtx, testKeyPairName)
5656
for _, mod := range mods {
5757
mod(&request)
5858
}
@@ -132,7 +132,7 @@ func TestBuildRequest(t *testing.T) {
132132

133133
diff := cmp.Diff(request, tt.expectedResult,
134134
cmp.AllowUnexported(tt.expectedResult),
135-
cmpopts.EquateComparable(testCtx),
135+
cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}),
136136
)
137137
if diff != "" {
138138
t.Fatalf("data does not match: %s", diff)

internal/cmd/network-area/describe/describe.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7979
var projects []string
8080

8181
if model.ShowAttachedProjects {
82-
projects, err = iaasUtils.ListAttachedProjects(ctx, apiClient, *model.OrganizationId, model.AreaId)
82+
projects, err = iaasUtils.ListAttachedProjects(ctx, apiClient.DefaultAPI, *model.OrganizationId, model.AreaId)
8383
if err != nil && errors.Is(err, iaasUtils.ErrItemsNil) {
8484
projects = []string{}
8585
} else if err != nil {
@@ -119,7 +119,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
119119
}
120120

121121
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetNetworkAreaRequest {
122-
return apiClient.GetNetworkArea(ctx, *model.OrganizationId, model.AreaId)
122+
return apiClient.DefaultAPI.GetNetworkArea(ctx, *model.OrganizationId, model.AreaId)
123123
}
124124

125125
func outputResult(p *print.Printer, outputFormat string, networkArea *iaas.NetworkArea, attachedProjects []string) error {
@@ -131,11 +131,11 @@ func outputResult(p *print.Printer, outputFormat string, networkArea *iaas.Netwo
131131
table := tables.NewTable()
132132
table.AddRow("ID", utils.PtrString(networkArea.Id))
133133
table.AddSeparator()
134-
table.AddRow("NAME", utils.PtrString(networkArea.Name))
134+
table.AddRow("NAME", networkArea.Name)
135135
table.AddSeparator()
136-
if networkArea.Labels != nil && len(*networkArea.Labels) > 0 {
136+
if networkArea.Labels != nil && len(networkArea.Labels) > 0 {
137137
var labels []string
138-
for key, value := range *networkArea.Labels {
138+
for key, value := range networkArea.Labels {
139139
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
140140
}
141141
table.AddRow("LABELS", strings.Join(labels, "\n"))

internal/cmd/network-area/describe/describe_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5858
}
5959

6060
func fixtureRequest(mods ...func(request *iaas.ApiGetNetworkAreaRequest)) iaas.ApiGetNetworkAreaRequest {
61-
request := testClient.GetNetworkArea(testCtx, testOrganizationId, testNetworkAreaId)
61+
request := testClient.DefaultAPI.GetNetworkArea(testCtx, testOrganizationId, testNetworkAreaId)
6262
for _, mod := range mods {
6363
mod(&request)
6464
}
@@ -173,7 +173,7 @@ func TestBuildRequest(t *testing.T) {
173173

174174
diff := cmp.Diff(request, tt.expectedRequest,
175175
cmp.AllowUnexported(tt.expectedRequest),
176-
cmpopts.EquateComparable(testCtx),
176+
cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}),
177177
)
178178
if diff != "" {
179179
t.Fatalf("Data does not match: %s", diff)

internal/cmd/network-area/network-range/describe/describe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 *iaas.APIClient) iaas.ApiGetNetworkAreaRangeRequest {
100-
req := apiClient.GetNetworkAreaRange(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.NetworkRangeId)
100+
req := apiClient.DefaultAPI.GetNetworkAreaRange(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.NetworkRangeId)
101101
return req
102102
}
103103

@@ -110,7 +110,7 @@ func outputResult(p *print.Printer, outputFormat string, networkRange *iaas.Netw
110110
table := tables.NewTable()
111111
table.AddRow("ID", utils.PtrString(networkRange.Id))
112112
table.AddSeparator()
113-
table.AddRow("Network range", utils.PtrString(networkRange.Prefix))
113+
table.AddRow("Network range", networkRange.Prefix)
114114

115115
err := table.Display(p)
116116
if err != nil {

internal/cmd/network-area/network-range/describe/describe_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6868
}
6969

7070
func fixtureRequest(mods ...func(request *iaas.ApiGetNetworkAreaRangeRequest)) iaas.ApiGetNetworkAreaRangeRequest {
71-
request := testClient.GetNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion, testNetworkRangeId)
71+
request := testClient.DefaultAPI.GetNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion, testNetworkRangeId)
7272
for _, mod := range mods {
7373
mod(&request)
7474
}
@@ -234,7 +234,7 @@ func TestBuildRequest(t *testing.T) {
234234

235235
diff := cmp.Diff(request, tt.expectedRequest,
236236
cmp.AllowUnexported(tt.expectedRequest),
237-
cmpopts.EquateComparable(testCtx),
237+
cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}),
238238
)
239239
if diff != "" {
240240
t.Fatalf("Data does not match: %s", diff)

0 commit comments

Comments
 (0)