Code Update

This commit is contained in:
Christer Warén 2024-05-31 23:26:44 +03:00
parent 706a917dbf
commit 0ef3f8d8d6
7 changed files with 42 additions and 38 deletions

View File

@ -7,7 +7,7 @@ wx-infra(){
INFRA_PATH="/home/cwchristerw/Desktop/Work in Progress/Programming/warengroup/infra" INFRA_PATH="/home/cwchristerw/Desktop/Work in Progress/Programming/warengroup/infra"
case $USER in case $USERNAME in
cwchristerw) cwchristerw)
if [[ -z $1 ]] if [[ -z $1 ]]
then then

View File

@ -78,10 +78,10 @@ wx-login(){
echo "Status: Username Required" echo "Status: Username Required"
wx-stop wx-stop
else else
USER=$LOGNAME USERNAME=$LOGNAME
fi fi
else else
USER=$SUDO_USER USERNAME=$SUDO_USER
fi fi
fi fi
@ -108,13 +108,12 @@ wx-login(){
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
if [[ -z $USER || $USER == "root" || $USER == "local" ]] if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]]
then then
echo -n "Username: " echo -n "Username: "
read USERNAME read USERNAME
else else
echo "Username: $USER" echo "Username: $USERNAME"
USERNAME=$USER
fi fi
echo -n "Password: " echo -n "Password: "

View File

@ -26,13 +26,13 @@ wx-ssh-config-edit(){
} }
wx-ssh-config-save(){ wx-ssh-config-save(){
curl https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/config -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"data\": \"$(cat ~/.ssh/config | base64 -w 0)\" } }" -s &> /dev/null 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-ssh-config-sync(){
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}") 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 ]] if [[ $VAULT_STATUS -eq 200 ]]
then then
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.data') | base64 -d > ~/.ssh/config 2>&1 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 fi
} }

View File

@ -32,7 +32,7 @@ wx-ssh-keys-generate(){
then then
if [[ ! -f "$HOME/.ssh/keys/$1" ]] if [[ ! -f "$HOME/.ssh/keys/$1" ]]
then then
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$1 -q -N "" -C "$USER" &> /dev/null ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$1 -q -N "" -C "$USERNAME" &> /dev/null
fi fi
fi fi
} }
@ -40,11 +40,11 @@ wx-ssh-keys-generate(){
wx-ssh-keys-retrieve(){ wx-ssh-keys-retrieve(){
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then 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]}") VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then 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/$USERNAME/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 echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/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
fi fi
fi fi
} }
@ -54,7 +54,7 @@ wx-ssh-keys-save(){
then then
if [[ -f "$HOME/.ssh/keys/$1" ]] if [[ -f "$HOME/.ssh/keys/$1" ]]
then 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 curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/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
fi fi
} }

View File

@ -24,12 +24,12 @@ wx-ssh-sign-create(){
if [[ ! -f "$HOME/.ssh/keys/$NAME" ]] if [[ ! -f "$HOME/.ssh/keys/$NAME" ]]
then then
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$NAME -q -N "" -C "$USER" &> /dev/null ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$NAME -q -N "" -C "$USERNAME" &> /dev/null
fi fi
if [[ -f "$HOME/.ssh/keys/$NAME" ]] if [[ -f "$HOME/.ssh/keys/$NAME" ]]
then then
echo "$NAME/$ROLE" echo "$NAME/$ROLE"
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.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME.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.pub)\", \"valid_principals\": \"$PRINCIPALS,$USERNAME\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME.sig 2>&1
fi fi
} }

View File

@ -9,9 +9,12 @@ wx-stop (){
chmod +x wx &> /dev/null chmod +x wx &> /dev/null
fi fi
if [[ $USER != "root" && $USER != "local" ]]
then
mkdir $HOME/bin &> /dev/null mkdir $HOME/bin &> /dev/null
curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o $HOME/bin/wx &> /dev/null curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o $HOME/bin/wx &> /dev/null
chmod +x $HOME/bin/wx &> /dev/null chmod +x $HOME/bin/wx &> /dev/null
fi
exit 1 exit 1
} }

