Skip to content

Commit b253b33

Browse files
committed
Nodes connections address update from route53 script
1 parent 4e6f0f8 commit b253b33

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

scripts/nodes-connections.bash

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Update nodes connection address environment variables
4+
# from AWS Route53 internal hosted zone
5+
6+
# Colors
7+
C_RESET='\033[0m'
8+
C_RED='\033[1;31m'
9+
C_GREEN='\033[1;32m'
10+
C_YELLOW='\033[1;33m'
11+
12+
# Logs
13+
PREFIX_INFO="${C_GREEN}[INFO]${C_RESET} [$(date +%d-%m\ %T)]"
14+
PREFIX_WARN="${C_YELLOW}[WARN]${C_RESET} [$(date +%d-%m\ %T)]"
15+
PREFIX_CRIT="${C_RED}[CRIT]${C_RESET} [$(date +%d-%m\ %T)]"
16+
17+
# Print help message
18+
function usage {
19+
echo "Usage: $0 [-h] -p PRODUCT -f FILEPATH"
20+
echo
21+
echo "CLI to update nodes connection address environment
22+
variables from AWS Route53 internal hosted zone"
23+
echo
24+
echo "Optional arguments:"
25+
echo " -h Show this help message and exit"
26+
echo " -f File path where environment variables update at"
27+
}
28+
29+
file_flag=""
30+
verbose_flag="false"
31+
32+
while getopts 'f:v' flag; do
33+
case "${flag}" in
34+
f) file_flag="${OPTARG}" ;;
35+
h) usage
36+
exit 1 ;;
37+
v) verbose_flag="true" ;;
38+
*) usage
39+
exit 1 ;;
40+
esac
41+
done
42+
43+
# Log messages
44+
function verbose {
45+
if [ "${verbose_flag}" == "true" ]; then
46+
echo -e "$1"
47+
fi
48+
}
49+
50+
# File flag should be specified
51+
if [ -z "${file_flag}" ]; then
52+
verbose "${PREFIX_CRIT} Please specify file path"
53+
usage
54+
exit 1
55+
fi
56+
57+
if [ ! -f "${file_flag}" ]; then
58+
verbose "${PREFIX_CRIT} Provided file does not exist"
59+
usage
60+
exit 1
61+
fi
62+
63+
verbose "${PREFIX_INFO} Source environment variables"
64+
. ${file_flag}
65+
66+
verbose "${PREFIX_INFO} Retrieving Ethereum node address and port"
67+
RETRIEVED_NODE_ETHEREUM_IPC_ADDR=$(aws route53 list-resource-record-sets --hosted-zone-id "${MOONSTREAM_INTERNAL_HOSTED_ZONE_ID}" --query "ResourceRecordSets[?Name == '${MOONSTREAM_ETHEREUM_WEB3_PROVIDER_URI}.'].ResourceRecords[].Value" | jq -r .[0])
68+
69+
if [ "$RETRIEVED_NODE_ETHEREUM_IPC_ADDR" == "null" ]; then
70+
verbose "${PREFIX_CRIT} Ethereum node address is null"
71+
exit 1
72+
fi
73+
74+
verbose "${PREFIX_INFO} Updating MOONSTREAM_NODE_ETHEREUM_IPC_ADDR"
75+
# TODO(kompotkot): Modify regexp to work with export prefix
76+
sed -i "s|^MOONSTREAM_NODE_ETHEREUM_IPC_ADDR=.*|MOONSTREAM_NODE_ETHEREUM_IPC_ADDR=\"$RETRIEVED_NODE_ETHEREUM_IPC_ADDR\"|" ${file_flag}
77+

0 commit comments

Comments
 (0)