44 "context"
55 "encoding/json"
66 "fmt"
7- "strings"
8-
97 "github.com/goccy/go-yaml"
108 "github.com/spf13/cobra"
119 "github.com/stackitcloud/stackit-cli/internal/pkg/args"
@@ -17,6 +15,7 @@ import (
1715 "github.com/stackitcloud/stackit-cli/internal/pkg/tables"
1816 "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1917 "github.com/stackitcloud/stackit-sdk-go/services/iaas"
18+ "strings"
2019)
2120
2221type inputModel struct {
@@ -114,7 +113,11 @@ func outputResult(p *print.Printer, model *inputModel, resp *iaas.SecurityGroup)
114113
115114 return nil
116115 default :
116+ var content []tables.Table
117+
117118 table := tables .NewTable ()
119+ table .SetTitle ("SECURITY GROUP" )
120+
118121 if id := resp .Id ; id != nil {
119122 table .AddRow ("ID" , * id )
120123 }
@@ -130,16 +133,80 @@ func outputResult(p *print.Printer, model *inputModel, resp *iaas.SecurityGroup)
130133 table .AddSeparator ()
131134 }
132135
136+ if stateful := resp .Stateful ; stateful != nil {
137+ table .AddRow ("STATEFUL" , * stateful )
138+ table .AddSeparator ()
139+ }
140+
133141 if resp .Labels != nil && len (* resp .Labels ) > 0 {
134- labels := []string {}
142+ var labels []string
135143 for key , value := range * resp .Labels {
136144 labels = append (labels , fmt .Sprintf ("%s: %s" , key , value ))
137145 }
138146 table .AddRow ("LABELS" , strings .Join (labels , "\n " ))
139147 table .AddSeparator ()
140148 }
141149
142- if err := table .Display (p ); err != nil {
150+ if resp .CreatedAt != nil {
151+ table .AddRow ("CREATED AT" , utils .ConvertTimePToDateTimeString (resp .CreatedAt ))
152+ table .AddSeparator ()
153+ }
154+
155+ if resp .UpdatedAt != nil {
156+ table .AddRow ("UPDATED AT" , utils .ConvertTimePToDateTimeString (resp .UpdatedAt ))
157+ table .AddSeparator ()
158+ }
159+
160+ content = append (content , table )
161+
162+ if resp .Rules != nil && len (* resp .Rules ) > 0 {
163+ rulesTable := tables .NewTable ()
164+ rulesTable .SetTitle ("RULES" )
165+ rulesTable .SetHeader (
166+ "ID" ,
167+ "DESCRIPTION" ,
168+ "PROTOCOL" ,
169+ "DIRECTION" ,
170+ "ETHER TYPE" ,
171+ "PORT RANGE" ,
172+ "IP RANGE" ,
173+ "ICMP PARAMETERS" ,
174+ "REMOTE SECURITY GROUP ID" ,
175+ )
176+
177+ for _ , rule := range * resp .Rules {
178+ var portRange string
179+ if rule .PortRange != nil {
180+ portRange = fmt .Sprintf ("%s-%s" , utils .PtrString (rule .PortRange .Min ), utils .PtrString (rule .PortRange .Max ))
181+ }
182+
183+ var protocol string
184+ if rule .Protocol != nil {
185+ protocol = utils .PtrString (rule .Protocol .Name )
186+ }
187+
188+ var icmpParameter string
189+ if rule .IcmpParameters != nil {
190+ icmpParameter = fmt .Sprintf ("type: %s, code: %s" , utils .PtrString (rule .IcmpParameters .Type ), utils .PtrString (rule .IcmpParameters .Code ))
191+ }
192+
193+ rulesTable .AddRow (
194+ utils .PtrString (rule .Id ),
195+ utils .PtrString (rule .Description ),
196+ protocol ,
197+ utils .PtrString (rule .Direction ),
198+ utils .PtrString (rule .Ethertype ),
199+ portRange ,
200+ utils .PtrString (rule .IpRange ),
201+ icmpParameter ,
202+ utils .PtrString (rule .RemoteSecurityGroupId ),
203+ )
204+ }
205+
206+ content = append (content , rulesTable )
207+ }
208+
209+ if err := tables .DisplayTables (p , content ); err != nil {
143210 return fmt .Errorf ("render table: %w" , err )
144211 }
145212
0 commit comments