File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ # Save the exact stdout bytes produced by a Black Belt response.
5+ # Network transport is opt-in through BBEA_TRANSPORT.
6+ OUTPUT=" ${1:? response file required} "
7+
8+ mkdir -p " $( dirname -- " $OUTPUT " ) "
9+
10+ if [[ " ${BBEA_NO_SAVE:- 0} " != " 1" ]]; then
11+ cat > " $OUTPUT "
12+ else
13+ cat > /dev/null
14+ fi
15+
16+ if [[ -n " ${BBEA_TRANSPORT:- } " ]]; then
17+ transport=" $BBEA_TRANSPORT "
18+ case " $transport " in
19+ https://* |http://* )
20+ if [[ " $transport " == http://* && " ${BBEA_ALLOW_INSECURE:- 0} " != " 1" ]]; then
21+ echo " Refusing plaintext HTTP transport; use HTTPS or set BBEA_ALLOW_INSECURE=1." >&2
22+ exit 8
23+ fi
24+ curl --fail-with-body --silent --show-error --data-binary " @$OUTPUT " \
25+ -H ' Content-Type: application/octet-stream' " $transport " > /dev/null
26+ ;;
27+ ssh://* )
28+ target=" ${transport# ssh:// } "
29+ hostpart=" ${target%%/* } "
30+ remotepath=" /${target#*/ } "
31+ if [[ " $target " == " $hostpart " ]]; then
32+ echo " SSH transport requires ssh://user@host/path." >&2
33+ exit 9
34+ fi
35+ scp -- " $OUTPUT " " ${hostpart} :${remotepath} "
36+ ;;
37+ telnet://* |raw://* )
38+ if [[ " ${BBEA_ALLOW_INSECURE:- 0} " != " 1" ]]; then
39+ echo " Refusing plaintext Telnet/Raw transport; set BBEA_ALLOW_INSECURE=1 explicitly." >&2
40+ exit 10
41+ fi
42+ target=" ${transport#*:// } "
43+ host=" ${target%%:* } "
44+ port=" ${target##*: } "
45+ command -v nc > /dev/null 2>&1 || { echo " nc is required for raw/telnet transport." >&2 ; exit 11; }
46+ nc " $host " " $port " < " $OUTPUT "
47+ ;;
48+ * )
49+ echo " Unsupported BBEA_TRANSPORT: $transport " >&2
50+ exit 12
51+ ;;
52+ esac
53+ fi
You can’t perform that action at this time.
0 commit comments