Skip to content

Commit 7e2ff73

Browse files
committed
feat: add ability to specify oauth2 config files
'MOODLE_OAUTH2_CONFIG_..' variables may now end in '_FILE' (or just 'MOODLE_OAUTH2_CONFIG_FILE' for a single configuration) to denote them as paths to a json file containing the configuration.
1 parent 43abadb commit 7e2ff73

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

entrypoint.d/40-oauth2.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
#!/bin/bash
22
set -e
33

4+
VAR_PREFIX="MOODLE_OAUTH2_CONFIG_"
5+
46
if [ "$IS_WORKER" = "false" ]; then
57
# Automatic OAuth2 Issuer Configuration
68
# Looks for MOODLE_OAUTH2_CONFIG_JSON or MOODLE_OAUTH2_CONFIG_<NAME>
9+
# Variables ending in _FILE are assumed to be paths to json configurations
710
# Use 'env' to get all variables and filter
8-
for var in $(env | grep ^MOODLE_OAUTH2_CONFIG_ | cut -d= -f1); do
11+
for var in $(env | grep "^{$VAR_PREFIX}" | cut -d= -f1); do
912
CONFIG_VAL="${!var}"
1013
if [ -n "$CONFIG_VAL" ]; then
11-
echo "Configuring OAuth2 Issuer from $var (via stdin)..."
12-
php "${MOODLE_DOCKER_ROOT}/scripts/manage_oauth2_issuer.php" <<< "$CONFIG_VAL"
14+
issuer="${var:${#VAR_PREFIX}}"
15+
if [ "${issuer:(-5)}" = "_FILE" ] || [ "$issuer" = "FILE" ]; then
16+
[ "$issuer" = "FILE" ] && issuer="" || issuer="${issuer:0:(-5)}"
17+
18+
echo "Configuring OAuth2 Issuer${issuer:- }$issuer from ${CONFIG_VAL}..."
19+
php "${MOODLE_DOCKER_ROOT}/scripts/manage_oauth2_issuer.php" "$CONFIG_VAL"
20+
else
21+
[ "$issuer" = "JSON" ] && issuer=""
22+
[ "${issuer:(-5)}" = "_JSON" ] && issuer="${issuer:0:(-5)}"
23+
24+
echo "Configuring OAuth2 Issuer${issuer:- }$issuer from $var (via stdin)..."
25+
php "${MOODLE_DOCKER_ROOT}/scripts/manage_oauth2_issuer.php" <<< "$CONFIG_VAL"
26+
fi
1327
fi
1428
done
1529

0 commit comments

Comments
 (0)