MCPcopy Create free account
hub / github.com/github/gh-aw / parseFirewallLogs

Function parseFirewallLogs

pkg/cli/logs_parsing_firewall.go:30–233  ·  view source on GitHub ↗

parseFirewallLogs runs the JavaScript firewall log parser and writes markdown to firewall.md

(runDir string, verbose bool)

Source from the content-addressed store, hash-verified

28
29// parseFirewallLogs runs the JavaScript firewall log parser and writes markdown to firewall.md
30func parseFirewallLogs(runDir string, verbose bool) error {
31 logsParsingFirewallLog.Printf("Parsing firewall logs in: %s", runDir)
32 // Get the firewall log parser script
33 jsScript := workflow.GetLogParserScript("parse_firewall_logs")
34 if jsScript == "" {
35 logsParsingFirewallLog.Print("Failed to get firewall log parser script")
36 if verbose {
37 fmt.Fprintln(os.Stderr, console.FormatWarningMessage("Failed to get firewall log parser script"))
38 }
39 return nil
40 }
41
42 // Check if squid logs directory exists in the run directory
43 // The logs could be in several locations depending on the AWF version and artifact structure.
44
45 logsDir, err := findFirewallLogsDir(runDir)
46 if err != nil {
47 return err
48 }
49 if logsDir == "" {
50 logsParsingFirewallLog.Print("No firewall logs found, skipping parsing")
51 // No firewall logs found - this is not an error, just skip parsing
52 if verbose {
53 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("No firewall logs found in %s, skipping firewall log parsing", filepath.Base(runDir))))
54 }
55 return nil
56 }
57
58 if verbose {
59 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Found firewall logs in "+logsDir))
60 }
61
62 // Create a temporary directory for running the parser
63 tempDir, err := os.MkdirTemp("", "firewall_log_parser")
64 if err != nil {
65 return fmt.Errorf("failed to create temp dir: %w", err)
66 }
67 defer os.RemoveAll(tempDir)
68
69 // Create a Node.js script that mimics the GitHub Actions environment
70 // The firewall parser expects logs in /tmp/gh-aw/squid-logs-{workflow}/
71 // We'll set GITHUB_WORKFLOW to a value that makes the parser look in our temp directory
72 nodeScript := fmt.Sprintf(`
73const fs = require('fs');
74const path = require('path');
75
76// Mock @actions/core for the parser
77const core = {
78 summary: {
79 addRaw: function(content) {
80 this._content = content;
81 return this;
82 },
83 write: function() {
84 console.log(this._content);
85 },
86 _content: ''
87 },

Callers 4

DownloadWorkflowLogsFunction · 0.70

Calls 7

GetLogParserScriptFunction · 0.92
FormatWarningMessageFunction · 0.92
FormatInfoMessageFunction · 0.92
findFirewallLogsDirFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1