-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/content-type
- Loading branch information
Showing
4 changed files
with
132 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
AUTHZ_FILE=public/authz_server/authorize | ||
CUSTOM_CODE=authz_server/custom_code | ||
|
||
if [ ! -d ${CUSTOM_CODE} ] || [ ! -f ${AUTHZ_FILE} ]; then | ||
exit 0 | ||
fi | ||
|
||
tmp_schema=$(mktemp) | ||
tmp_zen=$(mktemp) | ||
tmp_keys=$(mktemp) | ||
tmp=$(mktemp) | ||
|
||
echo "{}" > ${tmp_schema} | ||
echo "{}" > ${tmp_zen} | ||
echo "{}" > ${tmp_keys} | ||
|
||
for f in ${CUSTOM_CODE}/*; do | ||
name=$(echo $f | rev | cut -d'/' -f1 | rev | cut -d'.' -f1) | ||
ext=$(echo $f | cut -d'.' -f2-) | ||
if [ -f $f ] && [ "$ext" = "schema.json" ]; then | ||
jq --arg name ${name} '.[$name] = input ' ${tmp_schema} $f > ${tmp} && mv ${tmp} ${tmp_schema} | ||
elif [ -f $f ] && [ "$ext" = "zen" ]; then | ||
echo "🎮 Loaded ${name} custom code" | ||
jq --arg name ${name} --arg contract "$(sed -z 's/\n/\\n/g' $f)" '.[$name] = $contract ' ${tmp_zen} > ${tmp} && mv ${tmp} ${tmp_zen} | ||
elif [ -f $f ] && [ "$ext" = "keys.json" ]; then | ||
jq --arg name ${name} '.[$name] = input ' ${tmp_keys} $f > ${tmp} && mv ${tmp} ${tmp_keys} | ||
fi | ||
done | ||
|
||
awk -v c="$(jq -r tostring ${tmp_zen})" '{gsub ("const contracts = .*", "const contracts = " c); print}' ${AUTHZ_FILE} > ${tmp} && mv ${tmp} ${AUTHZ_FILE} | ||
awk -v s="$(jq -r tostring ${tmp_schema})" '{gsub ("const schemas = .*", "const schemas = " s); print}' ${AUTHZ_FILE} > ${tmp} && mv ${tmp} ${AUTHZ_FILE} | ||
awk -v k="$(jq -r tostring ${tmp_keys})" '{gsub ("const keys = .*", "const keys = " k); print}' ${AUTHZ_FILE} > ${tmp} && mv ${tmp} ${AUTHZ_FILE} | ||
|
||
rm ${tmp_schema} ${tmp_zen} ${tmp_keys} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env bash | ||
|
||
UP_PORT=${1} | ||
MS_NAME=${2} | ||
|
||
if [ ! -x scripts/autorun_search.sh ]; then | ||
chmod +x scripts/autorun_search.sh | ||
fi | ||
|
||
if [ ! -x scripts/autorun_store.sh ]; then | ||
chmod +x scripts/autorun_store.sh | ||
fi | ||
|
||
function start_service() { | ||
service=$1 | ||
echo "🐣 Starting service: ${service}" | ||
wk_name="" | ||
case ${service} in | ||
"authz_server") | ||
wk_name="oauth-authorization-server" | ||
;; | ||
"credential_issuer") | ||
wk_name="openid-credential-issuer" | ||
;; | ||
"relying_party") | ||
wk_name="openid-relying-party" | ||
;; | ||
*) | ||
echo "Unknown value for ${service}. Nothing to do." >&2 | ||
exit 1 | ||
;; | ||
esac | ||
name=${MS_NAME} | ||
if [ -z "${name}" ]; then name=$service; fi | ||
( | ||
MS_NAME=$name ./ncr -p $port -z $service --public-directory public/$service --basepath '/'$service & | ||
APP_PID=$! | ||
echo $APP_PID > .${service}.pid | ||
( | ||
sleep 5 | ||
if [ ! -f $service/secrets.keys ]; then | ||
echo "📢 Announce phase failed" | ||
echo "🗝️ Secret keys not created in file: ${s}/secrets.keys" | ||
echo "⛔ Stopping the service" | ||
kill $APP_PID | ||
exit 1 | ||
fi | ||
kid=$(jq -r '.jwks.keys[0].kid' public/$service/.well-known/$wk_name) | ||
if [ "${kid:0:1}" = "{" ]; then | ||
echo "📢 Announce phase failed" | ||
echo "🪪 Kid not created in file: public/$service/.well-known/$wk_name" | ||
echo "⛔ Stopping the service" | ||
kill $APP_PID | ||
exit 1 | ||
fi | ||
) | ||
wait $APP_PID | ||
) | ||
} | ||
|
||
service="" | ||
for s in authz_server credential_issuer relying_party; do | ||
if [[ -d "$s" ]]; then | ||
service="$service $s" | ||
fi | ||
done | ||
if [ -z "${service}" ]; then | ||
echo "😢 No service found" | ||
exit 1 | ||
fi | ||
|
||
port=${UP_PORT} | ||
if [ "$(echo ${service} | wc -w)" = "1" ]; then | ||
start_service ${service} ${port} | ||
else | ||
for s in ${service}; do | ||
start_service ${s} ${port} & | ||
port=$((port+1)) | ||
done | ||
fi |