Code Update
This commit is contained in:
parent
fb02109d68
commit
a6cb4ae626
@ -19,6 +19,7 @@ wxNormal=$(tput sgr0)
|
||||
|
||||
declare -Ax config
|
||||
|
||||
|
||||
{{ FUNCTIONS }}
|
||||
{{ COMMANDS }}
|
||||
|
||||
|
@ -6,7 +6,7 @@ wx-ssh(){
|
||||
wx-ssh-sign
|
||||
;;
|
||||
config)
|
||||
wx-ssh-config
|
||||
wx-ssh-config $2
|
||||
;;
|
||||
*)
|
||||
echo " >> SSH << "
|
||||
|
@ -1,5 +1,36 @@
|
||||
wx-ssh-config(){
|
||||
echo " >> SSH << "
|
||||
echo " Config "
|
||||
echo " >> SSH / Config << "
|
||||
echo "------------------------------"
|
||||
|
||||
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
|
||||
;;
|
||||
*)
|
||||
wx-ssh-config-sync
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
}
|
||||
|
||||
wx-ssh-config-edit(){
|
||||
nano ~/.ssh/config
|
||||
}
|
||||
|
||||
wx-ssh-config-save(){
|
||||
curl https://$VAULT_DOMAIN/v1/cli/data/$USER -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"settings/ssh/config\": \"$(cat ~/.ssh/config | base64 -w 0)\" } }" -s &> /dev/null
|
||||
}
|
||||
|
||||
wx-ssh-config-sync(){
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USER -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data["settings/ssh/config"]') | base64 -d > ~/.ssh/config 2>&1
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
wx-ssh-sign(){
|
||||
echo " >> SSH << "
|
||||
echo " Sign "
|
||||
echo " >> SSH / Sign << "
|
||||
echo "------------------------------"
|
||||
|
||||
if [[ $ORG == "warengroup" ]]
|
||||
@ -35,6 +34,6 @@ wx-ssh-sign-create(){
|
||||
if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]]
|
||||
then
|
||||
echo "$NAME/$ROLE"
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
|
||||
fi
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
wx-login(){
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
ORG=$1
|
||||
|
||||
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
|
||||
@ -20,6 +17,9 @@ wx-login(){
|
||||
ORG=cwchristerw
|
||||
elif [[ -z $ORG ]]
|
||||
then
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo -n "Status: Organization Required"
|
||||
wx-stop
|
||||
fi
|
||||
@ -34,6 +34,9 @@ wx-login(){
|
||||
then
|
||||
DOMAIN=christerwaren.fi
|
||||
else
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo -n "Status: Organization Unsupported"
|
||||
wx-stop
|
||||
fi
|
||||
@ -51,6 +54,9 @@ wx-login(){
|
||||
then
|
||||
HOSTNAME="$2.$DEVICE_DOMAIN"
|
||||
else
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo -n "Status: Hostname Required"
|
||||
wx-stop
|
||||
fi
|
||||
@ -61,6 +67,9 @@ wx-login(){
|
||||
then
|
||||
if [[ -z LOGNAME ]]
|
||||
then
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo -n "Status: Username Required"
|
||||
wx-stop
|
||||
else
|
||||
@ -74,30 +83,23 @@ wx-login(){
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
if [[ -f "$HOME/.config/warengroup/login.json" ]]
|
||||
if [[ -f "$HOME/.config/warengroup/config.json" ]]
|
||||
then
|
||||
TOKEN="$(cat $HOME/.config/warengroup/login.json | jq -r .$ORG)"
|
||||
TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)"
|
||||
fi
|
||||
|
||||
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token')
|
||||
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
|
||||
then
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
echo -n "Username: "
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/auth/token/lookup-self -X GET --header "X-Vault-Token: $VAULT_LOGIN" -s | jq -r '.data.meta.username')
|
||||
|
||||
echo -n "Token: "
|
||||
echo "****************"
|
||||
|
||||
config[${ORG}]=$VAULT_LOGIN
|
||||
echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json
|
||||
|
||||
wx-start
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
|
||||
else
|
||||
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
|
||||
if [[ $IDM_STATUS -eq 301 ]]
|
||||
then
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
|
||||
@ -125,16 +127,19 @@ wx-login(){
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config[${ORG}]=$VAULT_LOGIN
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
mkdir -p $HOME/.config/warengroup &> /dev/null
|
||||
touch $HOME/.config/warengroup/login.json &> /dev/null
|
||||
touch $HOME/.config/warengroup/config.json &> /dev/null
|
||||
|
||||
echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json
|
||||
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
|
||||
|
||||
wx-start
|
||||
fi
|
||||
else
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
echo -n "Token: "
|
||||
@ -154,17 +159,20 @@ wx-login(){
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config[${ORG}]=$VAULT_LOGIN
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
mkdir -p $HOME/.config/warengroup &> /dev/null
|
||||
touch $HOME/.config/warengroup/login.json &> /dev/null
|
||||
touch $HOME/.config/warengroup/config.json &> /dev/null
|
||||
|
||||
echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json
|
||||
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
|
||||
|
||||
wx-start
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
echo -n "Status: Vault Offline"
|
||||
|
97
wx
97
wx
@ -19,10 +19,8 @@ wxNormal=$(tput sgr0)
|
||||
|
||||
declare -Ax config
|
||||
|
||||
wx-login(){
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
wx-login(){
|
||||
ORG=$1
|
||||
|
||||
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
|
||||
@ -41,6 +39,9 @@ wx-login(){
|
||||
ORG=cwchristerw
|
||||
elif [[ -z $ORG ]]
|
||||
then
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo -n "Status: Organization Required"
|
||||
wx-stop
|
||||
fi
|
||||
@ -55,6 +56,9 @@ wx-login(){
|
||||
then
|
||||
DOMAIN=christerwaren.fi
|
||||
else
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo -n "Status: Organization Unsupported"
|
||||
wx-stop
|
||||
fi
|
||||
@ -72,6 +76,9 @@ wx-login(){
|
||||
then
|
||||
HOSTNAME="$2.$DEVICE_DOMAIN"
|
||||
else
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo -n "Status: Hostname Required"
|
||||
wx-stop
|
||||
fi
|
||||
@ -82,6 +89,9 @@ wx-login(){
|
||||
then
|
||||
if [[ -z LOGNAME ]]
|
||||
then
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo -n "Status: Username Required"
|
||||
wx-stop
|
||||
else
|
||||
@ -95,30 +105,23 @@ wx-login(){
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
if [[ -f "$HOME/.config/warengroup/login.json" ]]
|
||||
if [[ -f "$HOME/.config/warengroup/config.json" ]]
|
||||
then
|
||||
TOKEN="$(cat $HOME/.config/warengroup/login.json | jq -r .$ORG)"
|
||||
TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)"
|
||||
fi
|
||||
|
||||
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token')
|
||||
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
|
||||
then
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
echo -n "Username: "
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/auth/token/lookup-self -X GET --header "X-Vault-Token: $VAULT_LOGIN" -s | jq -r '.data.meta.username')
|
||||
|
||||
echo -n "Token: "
|
||||
echo "****************"
|
||||
|
||||
config[${ORG}]=$VAULT_LOGIN
|
||||
echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json
|
||||
|
||||
wx-start
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
|
||||
else
|
||||
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
|
||||
if [[ $IDM_STATUS -eq 301 ]]
|
||||
then
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
|
||||
@ -146,16 +149,19 @@ wx-login(){
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config[${ORG}]=$VAULT_LOGIN
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
mkdir -p $HOME/.config/warengroup &> /dev/null
|
||||
touch $HOME/.config/warengroup/login.json &> /dev/null
|
||||
touch $HOME/.config/warengroup/config.json &> /dev/null
|
||||
|
||||
echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json
|
||||
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
|
||||
|
||||
wx-start
|
||||
fi
|
||||
else
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
echo -n "Token: "
|
||||
@ -175,17 +181,20 @@ wx-login(){
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config[${ORG}]=$VAULT_LOGIN
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
mkdir -p $HOME/.config/warengroup &> /dev/null
|
||||
touch $HOME/.config/warengroup/login.json &> /dev/null
|
||||
touch $HOME/.config/warengroup/config.json &> /dev/null
|
||||
|
||||
echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json
|
||||
echo '{ "login": { "'$ORG'": "'$VAULT_LOGIN'" } }' | jq > $HOME/.config/warengroup/config.json
|
||||
|
||||
wx-start
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo " >> Login << "
|
||||
echo "------------------------------"
|
||||
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
echo -n "Status: Vault Offline"
|
||||
@ -281,7 +290,7 @@ wx-ssh(){
|
||||
wx-ssh-sign
|
||||
;;
|
||||
config)
|
||||
wx-ssh-config
|
||||
wx-ssh-config $2
|
||||
;;
|
||||
*)
|
||||
echo " >> SSH << "
|
||||
@ -298,14 +307,44 @@ wx-welcome(){
|
||||
}
|
||||
|
||||
wx-ssh-config(){
|
||||
echo " >> SSH << "
|
||||
echo " Config "
|
||||
echo " >> SSH / Config << "
|
||||
echo "------------------------------"
|
||||
|
||||
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
|
||||
;;
|
||||
*)
|
||||
wx-ssh-config-sync
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
}
|
||||
|
||||
wx-ssh-config-edit(){
|
||||
nano ~/.ssh/config
|
||||
}
|
||||
|
||||
wx-ssh-config-save(){
|
||||
curl https://$VAULT_DOMAIN/v1/cli/data/$USER -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"settings/ssh/config\": \"$(cat ~/.ssh/config | base64 -w 0)\" } }" -s &> /dev/null
|
||||
}
|
||||
|
||||
wx-ssh-config-sync(){
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USER -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data["settings/ssh/config"]') | base64 -d > ~/.ssh/config 2>&1
|
||||
}
|
||||
|
||||
wx-ssh-sign(){
|
||||
echo " >> SSH << "
|
||||
echo " Sign "
|
||||
echo " >> SSH / Sign << "
|
||||
echo "------------------------------"
|
||||
|
||||
if [[ $ORG == "warengroup" ]]
|
||||
@ -340,7 +379,7 @@ wx-ssh-sign-create(){
|
||||
if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]]
|
||||
then
|
||||
echo "$NAME/$ROLE"
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user