wx-ssh-config(){ wx-restricted case $1 in edit) wx-ssh-config-sync wx-ssh-config-edit wx-ssh-config-save ;; save) wx-ssh-config-save ;; sync) wx-ssh-config-sync ;; clean) wx-ssh-config-clean ;; *) wx-ssh-config-sync wx-stop ;; esac } wx-ssh-config-edit(){ wx-header "SSH / Config / Edit" wx-restricted nano ~/.ssh/config } wx-ssh-config-save(){ wx-header "SSH / Config / Save" wx-restricted curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"data\": \"$(cat ~/.ssh/config | base64 -w 0)\" } }" -s &> /dev/null } wx-ssh-config-sync(){ wx-header "SSH / Config / Sync" wx-restricted VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}") if [[ $VAULT_STATUS -eq 200 ]] then echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.data') | base64 -d > ~/.ssh/config 2>&1 fi } wx-ssh-config-clean(){ wx-header "SSH / Config / Clean" wx-restricted VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}") if [[ -f "$HOME/.ssh/config" && $VAULT_STATUS -eq 200 ]] then rm "$HOME/.ssh/config" fi }