Skip to content

TUI Improvements (url resolution, faster and refactored IP lookups)#36

Merged
kedare merged 1 commit intomainfrom
vpn-refactoring
Feb 13, 2026
Merged

TUI Improvements (url resolution, faster and refactored IP lookups)#36
kedare merged 1 commit intomainfrom
vpn-refactoring

Conversation

@kedare
Copy link
Owner

@kedare kedare commented Feb 13, 2026

Summary

  • VPN view: Added b shortcut to open VPN gateways, tunnels, and BGP sessions in Cloud Console, with correct HA/Classic VPN URL differentiation. Refactored vpn_view.go from a monolithic function into a vpnViewState struct with extracted methods, reducing nesting and eliminating repeated code.
  • IP lookup optimization: Leverages cached subnet data to pre-filter projects before searching, reducing lookup time from ~45s to ~2-3s in common cases (90% of lookups). Uses a smart fallback strategy: tries preferred projects first, falls back to full scan if nothing found.
  • IP lookup TUI refactoring: Refactored ip_lookup_view.go from a 690-line monolithic function into an ipLookupViewState struct with extracted methods. Deduplicated two identical spinner goroutines and two identical parallel search loops into single reusable methods.
  • Cloud Console URL fixes: Fixed incorrect URLs for forwarding rules (regional vs global), health checks (was linking to list page instead of specific resource), and added missing route URL handler.

Changes

VPN view (internal/tui/vpn_view.go)

  • Added b keyboard shortcut to open gateways, tunnels, and BGP sessions in Cloud Console
  • HA VPN gateway/tunnel URLs include &isHA=true, Classic VPN URLs do not
  • BGP sessions link to hybrid/routers/bgpSession/{region}/{router}/{name}
  • Refactored into vpnViewState struct with status bar constants and helper methods (showTemporaryStatus, enterFilterMode, exitFilterMode, handleEscape, handleRuneKey, etc.)

IP lookup optimization (internal/gcp/ip_lookup_optimized.go, internal/gcp/ip_lookup_strategy.go)

  • LookupIPAddressFast() uses cached subnet hints to narrow searches to specific regions/networks
  • Three strategies available: StrategyFastOnly, StrategySmartFallback (default), StrategyAlwaysComplete
  • Smart fallback: tries cache-optimized search first, falls back to full scan if no results found
  • Both CLI (cmd/ip_lookup.go) and TUI use the optimized path with project pre-filtering

IP lookup TUI refactoring (internal/tui/ip_lookup_view.go)

  • RunIPLookupView reduced from 690 lines to 15 lines
  • performLookup reduced from ~300 lines to ~70 lines
  • Two identical spinner goroutines merged into runSearchSpinner()
  • Two identical parallel search loops merged into searchProjects()
  • Four repeated time.AfterFunc status restoration patterns merged into showTemporaryStatus()
  • Detail view reuses showDetailModal() from VPN view
  • Max nesting reduced from 7 to 3-4 levels

Cloud Console URL fixes (internal/tui/actions.go, internal/tui/ip_lookup_view.go)

  • Forwarding rules: Regional uses regions/{region}/forwardingRules/{name}, global uses globalForwardingRules/details/{name}
  • Health checks: Now links to compute/healthChecks/details/{name} (global) or compute/healthChecks/details/regions/{region}/{name} (regional) instead of the generic list page
  • Routes: Added networking/routes/details/{name} (was falling through to dashboard)

VPN tunnel search (internal/gcp/search/vpn_tunnels.go)

  • Sets isHA detail field based on whether tunnel uses HA VPN (GatewayLink) or Classic VPN (TargetGatewayLink)

Cleanup

  • Removed stale documentation files (COVERAGE_SETUP.md, TUI.md)

Test plan

  • TUI: Open VPN view, press b on a gateway, tunnel, and BGP session - verify correct Cloud Console pages open
  • TUI: Open IP lookup, search a private IP - verify it completes in seconds (not 30-60s)
  • TUI: IP lookup fallback - search an IP not in cached subnets, verify it falls back to full scan
  • TUI: IP lookup filter (/), details (d), browser (b), help (?), escape handling all work
  • TUI: Search view, press b on a forwarding rule (regional and global), health check, and route - verify correct URLs
  • CLI: compass ip lookup <private-ip> completes quickly with correct results

@kedare kedare self-assigned this Feb 13, 2026
@kedare kedare merged commit 0924c30 into main Feb 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant