@@ -33,7 +33,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
3333 cmd := & cobra.Command {
3434 Use : fmt .Sprintf ("describe %s" , loadbalancerNameArg ),
3535 Short : "Describes an application loadbalancer" ,
36- Long : "Describes an application loadbalancer ." ,
36+ Long : "Describes an application alb ." ,
3737 Args : args .SingleArg (loadbalancerNameArg , nil ),
3838 Example : examples .Build (
3939 examples .NewExample (
@@ -117,33 +117,104 @@ func outputResult(p *print.Printer, outputFormat string, response *alb.LoadBalan
117117
118118 return nil
119119 default :
120- table := tables .NewTable ()
121- table .AddRow ("EXTERNAL ADDRESS" , utils .PtrString (response .ExternalAddress ))
122- table .AddSeparator ()
123- var numErrors int
124- if response .Errors != nil {
125- numErrors = len (* response .Errors )
126- }
127- table .AddRow ("NUMBER OF ERRORS" , numErrors )
128- table .AddSeparator ()
129- table .AddRow ("PLAN ID" , utils .PtrString (response .PlanId ))
130- table .AddSeparator ()
131- table .AddRow ("REGION" , utils .PtrString (response .Region ))
132- table .AddSeparator ()
133- table .AddRow ("STATUS" , utils .PtrString (response .Status ))
134- table .AddSeparator ()
135- table .AddRow ("VERSION" , utils .PtrString (response .Version ))
136- if response .Errors != nil {
137- table .AddSeparator ()
138- var builder strings.Builder
139- for _ , err := range * response .Errors {
140- builder .WriteString (fmt .Sprintf ("[%s] %s\n " , utils .PtrString (err .Type ), utils .PtrString (err .Description )))
141- }
142- table .AddRow ("ERRORS" , builder .String ())
120+ if err := outputResultAsTable (p , response ); err != nil {
121+ return err
143122 }
123+ }
144124
145- p .Outputln (table .Render ())
125+ return nil
126+ }
127+
128+ func outputResultAsTable (p * print.Printer , loadbalancer * alb.LoadBalancer ) error {
129+ content := []tables.Table {}
130+
131+ content = append (content , buildLoadBalancerTable (loadbalancer ))
132+
133+ if loadbalancer .Listeners != nil {
134+ content = append (content , buildListenersTable (* loadbalancer .Listeners ))
135+ }
136+
137+ if loadbalancer .TargetPools != nil {
138+ content = append (content , buildTargetPoolsTable (* loadbalancer .TargetPools ))
139+ }
140+
141+ err := tables .DisplayTables (p , content )
142+ if err != nil {
143+ return fmt .Errorf ("display output: %w" , err )
146144 }
147145
148146 return nil
149147}
148+
149+ func buildLoadBalancerTable (loadbalancer * alb.LoadBalancer ) tables.Table {
150+ acl := []string {}
151+ privateAccessOnly := false
152+ if loadbalancer .Options != nil {
153+ if loadbalancer .Options .AccessControl != nil && loadbalancer .Options .AccessControl .AllowedSourceRanges != nil {
154+ acl = * loadbalancer .Options .AccessControl .AllowedSourceRanges
155+ }
156+
157+ if loadbalancer .Options .PrivateNetworkOnly != nil {
158+ privateAccessOnly = * loadbalancer .Options .PrivateNetworkOnly
159+ }
160+ }
161+
162+ networkId := "-"
163+ if loadbalancer .Networks != nil && len (* loadbalancer .Networks ) > 0 {
164+ networks := * loadbalancer .Networks
165+ networkId = * networks [0 ].NetworkId
166+ }
167+
168+ externalAddress := utils .PtrStringDefault (loadbalancer .ExternalAddress , "-" )
169+
170+ errorDescriptions := []string {}
171+ if loadbalancer .Errors != nil && len ((* loadbalancer .Errors )) > 0 {
172+ for _ , err := range * loadbalancer .Errors {
173+ errorDescriptions = append (errorDescriptions , * err .Description )
174+ }
175+ }
176+
177+ table := tables .NewTable ()
178+ table .SetTitle ("Load Balancer" )
179+ table .AddRow ("NAME" , utils .PtrString (loadbalancer .Name ))
180+ table .AddSeparator ()
181+ table .AddRow ("STATE" , utils .PtrString (loadbalancer .Status ))
182+ table .AddSeparator ()
183+ if len (errorDescriptions ) > 0 {
184+ table .AddRow ("ERROR DESCRIPTIONS" , strings .Join (errorDescriptions , "\n " ))
185+ table .AddSeparator ()
186+ }
187+ table .AddRow ("PRIVATE ACCESS ONLY" , privateAccessOnly )
188+ table .AddSeparator ()
189+ table .AddRow ("ATTACHED PUBLIC IP" , externalAddress )
190+ table .AddSeparator ()
191+ table .AddRow ("ATTACHED NETWORK ID" , networkId )
192+ table .AddSeparator ()
193+ table .AddRow ("ACL" , acl )
194+ return table
195+ }
196+
197+ func buildListenersTable (listeners []alb.Listener ) tables.Table {
198+ table := tables .NewTable ()
199+ table .SetTitle ("Listeners" )
200+ table .SetHeader ("NAME" , "PORT" , "PROTOCOL" , "TARGET POOL" )
201+ for i := range listeners {
202+ listener := listeners [i ]
203+ table .AddRow (
204+ utils .PtrString (listener .Name ),
205+ utils .PtrString (listener .Port ),
206+ utils .PtrString (listener .Protocol ),
207+ )
208+ }
209+ return table
210+ }
211+
212+ func buildTargetPoolsTable (targetPools []alb.TargetPool ) tables.Table {
213+ table := tables .NewTable ()
214+ table .SetTitle ("Target Pools" )
215+ table .SetHeader ("NAME" , "PORT" , "TARGETS" )
216+ for _ , targetPool := range targetPools {
217+ table .AddRow (utils .PtrString (targetPool .Name ), utils .PtrString (targetPool .TargetPort ), len (* targetPool .Targets ))
218+ }
219+ return table
220+ }
0 commit comments