Code Update
This commit is contained in:
62
src/commands/ssh/keys.sh
Normal file
62
src/commands/ssh/keys.sh
Normal file
@@ -0,0 +1,62 @@
|
||||
wx-ssh-keys(){
|
||||
echo " >> SSH / Keys << "
|
||||
echo "------------------------------"
|
||||
|
||||
case $1 in
|
||||
generate)
|
||||
wx-ssh-keys-sync $2
|
||||
wx-ssh-keys-generate $2
|
||||
wx-ssh-config-save $2
|
||||
;;
|
||||
retrieve)
|
||||
wx-ssh-keys-retrieve $2
|
||||
;;
|
||||
save)
|
||||
wx-ssh-keys-save $2
|
||||
;;
|
||||
sync)
|
||||
wx-ssh-keys-sync $2
|
||||
;;
|
||||
delete)
|
||||
wx-ssh-keys-remove $2
|
||||
;;
|
||||
*)
|
||||
wx-ssh-keys-sync
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wx-ssh-keys-generate(){
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ ! -f "$HOME/.ssh/keys/$1" ]]
|
||||
then
|
||||
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$1 -q -N "" -C "$USER" &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-retrieve(){
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.private') | base64 -d > ~/.ssh/keys/$1 2>&1
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.public') | base64 -d > ~/.ssh/keys/$1.pub 2>&1
|
||||
else
|
||||
echo "Status: Key Required"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-save(){
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ -f "$HOME/.ssh/keys/$1" ]]
|
||||
then
|
||||
curl https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/keys/$1 -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"private\": \"$(cat ~/.ssh/keys/$1 | base64 -w 0)\", \"public\": \"$(cat ~/.ssh/keys/$1.pub | base64 -w 0)\" } }" -s &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user