Skip to content

Commit

Permalink
Update environment to support embedded variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Dec 29, 2023
1 parent c873538 commit 71a4a3c
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions lib/pakman/bootstrap/templates/environment.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@

set -e

function fetch_from_instellar() {
endpoint="$(curl -s --unix-socket /dev/lxd/sock x/1.0/config/user.INSTELLAR_INSTALLATION_ENDPOINT)"
token="$(curl -s --unix-socket /dev/lxd/sock x/1.0/config/user.INSTELLAR_BOT_TOKEN)"
code="$(curl -s -o /dev/null -w "%{http_code}" "${endpoint}" -H "Authorization: Bearer ${token}" -H 'Content-Type: application/json; charset=utf-8')"

if [[ "$code" == "200" ]]; then
echo "----- Fetching ${endpoint} -----"

variables="$(curl -s "${endpoint}" -H "Authorization: Bearer ${token}" -H 'Content-Type: application/json; charset=utf-8' | jq '.data.attributes.variables')"
else
echo "----- Fetching from backup -----"

variables="$(cat /root/.<%= name %>/variables.json | jq '.data.attributes.variables')"
fi
}

manager="$(curl -s --unix-socket /dev/lxd/sock x/1.0/config/user.managed_by)"
export HOSTNAME="$(echo $HOSTNAME)"

if [ "$manager" = "uplink" ]
then
endpoint="$(curl -s --unix-socket /dev/lxd/sock x/1.0/config/user.install_variables_endpoint)"
then
endpoint="$(curl -s --unix-socket /dev/lxd/sock x/1.0/config/user.install_variables_endpoint)"

echo "----- Fetching ${endpoint} -----"
echo "----- Fetching ${endpoint} -----"

variables="$(curl -s "${endpoint}" -H 'Content-Type: application/json; charset=utf-8' | jq '.data.attributes.variables')"
variables="$(curl -s "${endpoint}" -H 'Content-Type: application/json; charset=utf-8' | jq '.data.attributes.variables')"
else
endpoint="$(curl -s --unix-socket /dev/lxd/sock x/1.0/config/user.INSTELLAR_INSTALLATION_ENDPOINT)"
token="$(curl -s --unix-socket /dev/lxd/sock x/1.0/config/user.INSTELLAR_BOT_TOKEN)"

echo "----- Fetching ${endpoint} -----"

variables="$(curl -s "${endpoint}" -H "Authorization: Bearer ${token}" -H 'Content-Type: application/json; charset=utf-8' | jq '.data.attributes.variables')"
fetch_from_instellar
fi

while read -rd $'' line
do
export "$line"
done < <(jq -r <<<"$variables" \
'to_entries|map("\(.key)=\(.value)\u0000")[]')
'to_entries|map("\(.key)=\(.value)\u0000")[]')

0 comments on commit 71a4a3c

Please sign in to comment.