-
Notifications
You must be signed in to change notification settings - Fork 2
/
mesh-gateway-sidecar-boot.sh
executable file
·80 lines (68 loc) · 1.82 KB
/
mesh-gateway-sidecar-boot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
set -euo pipefail
readonly mode="${SBOOT_MODE:-}"
readonly agent_tls="${SBOOT_AGENT_TLS:-}"
readonly agent_grpc_tls="${SBOOT_AGENT_GRPC_TLS:-}"
readonly partition="${SBOOT_PARTITION:-}"
api_args=()
acl_api_args=()
case "${mode}" in
insecure)
;;
direct)
readonly token_file="${SBOOT_TOKEN_FILE:-}"
if [[ -z "${token_file}" ]]; then
echo "missing required env var SBOOT_TOKEN_FILE" >&2
exit 1
fi
token=''
while : ; do
read -r token < "${token_file}" || true
if [[ -n "${token}" ]]; then
break
fi
echo "waiting for secret to show up at ${token_file}..."
sleep 0.1
done
api_args+=( -token-file "${token_file}" )
acl_api_args+=( -token-file "${token_file}" )
;;
*)
echo "unknown mode: $mode" >&2
exit 1
;;
esac
if [[ -n "${partition}" ]]; then
api_args+=( -partition "${partition}" )
acl_api_args+=( -partition "${partition}" )
fi
if [[ -n "$agent_tls" ]]; then
api_args+=(
-ca-file /tls/consul-agent-ca.pem
-http-addr https://127.0.0.1:8501
)
else
api_args+=( -http-addr http://127.0.0.1:8500 )
fi
acl_api_args+=( -http-addr http://127.0.0.1:8500 )
grpc_args=()
if [[ -n "$agent_grpc_tls" ]]; then
grpc_args+=( -grpc-addr https://127.0.0.1:8503 )
else
grpc_args+=( -grpc-addr http://127.0.0.1:8502 )
fi
if [[ "${mode}" != "insecure" ]]; then
while : ; do
if consul acl token read "${acl_api_args[@]}" -self ; then
break
fi
echo "waiting for ACLs to work..."
sleep 0.1
done
fi
echo "Launching mesh-gateway proxy..."
exec consul connect envoy \
-register \
-mesh-gateway \
"${grpc_args[@]}" "${api_args[@]}" \
"$@"