#!/usr/bin/bash

# Generate a JSON encoded list of the NIF account instances with mtls certificates, based on filesystem
echo '{"data":['
for d in $(find /home -maxdepth 1 -type d -iname "nif_*" -printf '%f\n'); do
    if [[ -d /home/$d/certs ]]; then
        for b in $(find /home/$d/accounts/ -maxdepth 1 -not -name "accounts" -printf '%f\n'); do
             echo  '  {"{#NIFACCOUNTNAME}":"'$d'","{#NIFACCOUNTBRANCH}":"'$b'", "{#NIFPEMPATH}":"'/home/$d/certs/${b}_client_cert.crt'"}'
        done
    fi
done | sed '$!s/$/,/' 
echo "]}"
