Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/cmd/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/spf13/cobra"
)

var logProxyCmd = logger.New("cmd:proxy")

// Proxy subcommand flag variables
var (
proxyGuardWasm string
Expand All @@ -41,9 +43,12 @@ const containerGuardWasmPath = "/guards/github/00-github-guard.wasm"
// detectGuardWasm returns the baked-in container guard path if it exists,
// or empty string if not found (requiring the user to specify --guard-wasm).
func detectGuardWasm() string {
logProxyCmd.Printf("Checking for baked-in guard at %s", containerGuardWasmPath)
if _, err := os.Stat(containerGuardWasmPath); err == nil {
logProxyCmd.Printf("Auto-detected baked-in guard: %s", containerGuardWasmPath)
return containerGuardWasmPath
}
logProxyCmd.Print("Baked-in guard not found, --guard-wasm flag required")
Comment on lines 47 to +51
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message "Baked-in guard not found" is logged for any os.Stat error. If the file exists but Stat fails (e.g., permission/IO error), this is misleading and hides the real cause. Consider branching on os.IsNotExist(err) for the 'not found' message, and otherwise log the error (or include it in the debug output) before returning.

Suggested change
if _, err := os.Stat(containerGuardWasmPath); err == nil {
logProxyCmd.Printf("Auto-detected baked-in guard: %s", containerGuardWasmPath)
return containerGuardWasmPath
}
logProxyCmd.Print("Baked-in guard not found, --guard-wasm flag required")
_, err := os.Stat(containerGuardWasmPath)
if err == nil {
logProxyCmd.Printf("Auto-detected baked-in guard: %s", containerGuardWasmPath)
return containerGuardWasmPath
}
if os.IsNotExist(err) {
logProxyCmd.Print("Baked-in guard not found, --guard-wasm flag required")
} else {
logProxyCmd.Printf("Error checking for baked-in guard at %s: %v", containerGuardWasmPath, err)
}

Copilot uses AI. Check for mistakes.
return ""
}

Expand Down Expand Up @@ -115,6 +120,8 @@ func runProxy(cmd *cobra.Command, args []string) error {
ctx, cancel := signal.NotifyContext(cmd.Context(), os.Interrupt, syscall.SIGTERM)
defer cancel()

logProxyCmd.Printf("Starting proxy: listen=%s, guard=%s, mode=%s, tls=%v", proxyListen, proxyGuardWasm, proxyDIFCMode, proxyTLS)

if err := ValidateDIFCMode(proxyDIFCMode); err != nil {
return fmt.Errorf("invalid --guards-mode flag: %w", err)
}
Expand Down Expand Up @@ -155,6 +162,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
apiURL = proxy.DefaultGitHubAPIBase
}
logger.LogInfo("startup", "Upstream GitHub API URL: %s", apiURL)
logProxyCmd.Printf("Resolved GitHub API URL: %s, explicit flag=%v", apiURL, proxyAPIURL != "")

// Create the proxy server
proxySrv, err := proxy.New(ctx, proxy.Config{
Expand All @@ -177,6 +185,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
if tlsDir == "" {
tlsDir = filepath.Join(proxyLogDir, "proxy-tls")
}
logProxyCmd.Printf("Generating TLS certificates in: %s", tlsDir)
tlsCfg, err = proxy.GenerateSelfSignedTLS(tlsDir)
if err != nil {
return fmt.Errorf("failed to generate TLS certificates: %w", err)
Expand Down
Loading