|
1 | 1 | # shellcheck shell=bash |
2 | | -# Drop GOPROXY entries that aren't usable from the current environment, keeping |
3 | | -# the rest. Probes the endpoint the way Go would (an HTTPS request with cert |
4 | | -# verification) and strips it if that fails. |
| 2 | +# Drop the GOPROXY entry that isn't usable from the current environment (hosts |
| 3 | +# ending in .fabric.dog), keeping the rest. Probes the endpoint the way Go would |
| 4 | +# (an HTTPS request with cert verification) and strips it only if that fails; |
| 5 | +# missing curl counts as unusable. |
5 | 6 | # |
6 | 7 | # Source this file (don't execute) so the change is visible to the caller: |
7 | 8 | # . tools/ci/sanitize-goproxy.sh |
8 | 9 | # Safe to source repeatedly; never empties GOPROXY. |
9 | 10 |
|
10 | | -__sgp_host='depot-read-api-go.rapid-dependency-management-depot.all-clusters.local-dc.fabric.dog' |
11 | | -__sgp_probe_url="https://${__sgp_host}:8443/magicmirror/magicmirror/@current/sumdb/sum.golang.org/supported" |
| 11 | +__sgp_probe_url="https://depot-read-api-go.rapid-dependency-management-depot.all-clusters.local-dc.fabric.dog:8443/magicmirror/magicmirror/@current/sumdb/sum.golang.org/supported" |
12 | 12 |
|
13 | 13 | # Returns 0 if the endpoint completes a request over verified TLS. No --fail: we |
14 | | -# only care that the request completes, not its HTTP status. Missing curl counts |
15 | | -# as not usable. |
| 14 | +# only care that the request completes, not its HTTP status. |
16 | 15 | __sgp_usable() { |
17 | | - command -v curl >/dev/null 2>&1 || return 1 |
18 | | - curl --silent --output /dev/null --connect-timeout 3 --max-time 5 "$__sgp_probe_url" |
19 | | -} |
20 | | - |
21 | | -# Drop entries whose host ends in .fabric.dog, keeping the '|' separators and |
22 | | -# every other entry. |
23 | | -__sgp_strip() { |
24 | | - printf '%s' "${1-}" \ |
25 | | - | tr '|' '\n' \ |
26 | | - | grep -vE '^https?://[^/]*\.fabric\.dog(:[0-9]+)?(/|$)' \ |
27 | | - | paste -sd '|' - |
| 16 | + command -v curl >/dev/null 2>&1 \ |
| 17 | + && curl --silent --output /dev/null --connect-timeout 3 --max-time 5 "$__sgp_probe_url" |
28 | 18 | } |
29 | 19 |
|
30 | 20 | case "${GOPROXY-}" in |
31 | 21 | *.fabric.dog*) |
32 | | - if __sgp_usable; then |
33 | | - echo "sanitize-goproxy: endpoint usable here; keeping it in GOPROXY" >&2 |
34 | | - else |
35 | | - GOPROXY="$(__sgp_strip "${GOPROXY-}")" |
| 22 | + if ! __sgp_usable; then |
| 23 | + GOPROXY="$(printf '%s' "$GOPROXY" | tr '|' '\n' \ |
| 24 | + | grep -vE '^https?://[^/]*\.fabric\.dog(:[0-9]+)?(/|$)' | paste -sd '|' -)" |
36 | 25 | export GOPROXY |
37 | 26 | echo "sanitize-goproxy: endpoint unusable here; stripped it from GOPROXY" >&2 |
38 | 27 | fi |
|
0 commit comments