this derivation will be built: /nix/store/wxmn3m2xkg54z5psxd46gv1lwmn819cd-treefmt-check.drv building '/nix/store/wxmn3m2xkg54z5psxd46gv1lwmn819cd-treefmt-check.drv' treefmt-check> treefmt v2.6.0traversed 442 files treefmt-check> emitted 408 files for processing treefmt-check> formatted 408 files (10 changed) in 1.363s treefmt-check> M docs/gen-ssh-config.sh treefmt-check> M docs/generate-host-info.sh treefmt-check> M docs/generate-lldp-graph.sh treefmt-check> M docs/get-lldp-neighbors.sh treefmt-check> M modules/db-sync/scripts/db-freeze.sh treefmt-check> M modules/db-sync/scripts/db-sync-all.sh treefmt-check> M modules/db-sync/scripts/db-sync-status.sh treefmt-check> M modules/db-sync/scripts/db-sync-stop.sh treefmt-check> M modules/db-sync/scripts/db-thaw.sh treefmt-check> M terraform/authentik/import-existing.sh treefmt-check> diff --git a/docs/gen-ssh-config.sh b/docs/gen-ssh-config.sh treefmt-check> index 575c5a6..63a3489 100755 treefmt-check> --- a/docs/gen-ssh-config.sh treefmt-check> +++ b/docs/gen-ssh-config.sh treefmt-check> @@ -4,9 +4,9 @@ set -euo pipefail treefmt-check> user=${1:-} treefmt-check> treefmt-check> if [[ -z $user ]]; then treefmt-check> - echo "Missing username" treefmt-check> - echo "Usage: $(basename "$0") username" treefmt-check> - exit 1 treefmt-check> + echo "Missing username" treefmt-check> + echo "Usage: $(basename "$0") username" treefmt-check> + exit 1 treefmt-check> fi treefmt-check> treefmt-check> # GitHub directory pages change independently of this script; use the stable API. treefmt-check> @@ -28,20 +28,20 @@ Host eta treefmt-check> EOF treefmt-check> treefmt-check> curl -fsSL \ treefmt-check> - -H 'Accept: application/vnd.github+json' \ treefmt-check> - -H 'X-GitHub-Api-Version: 2022-11-28' \ treefmt-check> - 'https://api.github.com/repos/SBEE-Lab/infra/contents/hosts?ref=main' \ treefmt-check> - >"$tempfile" treefmt-check> + -H 'Accept: application/vnd.github+json' \ treefmt-check> + -H 'X-GitHub-Api-Version: 2022-11-28' \ treefmt-check> + 'https://api.github.com/repos/SBEE-Lab/infra/contents/hosts?ref=main' \ treefmt-check> + >"$tempfile" treefmt-check> machines=$(grep -oE '"name"[[:space:]]*:[[:space:]]*"[^"]+\.nix"' "$tempfile" | treefmt-check> - sed -E 's/.*"([^"]+)\.nix"/\1/' | treefmt-check> - sort -u) treefmt-check> + sed -E 's/.*"([^"]+)\.nix"/\1/' | treefmt-check> + sort -u) treefmt-check> treefmt-check> while read -r machine; do treefmt-check> - if [[ -z $machine || $machine == "eta" ]]; then treefmt-check> - continue treefmt-check> - fi treefmt-check> + if [[ -z $machine || $machine == "eta" ]]; then treefmt-check> + continue treefmt-check> + fi treefmt-check> treefmt-check> - cat < + cat < Host $machine treefmt-check> HostName $machine.sjanglab.org treefmt-check> User $user treefmt-check> diff --git a/docs/generate-host-info.sh b/docs/generate-host-info.sh treefmt-check> index 92a5380..87ddb19 100755 treefmt-check> --- a/docs/generate-host-info.sh treefmt-check> +++ b/docs/generate-host-info.sh treefmt-check> @@ -2,8 +2,8 @@ treefmt-check> set -euo pipefail treefmt-check> treefmt-check> if [[ -z ${1:-} ]]; then treefmt-check> - echo "Usage: $(basename "$0") host" >&2 treefmt-check> - exit 1 treefmt-check> + echo "Usage: $(basename "$0") host" >&2 treefmt-check> + exit 1 treefmt-check> fi treefmt-check> treefmt-check> target=$1 treefmt-check> diff --git a/docs/generate-lldp-graph.sh b/docs/generate-lldp-graph.sh treefmt-check> index 7fbaa06..0a099a6 100755 treefmt-check> --- a/docs/generate-lldp-graph.sh treefmt-check> +++ b/docs/generate-lldp-graph.sh treefmt-check> @@ -2,8 +2,8 @@ treefmt-check> set -euo pipefail treefmt-check> treefmt-check> if ((BASH_VERSINFO[0] < 4)); then treefmt-check> - echo "$(basename "$0") requires Bash 4 or newer" >&2 treefmt-check> - exit 1 treefmt-check> + echo "$(basename "$0") requires Bash 4 or newer" >&2 treefmt-check> + exit 1 treefmt-check> fi treefmt-check> treefmt-check> report="../graph.md" treefmt-check> @@ -11,60 +11,60 @@ url="https://github.com/SBEE-Lab/infra/blob/main/docs/hosts" treefmt-check> declare -A interfaces treefmt-check> treefmt-check> { treefmt-check> - echo '```mermaid' treefmt-check> - echo ' graph TD' treefmt-check> + echo '```mermaid' treefmt-check> + echo ' graph TD' treefmt-check> treefmt-check> - for host_file in *; do treefmt-check> - [[ -f $host_file ]] || continue treefmt-check> - while read -r neighbor; do treefmt-check> - [[ -z $neighbor ]] && continue treefmt-check> - host_interface=$(echo "$neighbor" | cut -d' ' -f1) treefmt-check> - link_speed=$(echo "$neighbor" | cut -d' ' -f2) treefmt-check> - neighbor_interface=$(echo "$neighbor" | cut -d' ' -f3 | tr -cd '[:alnum:]._-') treefmt-check> - neighbor_name=$(echo "$neighbor" | cut -d' ' -f4 | tr -cd '[:alnum:]._-') treefmt-check> + for host_file in *; do treefmt-check> + [[ -f $host_file ]] || continue treefmt-check> + while read -r neighbor; do treefmt-check> + [[ -z $neighbor ]] && continue treefmt-check> + host_interface=$(echo "$neighbor" | cut -d' ' -f1) treefmt-check> + link_speed=$(echo "$neighbor" | cut -d' ' -f2) treefmt-check> + neighbor_interface=$(echo "$neighbor" | cut -d' ' -f3 | tr -cd '[:alnum:]._-') treefmt-check> + neighbor_name=$(echo "$neighbor" | cut -d' ' -f4 | tr -cd '[:alnum:]._-') treefmt-check> treefmt-check> - interfaces[$host_file]+=" $host_interface" treefmt-check> - interfaces[$neighbor_name]+=" $neighbor_interface" treefmt-check> + interfaces[$host_file]+=" $host_interface" treefmt-check> + interfaces[$neighbor_name]+=" $neighbor_interface" treefmt-check> treefmt-check> - echo " ${host_file}.${host_interface}[\"$host_interface\"]-- $link_speed ---${neighbor_name}.${neighbor_interface}[\"$neighbor_interface\"]" treefmt-check> - done <"$host_file" treefmt-check> - done treefmt-check> + echo " ${host_file}.${host_interface}[\"$host_interface\"]-- $link_speed ---${neighbor_name}.${neighbor_interface}[\"$neighbor_interface\"]" treefmt-check> + done <"$host_file" treefmt-check> + done treefmt-check> treefmt-check> - for host in "${!interfaces[@]}"; do treefmt-check> - interfaces[$host]=$(xargs -n 1 <<<"${interfaces[$host]}" | sort -u | xargs) treefmt-check> - echo " subgraph $host" treefmt-check> - for interface in ${interfaces[$host]}; do treefmt-check> - echo " ${host}.${interface}[\"$interface\"]" treefmt-check> - done treefmt-check> - echo " end" treefmt-check> - done treefmt-check> + for host in "${!interfaces[@]}"; do treefmt-check> + interfaces[$host]=$(xargs -n 1 <<<"${interfaces[$host]}" | sort -u | xargs) treefmt-check> + echo " subgraph $host" treefmt-check> + for interface in ${interfaces[$host]}; do treefmt-check> + echo " ${host}.${interface}[\"$interface\"]" treefmt-check> + done treefmt-check> + echo " end" treefmt-check> + done treefmt-check> treefmt-check> - for host in "${!interfaces[@]}"; do treefmt-check> - [[ -f "../$host.md" ]] || continue treefmt-check> - for interface in ${interfaces[$host]}; do treefmt-check> - echo " click ${host}.${interface} \"$url/$host.md\" \"$host\"" treefmt-check> - done treefmt-check> - done treefmt-check> + for host in "${!interfaces[@]}"; do treefmt-check> + [[ -f "../$host.md" ]] || continue treefmt-check> + for interface in ${interfaces[$host]}; do treefmt-check> + echo " click ${host}.${interface} \"$url/$host.md\" \"$host\"" treefmt-check> + done treefmt-check> + done treefmt-check> treefmt-check> - echo '```' treefmt-check> + echo '```' treefmt-check> } >"$report" treefmt-check> treefmt-check> # Remove inverse duplicate links. treefmt-check> while true; do treefmt-check> - duplicate="" treefmt-check> - while read -r link; do treefmt-check> - interface_1=$(awk '{print $1}' <<<"$link" | rev | cut -c 3- | rev) treefmt-check> - link_speed=$(awk '{print $2}' <<<"$link") treefmt-check> - interface_2=$(awk '{print $3}' <<<"$link" | cut -c 4-) treefmt-check> - candidate="$interface_2-- $link_speed ---$interface_1" treefmt-check> - if grep -q -F "$candidate" "$report"; then treefmt-check> - duplicate=$candidate treefmt-check> - break treefmt-check> - fi treefmt-check> - done < <(grep -E -- '-- [[:digit:]]+[GM] ---' "$report") treefmt-check> + duplicate="" treefmt-check> + while read -r link; do treefmt-check> + interface_1=$(awk '{print $1}' <<<"$link" | rev | cut -c 3- | rev) treefmt-check> + link_speed=$(awk '{print $2}' <<<"$link") treefmt-check> + interface_2=$(awk '{print $3}' <<<"$link" | cut -c 4-) treefmt-check> + candidate="$interface_2-- $link_speed ---$interface_1" treefmt-check> + if grep -q -F "$candidate" "$report"; then treefmt-check> + duplicate=$candidate treefmt-check> + break treefmt-check> + fi treefmt-check> + done < <(grep -E -- '-- [[:digit:]]+[GM] ---' "$report") treefmt-check> treefmt-check> - [[ -n $duplicate ]] || break treefmt-check> - tempfile=$(mktemp -t sbee-lldp-graph.XXXXXX) treefmt-check> - awk -v pattern="$duplicate" 'index($0, pattern) == 0' "$report" >"$tempfile" treefmt-check> - mv "$tempfile" "$report" treefmt-check> + [[ -n $duplicate ]] || break treefmt-check> + tempfile=$(mktemp -t sbee-lldp-graph.XXXXXX) treefmt-check> + awk -v pattern="$duplicate" 'index($0, pattern) == 0' "$report" >"$tempfile" treefmt-check> + mv "$tempfile" "$report" treefmt-check> done treefmt-check> diff --git a/docs/get-lldp-neighbors.sh b/docs/get-lldp-neighbors.sh treefmt-check> index 1396412..dd84cfb 100755 treefmt-check> --- a/docs/get-lldp-neighbors.sh treefmt-check> +++ b/docs/get-lldp-neighbors.sh treefmt-check> @@ -2,8 +2,8 @@ treefmt-check> set -euo pipefail treefmt-check> treefmt-check> if [[ -z ${1:-} ]]; then treefmt-check> - echo "Usage: $(basename "$0") host" >&2 treefmt-check> - exit 1 treefmt-check> + echo "Usage: $(basename "$0") host" >&2 treefmt-check> + exit 1 treefmt-check> fi treefmt-check> treefmt-check> target=$1 treefmt-check> @@ -12,17 +12,17 @@ report="$hostname" treefmt-check> lldp=$(ssh "$target" -- networkctl lldp --json=short) treefmt-check> treefmt-check> while IFS=$' ' read -r interface neighbor_interface neighbor_name; do treefmt-check> - [[ -z $interface ]] && continue treefmt-check> - link_speed=$(ssh "$target" -- cat "/sys/class/net/$interface/speed" + [[ -z $interface ]] && continue treefmt-check> + link_speed=$(ssh "$target" -- cat "/sys/class/net/$interface/speed" treefmt-check> - if ((link_speed >= 1000)); then treefmt-check> - speed="$((link_speed / 1000))G" treefmt-check> - else treefmt-check> - speed="${link_speed}M" treefmt-check> - fi treefmt-check> - echo "$interface $speed $neighbor_interface $neighbor_name" treefmt-check> + if ((link_speed >= 1000)); then treefmt-check> + speed="$((link_speed / 1000))G" treefmt-check> + else treefmt-check> + speed="${link_speed}M" treefmt-check> + fi treefmt-check> + echo "$interface $speed $neighbor_interface $neighbor_name" treefmt-check> done < <( treefmt-check> - python3 -c ' treefmt-check> + python3 -c ' treefmt-check> import json treefmt-check> import sys treefmt-check> treefmt-check> diff --git a/modules/db-sync/scripts/db-freeze.sh b/modules/db-sync/scripts/db-freeze.sh treefmt-check> index 6c31d2c..b709211 100644 treefmt-check> --- a/modules/db-sync/scripts/db-freeze.sh treefmt-check> +++ b/modules/db-sync/scripts/db-freeze.sh treefmt-check> @@ -1,24 +1,24 @@ treefmt-check> #!/usr/bin/env bash treefmt-check> set -euo pipefail treefmt-check> if [[ $# -ne 2 ]]; then treefmt-check> - echo "Usage: db-freeze " >&2 treefmt-check> - exit 1 treefmt-check> + echo "Usage: db-freeze " >&2 treefmt-check> + exit 1 treefmt-check> fi treefmt-check> db="$1" treefmt-check> tag="$2" treefmt-check> src="@dbRoot@/$db" treefmt-check> dst="@dbRoot@/$db.frozen.$tag" treefmt-check> [[ -d $src ]] || { treefmt-check> - echo "Not found: $db" >&2 treefmt-check> - exit 1 treefmt-check> + echo "Not found: $db" >&2 treefmt-check> + exit 1 treefmt-check> } treefmt-check> [[ ! -e $dst ]] || { treefmt-check> - echo "Already exists: $dst" >&2 treefmt-check> - exit 1 treefmt-check> + echo "Already exists: $dst" >&2 treefmt-check> + exit 1 treefmt-check> } treefmt-check> if systemctl is-active --quiet "db-sync-$db.service" 2>/dev/null; then treefmt-check> - echo "Sync in progress for $db, abort" >&2 treefmt-check> - exit 1 treefmt-check> + echo "Sync in progress for $db, abort" >&2 treefmt-check> + exit 1 treefmt-check> fi treefmt-check> cp --reflink=auto -a "$src" "$dst" treefmt-check> echo "Frozen: $dst" treefmt-check> diff --git a/modules/db-sync/scripts/db-sync-all.sh b/modules/db-sync/scripts/db-sync-all.sh treefmt-check> index 442bc74..9d558f0 100644 treefmt-check> --- a/modules/db-sync/scripts/db-sync-all.sh treefmt-check> +++ b/modules/db-sync/scripts/db-sync-all.sh treefmt-check> @@ -1,8 +1,8 @@ treefmt-check> #!/usr/bin/env bash treefmt-check> set -euo pipefail treefmt-check> for timer in $(systemctl list-units 'db-sync-*.timer' --plain --no-legend | awk '{print $1}'); do treefmt-check> - svc="${timer%.timer}.service" treefmt-check> - echo "Starting $svc ..." treefmt-check> - systemctl start --no-block "$svc" treefmt-check> + svc="${timer%.timer}.service" treefmt-check> + echo "Starting $svc ..." treefmt-check> + systemctl start --no-block "$svc" treefmt-check> done treefmt-check> echo "All sync services triggered (running in background)" treefmt-check> diff --git a/modules/db-sync/scripts/db-sync-status.sh b/modules/db-sync/scripts/db-sync-status.sh treefmt-check> index d901078..13ece0c 100644 treefmt-check> --- a/modules/db-sync/scripts/db-sync-status.sh treefmt-check> +++ b/modules/db-sync/scripts/db-sync-status.sh treefmt-check> @@ -5,14 +5,14 @@ echo "" treefmt-check> printf "%-40s %-10s %-10s %s\n" "SERVICE" "STATE" "RESULT" "LAST RUN" treefmt-check> printf "%-40s %-10s %-10s %s\n" "-------" "-----" "------" "--------" treefmt-check> for svc in $(systemctl list-units 'db-sync-*.service' --plain --no-legend --all | awk '{print $1}' | grep -v notify); do treefmt-check> - result=$(systemctl show "$svc" -p Result --value) treefmt-check> - active=$(systemctl show "$svc" -p ActiveState --value) treefmt-check> - started=$(systemctl show "$svc" -p ExecMainStartTimestamp --value) treefmt-check> - if [[ -z $started ]]; then treefmt-check> - started="never" treefmt-check> - result="-" treefmt-check> - fi treefmt-check> - printf "%-40s %-10s %-10s %s\n" "$svc" "$active" "$result" "$started" treefmt-check> + result=$(systemctl show "$svc" -p Result --value) treefmt-check> + active=$(systemctl show "$svc" -p ActiveState --value) treefmt-check> + started=$(systemctl show "$svc" -p ExecMainStartTimestamp --value) treefmt-check> + if [[ -z $started ]]; then treefmt-check> + started="never" treefmt-check> + result="-" treefmt-check> + fi treefmt-check> + printf "%-40s %-10s %-10s %s\n" "$svc" "$active" "$result" "$started" treefmt-check> done treefmt-check> echo "" treefmt-check> echo "Disk usage:" treefmt-check> diff --git a/modules/db-sync/scripts/db-sync-stop.sh b/modules/db-sync/scripts/db-sync-stop.sh treefmt-check> index 5fe0b69..c2035a8 100644 treefmt-check> --- a/modules/db-sync/scripts/db-sync-stop.sh treefmt-check> +++ b/modules/db-sync/scripts/db-sync-stop.sh treefmt-check> @@ -1,17 +1,17 @@ treefmt-check> #!/usr/bin/env bash treefmt-check> set -euo pipefail treefmt-check> if [[ $# -eq 0 ]]; then treefmt-check> - # Stop all running sync services treefmt-check> - for svc in $(systemctl list-units 'db-sync-*.service' --plain --no-legend --state=activating,running | awk '{print $1}'); do treefmt-check> - echo "Stopping $svc ..." treefmt-check> - systemctl stop "$svc" treefmt-check> - done treefmt-check> - echo "All sync services stopped" treefmt-check> + # Stop all running sync services treefmt-check> + for svc in $(systemctl list-units 'db-sync-*.service' --plain --no-legend --state=activating,running | awk '{print $1}'); do treefmt-check> + echo "Stopping $svc ..." treefmt-check> + systemctl stop "$svc" treefmt-check> + done treefmt-check> + echo "All sync services stopped" treefmt-check> else treefmt-check> - # Stop specific database(s) treefmt-check> - for db in "$@"; do treefmt-check> - svc="db-sync-${db}.service" treefmt-check> - echo "Stopping $svc ..." treefmt-check> - systemctl stop "$svc" treefmt-check> - done treefmt-check> + # Stop specific database(s) treefmt-check> + for db in "$@"; do treefmt-check> + svc="db-sync-${db}.service" treefmt-check> + echo "Stopping $svc ..." treefmt-check> + systemctl stop "$svc" treefmt-check> + done treefmt-check> fi treefmt-check> diff --git a/modules/db-sync/scripts/db-thaw.sh b/modules/db-sync/scripts/db-thaw.sh treefmt-check> index bf0ab2f..f7a388b 100644 treefmt-check> --- a/modules/db-sync/scripts/db-thaw.sh treefmt-check> +++ b/modules/db-sync/scripts/db-thaw.sh treefmt-check> @@ -1,15 +1,15 @@ treefmt-check> #!/usr/bin/env bash treefmt-check> set -euo pipefail treefmt-check> if [[ $# -ne 2 ]]; then treefmt-check> - echo "Usage: db-thaw " >&2 treefmt-check> - exit 1 treefmt-check> + echo "Usage: db-thaw " >&2 treefmt-check> + exit 1 treefmt-check> fi treefmt-check> db="$1" treefmt-check> tag="$2" treefmt-check> target="@dbRoot@/$db.frozen.$tag" treefmt-check> [[ -d $target ]] || { treefmt-check> - echo "Not found: $target" >&2 treefmt-check> - exit 1 treefmt-check> + echo "Not found: $target" >&2 treefmt-check> + exit 1 treefmt-check> } treefmt-check> rm -rf "$target" treefmt-check> echo "Thawed: $db.frozen.$tag" treefmt-check> diff --git a/terraform/authentik/import-existing.sh b/terraform/authentik/import-existing.sh treefmt-check> index 0b6c4d5..fa14c4d 100755 treefmt-check> --- a/terraform/authentik/import-existing.sh treefmt-check> +++ b/terraform/authentik/import-existing.sh treefmt-check> @@ -6,83 +6,83 @@ AK_TOKEN=${AK_TOKEN:-$(sops -d --extract '["AUTHENTIK_TOKEN"]' secrets.yaml)} treefmt-check> TG=${TG:-terragrunt} treefmt-check> treefmt-check> api() { treefmt-check> - curl -sSf -H "Authorization: Bearer ${AK_TOKEN}" "$AK/api/v3/$1" treefmt-check> + curl -sSf -H "Authorization: Bearer ${AK_TOKEN}" "$AK/api/v3/$1" treefmt-check> } treefmt-check> treefmt-check> state_has() { treefmt-check> - $TG state show "$1" >/dev/null 2>&1 treefmt-check> + $TG state show "$1" >/dev/null 2>&1 treefmt-check> } treefmt-check> treefmt-check> import_if_missing() { treefmt-check> - local address=$1 treefmt-check> - local id=$2 treefmt-check> + local address=$1 treefmt-check> + local id=$2 treefmt-check> treefmt-check> - if [ -z "$id" ] || [ "$id" = "null" ]; then treefmt-check> - echo "skip $address: no remote object" treefmt-check> - return 0 treefmt-check> - fi treefmt-check> + if [ -z "$id" ] || [ "$id" = "null" ]; then treefmt-check> + echo "skip $address: no remote object" treefmt-check> + return 0 treefmt-check> + fi treefmt-check> treefmt-check> - if state_has "$address"; then treefmt-check> - echo "ok $address already imported" treefmt-check> - return 0 treefmt-check> - fi treefmt-check> + if state_has "$address"; then treefmt-check> + echo "ok $address already imported" treefmt-check> + return 0 treefmt-check> + fi treefmt-check> treefmt-check> - echo "import $address <- $id" treefmt-check> - $TG import "$address" "$id" treefmt-check> + echo "import $address <- $id" treefmt-check> + $TG import "$address" "$id" treefmt-check> } treefmt-check> treefmt-check> json_quote() { treefmt-check> - jq -Rn --arg v "$1" '$v' treefmt-check> + jq -Rn --arg v "$1" '$v' treefmt-check> } treefmt-check> treefmt-check> group_id_by_name() { treefmt-check> - local name=$1 treefmt-check> - api "core/groups/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" | treefmt-check> - jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' | treefmt-check> - head -n1 treefmt-check> + local name=$1 treefmt-check> + api "core/groups/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" | treefmt-check> + jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' | treefmt-check> + head -n1 treefmt-check> } treefmt-check> treefmt-check> user_id_by_username() { treefmt-check> - local username=$1 treefmt-check> - api "core/users/?search=$(jq -rn --arg v "$username" '$v|@uri')&page_size=100" | treefmt-check> - jq -r --arg username "$username" '.results[] | select(.username == $username) | .pk' | treefmt-check> - head -n1 treefmt-check> + local username=$1 treefmt-check> + api "core/users/?search=$(jq -rn --arg v "$username" '$v|@uri')&page_size=100" | treefmt-check> + jq -r --arg username "$username" '.results[] | select(.username == $username) | .pk' | treefmt-check> + head -n1 treefmt-check> } treefmt-check> treefmt-check> proxy_id_by_external_host() { treefmt-check> - local external_host=$1 treefmt-check> - api "providers/proxy/?page_size=100" | treefmt-check> - jq -r --arg external_host "$external_host" '.results[] | select(.external_host == $external_host) | .pk' | treefmt-check> - head -n1 treefmt-check> + local external_host=$1 treefmt-check> + api "providers/proxy/?page_size=100" | treefmt-check> + jq -r --arg external_host "$external_host" '.results[] | select(.external_host == $external_host) | .pk' | treefmt-check> + head -n1 treefmt-check> } treefmt-check> treefmt-check> app_uuid_by_slug() { treefmt-check> - local slug=$1 treefmt-check> - curl -sS -H "Authorization: Bearer ${AK_TOKEN}" "$AK/api/v3/core/applications/${slug}/" 2>/dev/null | treefmt-check> - jq -r '.pk // empty' 2>/dev/null || true treefmt-check> + local slug=$1 treefmt-check> + curl -sS -H "Authorization: Bearer ${AK_TOKEN}" "$AK/api/v3/core/applications/${slug}/" 2>/dev/null | treefmt-check> + jq -r '.pk // empty' 2>/dev/null || true treefmt-check> } treefmt-check> treefmt-check> oauth2_id_by_name() { treefmt-check> - local name=$1 treefmt-check> - api "providers/oauth2/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" | treefmt-check> - jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' | treefmt-check> - head -n1 treefmt-check> + local name=$1 treefmt-check> + api "providers/oauth2/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" | treefmt-check> + jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' | treefmt-check> + head -n1 treefmt-check> } treefmt-check> treefmt-check> scope_mapping_id_by_name() { treefmt-check> - local name=$1 treefmt-check> - api "propertymappings/provider/scope/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" | treefmt-check> - jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' | treefmt-check> - head -n1 treefmt-check> + local name=$1 treefmt-check> + api "propertymappings/provider/scope/?search=$(jq -rn --arg v "$name" '$v|@uri')&page_size=100" | treefmt-check> + jq -r --arg name "$name" '.results[] | select(.name == $name) | .pk' | treefmt-check> + head -n1 treefmt-check> } treefmt-check> treefmt-check> outpost_id=$(api 'outposts/instances/?search=authentik%20Embedded%20Outpost&page_size=100' | treefmt-check> - jq -r '.results[] | select(.name == "authentik Embedded Outpost") | .pk' | treefmt-check> - head -n1) treefmt-check> + jq -r '.results[] | select(.name == "authentik Embedded Outpost") | .pk' | treefmt-check> + head -n1) treefmt-check> treefmt-check> # Keep keys in sync with local.groups in groups.tf. treefmt-check> while IFS='|' read -r key name; do treefmt-check> - import_if_missing "authentik_group.group[$(json_quote "$key")]" "$(group_id_by_name "$name")" treefmt-check> + import_if_missing "authentik_group.group[$(json_quote "$key")]" "$(group_id_by_name "$name")" treefmt-check> done <<'EOF' treefmt-check> authentik_admins|authentik Admins treefmt-check> sjanglab_admins|sjanglab-admins treefmt-check> @@ -93,45 +93,45 @@ sjanglab_pending|sjanglab-pending treefmt-check> EOF treefmt-check> treefmt-check> for username in akadmin terraform; do treefmt-check> - import_if_missing "authentik_user.service[$(json_quote "$username")]" "$(user_id_by_username "$username")" treefmt-check> + import_if_missing "authentik_user.service[$(json_quote "$username")]" "$(user_id_by_username "$username")" treefmt-check> done treefmt-check> treefmt-check> while IFS='|' read -r app external_host; do treefmt-check> - provider_id=$(proxy_id_by_external_host "$external_host") treefmt-check> - app_id=$(app_uuid_by_slug "$app") treefmt-check> - treefmt-check> - import_if_missing "authentik_provider_proxy.app[$(json_quote "$app")]" "$provider_id" treefmt-check> - if [ -n "$app_id" ]; then treefmt-check> - import_if_missing "authentik_application.app[$(json_quote "$app")]" "$app" treefmt-check> - else treefmt-check> - echo "skip application for $app: no remote object" treefmt-check> - fi treefmt-check> - treefmt-check> - if [ -n "$outpost_id" ] && [ -n "$provider_id" ]; then treefmt-check> - import_if_missing "authentik_outpost_provider_attachment.embedded[$(json_quote "$app")]" "${outpost_id}:${provider_id}" treefmt-check> - else treefmt-check> - echo "skip outpost attachment for $app: no outpost/provider" treefmt-check> - fi treefmt-check> + provider_id=$(proxy_id_by_external_host "$external_host") treefmt-check> + app_id=$(app_uuid_by_slug "$app") treefmt-check> + treefmt-check> + import_if_missing "authentik_provider_proxy.app[$(json_quote "$app")]" "$provider_id" treefmt-check> + if [ -n "$app_id" ]; then treefmt-check> + import_if_missing "authentik_application.app[$(json_quote "$app")]" "$app" treefmt-check> + else treefmt-check> + echo "skip application for $app: no remote object" treefmt-check> + fi treefmt-check> + treefmt-check> + if [ -n "$outpost_id" ] && [ -n "$provider_id" ]; then treefmt-check> + import_if_missing "authentik_outpost_provider_attachment.embedded[$(json_quote "$app")]" "${outpost_id}:${provider_id}" treefmt-check> + else treefmt-check> + echo "skip outpost attachment for $app: no outpost/provider" treefmt-check> + fi treefmt-check> done <<'EOF' treefmt-check> n8n|https://n8n.sjanglab.org treefmt-check> logging|https://logging.sjanglab.org treefmt-check> EOF treefmt-check> treefmt-check> while IFS='|' read -r key name; do treefmt-check> - import_if_missing "authentik_property_mapping_provider_scope.oidc_group[$(json_quote "$key")]" "$(scope_mapping_id_by_name "$name")" treefmt-check> + import_if_missing "authentik_property_mapping_provider_scope.oidc_group[$(json_quote "$key")]" "$(scope_mapping_id_by_name "$name")" treefmt-check> done <<'EOF' treefmt-check> headscale|headscale-groups treefmt-check> nextcloud|nextcloud-groups treefmt-check> EOF treefmt-check> treefmt-check> while IFS='|' read -r key name slug; do treefmt-check> - import_if_missing "authentik_provider_oauth2.oidc[$(json_quote "$key")]" "$(oauth2_id_by_name "$name")" treefmt-check> - app_id=$(app_uuid_by_slug "$slug") treefmt-check> - if [ -n "$app_id" ]; then treefmt-check> - import_if_missing "authentik_application.oidc[$(json_quote "$key")]" "$slug" treefmt-check> - else treefmt-check> - echo "skip application for $slug: no remote object" treefmt-check> - fi treefmt-check> + import_if_missing "authentik_provider_oauth2.oidc[$(json_quote "$key")]" "$(oauth2_id_by_name "$name")" treefmt-check> + app_id=$(app_uuid_by_slug "$slug") treefmt-check> + if [ -n "$app_id" ]; then treefmt-check> + import_if_missing "authentik_application.oidc[$(json_quote "$key")]" "$slug" treefmt-check> + else treefmt-check> + echo "skip application for $slug: no remote object" treefmt-check> + fi treefmt-check> done <<'EOF' treefmt-check> headscale|Headscale|headscale treefmt-check> nextcloud|Nextcloud|nextcloud error: Cannot build '/nix/store/wxmn3m2xkg54z5psxd46gv1lwmn819cd-treefmt-check.drv'. Reason: builder failed with exit code 1. Output paths: /nix/store/nd7anvk4qa4rm26irpv6lzym0k8kclya-treefmt-check Last 25 log lines: > - import_if_missing "authentik_property_mapping_provider_scope.oidc_group[$(json_quote "$key")]" "$(scope_mapping_id_by_name "$name")" > + import_if_missing "authentik_property_mapping_provider_scope.oidc_group[$(json_quote "$key")]" "$(scope_mapping_id_by_name "$name")" > done <<'EOF' > headscale|headscale-groups > nextcloud|nextcloud-groups > EOF > > while IFS='|' read -r key name slug; do > - import_if_missing "authentik_provider_oauth2.oidc[$(json_quote "$key")]" "$(oauth2_id_by_name "$name")" > - app_id=$(app_uuid_by_slug "$slug") > - if [ -n "$app_id" ]; then > - import_if_missing "authentik_application.oidc[$(json_quote "$key")]" "$slug" > - else > - echo "skip application for $slug: no remote object" > - fi > + import_if_missing "authentik_provider_oauth2.oidc[$(json_quote "$key")]" "$(oauth2_id_by_name "$name")" > + app_id=$(app_uuid_by_slug "$slug") > + if [ -n "$app_id" ]; then > + import_if_missing "authentik_application.oidc[$(json_quote "$key")]" "$slug" > + else > + echo "skip application for $slug: no remote object" > + fi > done <<'EOF' > headscale|Headscale|headscale > nextcloud|Nextcloud|nextcloud For full logs, run: nix log /nix/store/wxmn3m2xkg54z5psxd46gv1lwmn819cd-treefmt-check.drv