Code Update

This commit is contained in:
Christer Warén 2024-06-01 00:28:18 +03:00
parent 0ef3f8d8d6
commit e36265403e
18 changed files with 197 additions and 132 deletions

View File

@ -22,7 +22,6 @@ declare -Ax config
{{ FUNCTIONS }} {{ FUNCTIONS }}
{{ COMMANDS }} {{ COMMANDS }}
wx-start
if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]] if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]]
then then
wx-$1 $2 $3 $4 $5 $6 $7 $8 $9 wx-$1 $2 $3 $4 $5 $6 $7 $8 $9

View File

@ -1,8 +1,6 @@
wx-auto(){ wx-auto(){
wx-login wx-login
wx-header "Auto"
echo " >> Auto << "
echo "------------------------------"
wx-ssh-config-sync wx-ssh-config-sync
wx-ssh-keys-sync wx-ssh-keys-sync

View File

@ -1,7 +1,6 @@
wx-help(){ wx-help(){
echo " >> Help << " wx-header "Help"
echo "------------------------------"
echo -n " echo -n "
Usage: $0 COMMAND [OPTIONS] Usage: $0 COMMAND [OPTIONS]
@ -21,9 +20,13 @@ Common Commands:
sync Sync sync Sync
sign Certificates sign Certificates
Authentication Commands:
login Login
logout Logout
Management Commands: Management Commands:
auto Auto auto Auto
login Login install Install
settings Settings settings Settings
"; ";

View File

@ -2,8 +2,8 @@ wx-infra(){
wx-login wx-login
wx-ssh-sign &> /dev/null wx-ssh-sign &> /dev/null
echo " >> Infra << " wx-header "Infra"
echo "------------------------------" wx-restricted
INFRA_PATH="/home/cwchristerw/Desktop/Work in Progress/Programming/warengroup/infra" INFRA_PATH="/home/cwchristerw/Desktop/Work in Progress/Programming/warengroup/infra"

19
src/commands/install.sh Normal file
View File

@ -0,0 +1,19 @@
wx-install(){
if [[ -z $1 ]]
then
wx-header "Install"
fi
wx-restricted
if [[ -f "./wx" ]] && [[ -d "./src" ]]
then
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
mv wx.tmp wx &> /dev/null
chmod +x wx &> /dev/null
fi
mkdir $HOME/bin &> /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
}

View File

@ -3,9 +3,7 @@ wx-login(){
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]] if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
then then
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Hostname Required" echo "Status: Hostname Required"
wx-stop wx-stop
fi fi
@ -23,9 +21,7 @@ wx-login(){
then then
ORG=cwchristerw ORG=cwchristerw
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Organization Required" echo "Status: Organization Required"
wx-stop wx-stop
fi fi
@ -40,9 +36,7 @@ wx-login(){
then then
DOMAIN=christerwaren.fi DOMAIN=christerwaren.fi
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Organization Unsupported" echo "Status: Organization Unsupported"
wx-stop wx-stop
fi fi
@ -59,9 +53,7 @@ wx-login(){
then then
HOSTNAME=$(hostname --fqdn) HOSTNAME=$(hostname --fqdn)
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Hostname Required" echo "Status: Hostname Required"
wx-stop wx-stop
fi fi
@ -72,9 +64,7 @@ wx-login(){
then then
if [[ -z LOGNAME ]] if [[ -z LOGNAME ]]
then then
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Username Required" echo "Status: Username Required"
wx-stop wx-stop
else else
@ -88,7 +78,8 @@ wx-login(){
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health) VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then then
if [[ -f "$HOME/.config/warengroup/config.json" ]]
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.config/warengroup/config.json" ]]
then then
TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)" TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)"
fi fi
@ -97,15 +88,16 @@ wx-login(){
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]] if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
then then
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
else else
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]] if [[ $IDM_STATUS -eq 301 ]]
then then
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]] if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]]
@ -133,15 +125,17 @@ wx-login(){
fi fi
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
wx-start wx-start
fi fi
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
echo -n "Token: " echo -n "Token: "
@ -162,18 +156,19 @@ wx-login(){
fi fi
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
wx-start wx-start
fi fi
fi fi
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
echo "Status: Vault Offline" echo "Status: Vault Offline"
wx-stop wx-stop
fi fi

3
src/commands/logout.sh Normal file
View File

@ -0,0 +1,3 @@
wx-logout(){
wx-header "Logout"
}

View File

@ -1,6 +1,4 @@
wx-settings(){ wx-settings(){
wx-login wx-login
wx-header "Settings"
echo " >> Settings << "
echo "------------------------------"
} }

View File

@ -15,8 +15,7 @@ wx-ssh(){
wx-ssh-config $2 wx-ssh-config $2
;; ;;
*) *)
echo " >> SSH << " wx-header "SSH"
echo "------------------------------"
wx-stop wx-stop
;; ;;

View File

@ -1,6 +1,6 @@
wx-ssh-config(){ wx-ssh-config(){
echo " >> SSH / Config << " wx-header "SSH / Config"
echo "------------------------------" wx-restricted
case $1 in case $1 in
edit) edit)
@ -22,14 +22,17 @@ wx-ssh-config(){
} }
wx-ssh-config-edit(){ wx-ssh-config-edit(){
wx-restricted
nano ~/.ssh/config nano ~/.ssh/config
} }
wx-ssh-config-save(){ wx-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 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(){
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]}") 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

