Download this file
| 1 | //go:build testbuild |
| 2 | |
| 3 | package egress |
| 4 | |
| 5 | import ( |
| 6 | "net/netip" |
| 7 | "os" |
| 8 | "strings" |
| 9 | ) |
| 10 | |
| 11 | // A test build's relay may carry an allowed host to a fake provider on |
| 12 | // a loopback address (a real Pi against a fake TensorX), named in |
| 13 | // EQUIPO_TEST_EGRESS_UPSTREAM as host=127.0.0.1:port pairs separated by |
| 14 | // commas. Only hosts the policy already allows reach here, and only a |
| 15 | // loopback address is taken. A release build never passes -tags |
| 16 | // testbuild, so has no such route. |
| 17 | func init() { |
| 18 | upstreamOverride = func(host string) (string, bool) { |
| 19 | for _, pair := range strings.Split(os.Getenv("EQUIPO_TEST_EGRESS_UPSTREAM"), ",") { |
| 20 | name, to, ok := strings.Cut(pair, "=") |
| 21 | if !ok || name != host { |
| 22 | continue |
| 23 | } |
| 24 | addr, err := netip.ParseAddrPort(to) |
| 25 | if err == nil && addr.Addr().IsLoopback() { |
| 26 | return to, true |
| 27 | } |
| 28 | } |
| 29 | return "", false |
| 30 | } |
| 31 | } |
| 32 | |