MCPcopy Index your code
hub / github.com/github/gh-aw / renderFirewallDiffPrettySection

Function renderFirewallDiffPrettySection

pkg/cli/audit_diff_render.go:302–382  ·  view source on GitHub ↗

renderFirewallDiffPrettySection renders the firewall diff as a pretty console sub-section

(diff *FirewallDiff)

Source from the content-addressed store, hash-verified

300
301// renderFirewallDiffPrettySection renders the firewall diff as a pretty console sub-section
302func renderFirewallDiffPrettySection(diff *FirewallDiff) {
303 if diff == nil || isEmptyFirewallDiff(diff) {
304 return
305 }
306
307 fmt.Fprintln(os.Stderr, console.FormatSectionHeader("Firewall Changes"))
308 fmt.Fprintln(os.Stderr)
309
310 if len(diff.NewDomains) > 0 {
311 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("New Domains (%d)", len(diff.NewDomains))))
312 config := console.TableConfig{
313 Headers: []string{"Domain", "Status", "Requests", "Anomaly"},
314 Rows: make([][]string, 0, len(diff.NewDomains)),
315 }
316 for _, entry := range diff.NewDomains {
317 total := entry.Run2Allowed + entry.Run2Blocked
318 anomalyNote := formatAnomalyNote(entry.IsAnomaly, entry.AnomalyNote)
319 config.Rows = append(config.Rows, []string{
320 entry.Domain,
321 firewallStatusEmoji(entry.Run2Status) + " " + entry.Run2Status,
322 strconv.Itoa(total),
323 anomalyNote,
324 })
325 }
326 fmt.Fprint(os.Stderr, console.RenderTable(config))
327 }
328
329 if len(diff.RemovedDomains) > 0 {
330 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Removed Domains (%d)", len(diff.RemovedDomains))))
331 config := console.TableConfig{
332 Headers: []string{"Domain", "Previous Status", "Previous Requests"},
333 Rows: make([][]string, 0, len(diff.RemovedDomains)),
334 }
335 for _, entry := range diff.RemovedDomains {
336 total := entry.Run1Allowed + entry.Run1Blocked
337 config.Rows = append(config.Rows, []string{
338 entry.Domain,
339 firewallStatusEmoji(entry.Run1Status) + " " + entry.Run1Status,
340 strconv.Itoa(total),
341 })
342 }
343 fmt.Fprint(os.Stderr, console.RenderTable(config))
344 }
345
346 if len(diff.StatusChanges) > 0 {
347 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Status Changes (%d)", len(diff.StatusChanges))))
348 config := console.TableConfig{
349 Headers: []string{"Domain", "Before", "After", "Anomaly"},
350 Rows: make([][]string, 0, len(diff.StatusChanges)),
351 }
352 for _, entry := range diff.StatusChanges {
353 anomalyNote := formatAnomalyNote(entry.IsAnomaly, entry.AnomalyNote)
354 config.Rows = append(config.Rows, []string{
355 entry.Domain,
356 firewallStatusEmoji(entry.Run1Status) + " " + entry.Run1Status,
357 firewallStatusEmoji(entry.Run2Status) + " " + entry.Run2Status,
358 anomalyNote,
359 })

Callers 1

Calls 6

FormatSectionHeaderFunction · 0.92
FormatInfoMessageFunction · 0.92
RenderTableFunction · 0.92
isEmptyFirewallDiffFunction · 0.85
formatAnomalyNoteFunction · 0.85
firewallStatusEmojiFunction · 0.85

Tested by

no test coverage detected