Files
cloud-ip-validator/scripts/httpstub/main.go
T

43 lines
1.5 KiB
Go
Raw Normal View History

2026-08-21 11:04:49 +03:00
// Command httpstub is a trivial local HTTP server used only by
// scripts/run-local-e2e.sh, standing in for two kinds of real internet
// resources so the offline end-to-end harness needs no real internet
// access:
// - "/" always returns 200 OK — stands in for the real outbound egress
// targets (hub.docker.com, github.com, packages.ubuntu.com).
// - "/ip" echoes the caller's remote address as plain text — stands in
// for the external IP-echo service the validator-agent's self-check
// queries in production (see internal/agentcore.detectPublicIP and
// config.SelfCheckCfg.IPEchoURLs). Because httpstub runs locally, this
// only produces a meaningful self-check signal in the harness because
// the "floating IP" under test is itself the loopback address the
// caller genuinely connects from — it is not a stand-in for OpenStack's
// SNAT behavior.
2026-08-21 07:34:45 +03:00
package main
import (
"flag"
2026-08-21 11:04:49 +03:00
"fmt"
2026-08-21 07:34:45 +03:00
"log"
2026-08-21 11:04:49 +03:00
"net"
2026-08-21 07:34:45 +03:00
"net/http"
)
func main() {
addr := flag.String("addr", ":9090", "address to listen on")
flag.Parse()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("stub ok\n"))
})
2026-08-21 11:04:49 +03:00
http.HandleFunc("/ip", func(w http.ResponseWriter, r *http.Request) {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
host = r.RemoteAddr
}
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(w, host)
})
2026-08-21 07:34:45 +03:00
log.Printf("httpstub listening on %s", *addr)
log.Fatal(http.ListenAndServe(*addr, nil))
}