Skip to content

Commit 290881b

Browse files
committed
Clean up relay credentials generation
1 parent da8f490 commit 290881b

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ source check-minimum-requirements.sh
2020
source turn-things-off.sh
2121
source create-docker-volumes.sh
2222
source ensure-files-from-examples.sh
23+
source ensure-relay-credentials.sh
2324
source generate-secret-key.sh
2425
source replace-tsdb.sh
2526
source update-docker-images.sh
@@ -31,6 +32,5 @@ source create-kafka-topics.sh
3132
source upgrade-postgres.sh
3233
source set-up-and-migrate-database.sh
3334
source migrate-file-storage.sh
34-
source relay-credentials.sh
3535
source geoip.sh
3636
source wrap-up.sh

install/relay-credentials-test.sh renamed to install/ensure-relay-credentials-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ test ! -f $cfg
99
test ! -f $creds
1010

1111
# Running the install script adds them.
12-
source relay-credentials.sh
12+
source ensure-relay-credentials.sh
1313
test -f $cfg
1414
test -f $creds
1515
test "$(jq -r 'keys[2]' $creds)" = "secret_key"
1616

1717
# If the files exist we don't touch it.
1818
echo GARBAGE > $cfg
1919
echo MOAR GARBAGE > $creds
20-
source relay-credentials.sh
20+
source ensure-relay-credentials.sh
2121
test "$(cat $cfg)" = "GARBAGE"
2222
test "$(cat $creds)" = "MOAR GARBAGE"
2323

install/ensure-relay-credentials.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
echo "${_group}Ensuring Relay credentials ..."
2+
3+
RELAY_CONFIG_YML="../relay/config.yml"
4+
RELAY_CREDENTIALS_JSON="../relay/credentials.json"
5+
6+
ensure_file_from_example $RELAY_CONFIG_YML
7+
8+
if [[ -f "$RELAY_CREDENTIALS_JSON" ]]; then
9+
echo "$RELAY_CREDENTIALS_JSON already exists, skipped creation."
10+
else
11+
12+
# There are a couple gotchas here:
13+
#
14+
# 1. We need to use a tmp file because if we redirect output directly to
15+
# credentials.json, then the shell will create an empty file that relay
16+
# will then try to read from (regardless of options such as --stdout or
17+
# --overwrite) and fail because it is empty.
18+
#
19+
# 2. We need to use -T to avoid additional garbage output cluttering
20+
# credentials.json under Docker Compose 1.x and 2.2.3+.
21+
22+
creds="$dcr --no-deps -T relay credentials"
23+
$creds generate --stdout > "$RELAY_CREDENTIALS_JSON".tmp
24+
mv "$RELAY_CREDENTIALS_JSON".tmp "$RELAY_CREDENTIALS_JSON"
25+
if ! grep -q Credentials <($creds show); then
26+
# Let's fail early if creds failed, to make debugging easier.
27+
echo "Failed to create relay credentials in $RELAY_CREDENTIALS_JSON."
28+
exit 1
29+
fi
30+
echo "Relay credentials written to $RELAY_CREDENTIALS_JSON."
31+
fi
32+
33+
echo "${_endgroup}"

install/relay-credentials.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)