View File

@ -1,6 +1,5 @@
wx-ssh-keys(){ wx-ssh-keys(){
echo " >> SSH / Keys << " wx-header "SSH / Keys"
echo "------------------------------"
case $1 in case $1 in
generate) generate)
@ -28,6 +27,7 @@ wx-ssh-keys(){
} }
wx-ssh-keys-generate(){ wx-ssh-keys-generate(){
wx-restricted
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then then
if [[ ! -f "$HOME/.ssh/keys/$1" ]] if [[ ! -f "$HOME/.ssh/keys/$1" ]]
@ -38,6 +38,7 @@ wx-ssh-keys-generate(){
} }
wx-ssh-keys-retrieve(){ wx-ssh-keys-retrieve(){
wx-restricted
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then then
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]}") 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]}")
@ -50,6 +51,7 @@ wx-ssh-keys-retrieve(){
} }
wx-ssh-keys-save(){ wx-ssh-keys-save(){
wx-restricted
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then then
if [[ -f "$HOME/.ssh/keys/$1" ]] if [[ -f "$HOME/.ssh/keys/$1" ]]
@ -60,5 +62,6 @@ wx-ssh-keys-save(){
} }
wx-ssh-keys-sync(){ wx-ssh-keys-sync(){
wx-restricted
echo "" echo ""
} }

View File

@ -1,6 +1,6 @@
wx-ssh-sign(){ wx-ssh-sign(){
echo " >> SSH / Sign << " wx-header "SSH / Sign"
echo "------------------------------" wx-restricted
if [[ $ORG == "warengroup" ]] if [[ $ORG == "warengroup" ]]
then then
@ -17,6 +17,8 @@ wx-ssh-sign(){
} }
wx-ssh-sign-create(){ wx-ssh-sign-create(){
wx-restricted
NAME=$1 NAME=$1
ROLE=$2 ROLE=$2
PRINCIPALS=$2 PRINCIPALS=$2

4
src/commands/update.sh Normal file
View File

@ -0,0 +1,4 @@
wx-update(){
wx-header "Update"
wx-install --update
}

View File

@ -1,4 +1,3 @@
wx-welcome(){ wx-welcome(){
echo " >> Welcome << " wx-header "Welcome"
echo "------------------------------"
} }

6
src/functions/header.sh Normal file
View File

@ -0,0 +1,6 @@
wx-header(){
wx-start
echo ">> $1 <<"
echo "------------------------------"
}

View File

@ -0,0 +1,10 @@
wx-restricted(){
if [[ $USER == "root" || $USER == "local" ]]
then
echo "Status: Command Restricted"
echo " "
echo " "
echo " "
exit 1
fi
}

View File

@ -2,19 +2,8 @@ wx-stop (){
echo " " echo " "
echo " " echo " "
echo " " echo " "
if [[ -f "./wx" ]] && [[ -d "./src" ]]
then
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
mv wx.tmp wx &> /dev/null
chmod +x wx &> /dev/null
fi
if [[ $USER != "root" && $USER != "local" ]] wx-install --auto
then
mkdir $HOME/bin &> /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
fi
exit 1 exit 1
} }

155
wx
View File

@ -19,6 +19,24 @@ wxNormal=$(tput sgr0)
declare -Ax config declare -Ax config
wx-header(){
wx-start
echo ">> $1 <<"
echo "------------------------------"
}
wx-restricted(){
if [[ $USER == "root" || $USER == "local" ]]
then
echo "Status: Command Restricted"
echo " "
echo " "
echo " "
exit 1
fi
}
wx-start(){ wx-start(){
echo "" echo ""
echo "" echo ""
@ -41,28 +59,15 @@ wx-stop (){
echo " " echo " "
echo " " echo " "
echo " " echo " "
if [[ -f "./wx" ]] && [[ -d "./src" ]]
then
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
mv wx.tmp wx &> /dev/null
chmod +x wx &> /dev/null
fi
if [[ $USER != "root" && $USER != "local" ]] wx-install --auto
then
mkdir $HOME/bin &> /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
fi
exit 1 exit 1
} }
wx-auto(){ wx-auto(){
wx-login wx-login
wx-header "Auto"
echo " >> Auto << "
echo "------------------------------"
wx-ssh-config-sync wx-ssh-config-sync
wx-ssh-keys-sync wx-ssh-keys-sync
@ -71,8 +76,7 @@ wx-auto(){
wx-help(){ wx-help(){
echo " >> Help << " wx-header "Help"
echo "------------------------------"
echo -n " echo -n "
Usage: $0 COMMAND [OPTIONS] Usage: $0 COMMAND [OPTIONS]
@ -92,9 +96,13 @@ Common Commands:
sync Sync sync Sync
sign Certificates sign Certificates
Authentication Commands:
login Login
logout Logout
Management Commands: Management Commands:
auto Auto auto Auto
login Login install Install
settings Settings settings Settings
"; ";
@ -104,8 +112,8 @@ wx-infra(){
wx-login wx-login
wx-ssh-sign &> /dev/null wx-ssh-sign &> /dev/null
echo " >> Infra << " wx-header "Infra"
echo "------------------------------" wx-restricted
INFRA_PATH="/home/cwchristerw/Desktop/Work in Progress/Programming/warengroup/infra" INFRA_PATH="/home/cwchristerw/Desktop/Work in Progress/Programming/warengroup/infra"
@ -138,14 +146,32 @@ wx-infra(){
esac esac
} }
wx-install(){
if [[ -z $1 ]]
then
wx-header "Install"
fi
wx-restricted
if [[ -f "./wx" ]] && [[ -d "./src" ]]
then
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
mv wx.tmp wx &> /dev/null
chmod +x wx &> /dev/null
fi
mkdir $HOME/bin &> /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
}
wx-login(){ wx-login(){
ORG=$1 ORG=$1
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]] if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
then then
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Hostname Required" echo "Status: Hostname Required"
wx-stop wx-stop
fi fi
@ -163,9 +189,7 @@ wx-login(){
then then
ORG=cwchristerw ORG=cwchristerw
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Organization Required" echo "Status: Organization Required"
wx-stop wx-stop
fi fi
@ -180,9 +204,7 @@ wx-login(){
then then
DOMAIN=christerwaren.fi DOMAIN=christerwaren.fi
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Organization Unsupported" echo "Status: Organization Unsupported"
wx-stop wx-stop
fi fi
@ -199,9 +221,7 @@ wx-login(){
then then
HOSTNAME=$(hostname --fqdn) HOSTNAME=$(hostname --fqdn)
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Hostname Required" echo "Status: Hostname Required"
wx-stop wx-stop
fi fi
@ -212,9 +232,7 @@ wx-login(){
then then
if [[ -z LOGNAME ]] if [[ -z LOGNAME ]]
then then
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo "Status: Username Required" echo "Status: Username Required"
wx-stop wx-stop
else else
@ -228,7 +246,8 @@ wx-login(){
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health) VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then then
if [[ -f "$HOME/.config/warengroup/config.json" ]]
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.config/warengroup/config.json" ]]
then then
TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)" TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)"
fi fi
@ -237,15 +256,16 @@ wx-login(){
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]] if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
then then
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
else else
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]] if [[ $IDM_STATUS -eq 301 ]]
then then
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]] if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]]
@ -273,15 +293,17 @@ wx-login(){
fi fi
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
wx-start wx-start
fi fi
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
echo -n "Token: " echo -n "Token: "
@ -302,28 +324,31 @@ wx-login(){
fi fi
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]]
then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
fi
wx-start wx-start
fi fi
fi fi
else else
echo " >> Login << " wx-header "Login"
echo "------------------------------"
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
echo "Status: Vault Offline" echo "Status: Vault Offline"
wx-stop wx-stop
fi fi
} }
wx-logout(){
wx-header "Logout"
}
wx-settings(){ wx-settings(){
wx-login wx-login
wx-header "Settings"
echo " >> Settings << "
echo "------------------------------"
} }
wx-ssh(){ wx-ssh(){
@ -343,22 +368,25 @@ wx-ssh(){
wx-ssh-config $2 wx-ssh-config $2
;; ;;
*) *)
echo " >> SSH << " wx-header "SSH"
echo "------------------------------"
wx-stop wx-stop
;; ;;
esac esac
} }
wx-update(){
wx-header "Update"
wx-install --update
}
wx-welcome(){ wx-welcome(){
echo " >> Welcome << " wx-header "Welcome"
echo "------------------------------"
} }
wx-ssh-config(){ wx-ssh-config(){
echo " >> SSH / Config << " wx-header "SSH / Config"
echo "------------------------------" wx-restricted
case $1 in case $1 in
edit) edit)
@ -380,14 +408,17 @@ wx-ssh-config(){
} }
wx-ssh-config-edit(){ wx-ssh-config-edit(){
wx-restricted
nano ~/.ssh/config nano ~/.ssh/config
} }
wx-ssh-config-save(){ wx-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 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(){
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]}") 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
@ -396,8 +427,7 @@ wx-ssh-config-sync(){
} }
wx-ssh-keys(){ wx-ssh-keys(){
echo " >> SSH / Keys << " wx-header "SSH / Keys"
echo "------------------------------"
case $1 in case $1 in
generate) generate)
@ -425,6 +455,7 @@ wx-ssh-keys(){
} }
wx-ssh-keys-generate(){ wx-ssh-keys-generate(){
wx-restricted
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then then
if [[ ! -f "$HOME/.ssh/keys/$1" ]] if [[ ! -f "$HOME/.ssh/keys/$1" ]]
@ -435,6 +466,7 @@ wx-ssh-keys-generate(){
} }
wx-ssh-keys-retrieve(){ wx-ssh-keys-retrieve(){
wx-restricted
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then then
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]}") 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]}")
@ -447,6 +479,7 @@ wx-ssh-keys-retrieve(){
} }
wx-ssh-keys-save(){ wx-ssh-keys-save(){
wx-restricted
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then then
if [[ -f "$HOME/.ssh/keys/$1" ]] if [[ -f "$HOME/.ssh/keys/$1" ]]
@ -457,12 +490,13 @@ wx-ssh-keys-save(){
} }
wx-ssh-keys-sync(){ wx-ssh-keys-sync(){
wx-restricted
echo "" echo ""
} }
wx-ssh-sign(){ wx-ssh-sign(){
echo " >> SSH / Sign << " wx-header "SSH / Sign"
echo "------------------------------" wx-restricted
if [[ $ORG == "warengroup" ]] if [[ $ORG == "warengroup" ]]
then then
@ -479,6 +513,8 @@ wx-ssh-sign(){
} }
wx-ssh-sign-create(){ wx-ssh-sign-create(){
wx-restricted
NAME=$1 NAME=$1
ROLE=$2 ROLE=$2
PRINCIPALS=$2 PRINCIPALS=$2
@ -497,7 +533,6 @@ wx-ssh-sign-create(){
} }
wx-start
if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]] if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]]
then then
wx-$1 $2 $3 $4 $5 $6 $7 $8 $9 wx-$1 $2 $3 $4 $5 $6 $7 $8 $9