Skip to content

Commit 2e64f20

Browse files
committed
fix NPE
1 parent 09846ac commit 2e64f20

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

internal/cmd/beta/security-group-rule/describe/describe.go

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,48 @@ func outputResult(p *print.Printer, outputFormat string, securityGroupRule *iaas
134134
table := tables.NewTable()
135135
table.AddRow("ID", *securityGroupRule.Id)
136136
table.AddSeparator()
137-
table.AddRow("PROTOCOL NAME", *securityGroupRule.Protocol.Name)
138-
table.AddSeparator()
139-
table.AddRow("PROTOCOL NUMBER", *securityGroupRule.Protocol.Number)
140-
table.AddSeparator()
137+
138+
if securityGroupRule.Protocol != nil {
139+
if securityGroupRule.Protocol.Name != nil {
140+
table.AddRow("PROTOCOL NAME", *securityGroupRule.Protocol.Name)
141+
table.AddSeparator()
142+
}
143+
144+
if securityGroupRule.Protocol.Number != nil {
145+
table.AddRow("PROTOCOL NUMBER", *securityGroupRule.Protocol.Number)
146+
table.AddSeparator()
147+
}
148+
}
149+
141150
table.AddRow("DIRECTION", *securityGroupRule.Direction)
142151
table.AddSeparator()
143-
table.AddRow("START PORT", *securityGroupRule.PortRange.Min)
144-
table.AddSeparator()
145-
table.AddRow("END PORT", *securityGroupRule.PortRange.Max)
146-
table.AddSeparator()
147-
table.AddRow("ETHER TYPE", *securityGroupRule.Ethertype)
148-
table.AddSeparator()
149-
table.AddRow("IP RANGE", *securityGroupRule.IpRange)
150-
table.AddSeparator()
151-
table.AddRow("REMOTE SECURITY GROUP", *securityGroupRule.RemoteSecurityGroupId)
152-
table.AddSeparator()
152+
153+
if securityGroupRule.PortRange != nil {
154+
if securityGroupRule.PortRange.Min != nil {
155+
table.AddRow("START PORT", *securityGroupRule.PortRange.Min)
156+
table.AddSeparator()
157+
}
158+
159+
if securityGroupRule.PortRange.Max != nil {
160+
table.AddRow("END PORT", *securityGroupRule.PortRange.Max)
161+
table.AddSeparator()
162+
}
163+
}
164+
165+
if securityGroupRule.Ethertype != nil {
166+
table.AddRow("ETHER TYPE", *securityGroupRule.Ethertype)
167+
table.AddSeparator()
168+
}
169+
170+
if securityGroupRule.IpRange != nil {
171+
table.AddRow("IP RANGE", *securityGroupRule.IpRange)
172+
table.AddSeparator()
173+
}
174+
175+
if securityGroupRule.RemoteSecurityGroupId != nil {
176+
table.AddRow("REMOTE SECURITY GROUP", *securityGroupRule.RemoteSecurityGroupId)
177+
table.AddSeparator()
178+
}
153179

154180
err := table.Display(p)
155181
if err != nil {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,19 @@ func outputResult(p *print.Printer, outputFormat string, securityGroupRules []ia
169169
table.SetHeader("ID", "ETHER TYPE", "DIRECTION", "PROTOCOL")
170170

171171
for _, securityGroupRule := range securityGroupRules {
172-
table.AddRow(*securityGroupRule.Id, *securityGroupRule.Ethertype, *securityGroupRule.Direction, *securityGroupRule.Protocol.Name)
172+
etherType := ""
173+
if securityGroupRule.Ethertype != nil {
174+
etherType = *securityGroupRule.Ethertype
175+
}
176+
177+
protocolName := ""
178+
if securityGroupRule.Protocol != nil {
179+
if securityGroupRule.Protocol.Name != nil {
180+
protocolName = *securityGroupRule.Protocol.Name
181+
}
182+
}
183+
184+
table.AddRow(*securityGroupRule.Id, etherType, *securityGroupRule.Direction, protocolName)
173185
table.AddSeparator()
174186
}
175187

0 commit comments

Comments
 (0)