34
wx
View File

@ -48,9 +48,12 @@ wx-stop (){
chmod +x wx &> /dev/null chmod +x wx &> /dev/null
fi fi
if [[ $USER != "root" && $USER != "local" ]]
then
mkdir $HOME/bin &> /dev/null mkdir $HOME/bin &> /dev/null
curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o $HOME/bin/wx &> /dev/null curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o $HOME/bin/wx &> /dev/null
chmod +x $HOME/bin/wx &> /dev/null chmod +x $HOME/bin/wx &> /dev/null
fi
exit 1 exit 1
} }
@ -106,7 +109,7 @@ wx-infra(){
INFRA_PATH="/home/cwchristerw/Desktop/Work in Progress/Programming/warengroup/infra" INFRA_PATH="/home/cwchristerw/Desktop/Work in Progress/Programming/warengroup/infra"
case $USER in case $USERNAME in
cwchristerw) cwchristerw)
if [[ -z $1 ]] if [[ -z $1 ]]
then then
@ -215,10 +218,10 @@ wx-login(){
echo "Status: Username Required" echo "Status: Username Required"
wx-stop wx-stop
else else
USER=$LOGNAME USERNAME=$LOGNAME
fi fi
else else
USER=$SUDO_USER USERNAME=$SUDO_USER
fi fi
fi fi
@ -245,13 +248,12 @@ wx-login(){
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
if [[ -z $USER || $USER == "root" || $USER == "local" ]] if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]]
then then
echo -n "Username: " echo -n "Username: "
read USERNAME read USERNAME
else else
echo "Username: $USER" echo "Username: $USERNAME"
USERNAME=$USER
fi fi
echo -n "Password: " echo -n "Password: "
@ -382,14 +384,14 @@ wx-ssh-config-edit(){
} }
wx-ssh-config-save(){ wx-ssh-config-save(){
curl https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/config -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"data\": \"$(cat ~/.ssh/config | base64 -w 0)\" } }" -s &> /dev/null 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-ssh-config-sync(){
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}") 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 ]] if [[ $VAULT_STATUS -eq 200 ]]
then then
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USER/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.data') | base64 -d > ~/.ssh/config 2>&1 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 fi
} }
@ -427,7 +429,7 @@ wx-ssh-keys-generate(){
then then
if [[ ! -f "$HOME/.ssh/keys/$1" ]] if [[ ! -f "$HOME/.ssh/keys/$1" ]]
then then
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$1 -q -N "" -C "$USER" &> /dev/null ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$1 -q -N "" -C "$USERNAME" &> /dev/null
fi fi
fi fi
} }
@ -435,11 +437,11 @@ wx-ssh-keys-generate(){
wx-ssh-keys-retrieve(){ wx-ssh-keys-retrieve(){
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then 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]}") VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then 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/$USERNAME/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 echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/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
fi fi
fi fi
} }
@ -449,7 +451,7 @@ wx-ssh-keys-save(){
then then
if [[ -f "$HOME/.ssh/keys/$1" ]] if [[ -f "$HOME/.ssh/keys/$1" ]]
then 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 curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/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
fi fi
} }
@ -484,13 +486,13 @@ wx-ssh-sign-create(){
if [[ ! -f "$HOME/.ssh/keys/$NAME" ]] if [[ ! -f "$HOME/.ssh/keys/$NAME" ]]
then then
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$NAME -q -N "" -C "$USER" &> /dev/null ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$NAME -q -N "" -C "$USERNAME" &> /dev/null
fi fi
if [[ -f "$HOME/.ssh/keys/$NAME" ]] if [[ -f "$HOME/.ssh/keys/$NAME" ]]
then then
echo "$NAME/$ROLE" echo "$NAME/$ROLE"
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.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME.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.pub)\", \"valid_principals\": \"$PRINCIPALS,$USERNAME\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME.sig 2>&1
fi fi
} }