Skip to content

Commit 53e3b4f

Browse files
authored
Handle legacy Prysm token files (#2017)
1 parent 51d999d commit 53e3b4f

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

vc-utils/keymanager.sh

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,46 @@ call_api() {
5151
}
5252

5353
call_cl_api() {
54-
set +e
55-
if [ -z "${__api_data}" ]; then
56-
__code=$(curl -m 60 -s --show-error -o /tmp/result.txt -w "%{http_code}" -X "${__http_method}" -H "Accept: application/json" \
57-
"${CL_NODE}"/"${__api_path}")
58-
else
59-
__code=$(curl -m 60 -s --show-error -o /tmp/result.txt -w "%{http_code}" -X "${__http_method}" -H "Accept: application/json" -H "Content-Type: application/json" \
60-
--data "${__api_data}" "${CL_NODE}"/"${__api_path}")
61-
fi
62-
__return=$?
63-
if [ $__return -ne 0 ]; then
64-
echo "Error encountered while trying to call the consensus client REST API via curl."
65-
echo "Please make sure the ${CL_NODE} URL is reachable."
66-
echo "Error code $__return"
67-
exit $__return
68-
fi
69-
if [ -f /tmp/result.txt ]; then
70-
__result=$(cat /tmp/result.txt)
71-
else
72-
echo "Error encountered while trying to call the consensus client REST API via curl."
73-
echo "HTTP code: ${__code}"
74-
exit 1
75-
fi
54+
set +e
55+
if [ -z "${__api_data}" ]; then
56+
__code=$(curl -m 60 -s --show-error -o /tmp/result.txt -w "%{http_code}" -X "${__http_method}" -H "Accept: application/json" \
57+
"${CL_NODE}"/"${__api_path}")
58+
else
59+
__code=$(curl -m 60 -s --show-error -o /tmp/result.txt -w "%{http_code}" -X "${__http_method}" -H "Accept: application/json" -H "Content-Type: application/json" \
60+
--data "${__api_data}" "${CL_NODE}"/"${__api_path}")
61+
fi
62+
__return=$?
63+
if [ $__return -ne 0 ]; then
64+
echo "Error encountered while trying to call the consensus client REST API via curl."
65+
echo "Please make sure the ${CL_NODE} URL is reachable."
66+
echo "Error code $__return"
67+
exit $__return
68+
fi
69+
if [ -f /tmp/result.txt ]; then
70+
__result=$(cat /tmp/result.txt)
71+
else
72+
echo "Error encountered while trying to call the consensus client REST API via curl."
73+
echo "HTTP code: ${__code}"
74+
exit 1
75+
fi
7676
}
7777

7878
get-token() {
7979
set +e
80-
__token=$(< "${__token_file}")
81-
__return=$?
82-
if [ $__return -ne 0 ]; then
83-
echo "Error encountered while trying to get the keymanager API token."
84-
echo "Please make sure the ${__service} service is up and its logs show the key manager API, port ${__api_port}, enabled."
85-
exit $__return
86-
fi
80+
__token=$(tail -n 1 "${__token_file}")
81+
__return=$?
82+
if [ $__return -ne 0 ]; then
83+
echo "Error encountered while trying to get the keymanager API token."
84+
echo "Please make sure the ${__service} service is up and its logs show the key manager API, port ${__api_port}, enabled."
85+
exit $__return
86+
fi
87+
if [ -z "${__token}" ]; then
88+
echo "The keymnanager API token in ${__token_file_client} is empty."
89+
echo "The token path is relative to the ${__service} container."
90+
echo "This could happen if the file ends with an empty line, which is a client bug."
91+
echo "Please report this on Github. Aborting."
92+
exit 1
93+
fi
8794
set -e
8895
}
8996

@@ -882,13 +889,7 @@ and secrets directories into .eth/validator_keys instead."
882889
call_api
883890
case $__code in
884891
200) ;;
885-
400)
886-
if [ -z "${PRYSM:+x}" ]; then
887-
echo "The pubkey was formatted wrong. Error: $(echo "$__result" | jq -r '.message')"; exit 1
888-
else
889-
echo "Bad format. Error: $__result"; exit 1
890-
fi
891-
;;
892+
400) echo "The pubkey was formatted wrong. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
892893
401) echo "No authorization token found. This is a bug. Error: $(echo "$__result" | jq -r '.message')"; exit 70;;
893894
403) echo "The authorization token is invalid. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
894895
500) echo "Internal server error. Error: $(echo "$__result" | jq -r '.message')"; exit 1;;
@@ -1209,6 +1210,7 @@ if [ "$(id -u)" = '0' ]; then
12091210
exit 1
12101211
fi
12111212
fi
1213+
__token_file_client="$1"
12121214
__token_file=/tmp/api-token.txt
12131215
__api_container=$2
12141216
__api_port=${KEY_API_PORT:-7500}

0 commit comments

Comments
 (0)