mirror of https://github.com/easzlab/kubeasz.git
fix: easzctl basic-auth 命令执行问题 #544
parent
fbaab4195b
commit
6b7d34cd10
|
@ -307,31 +307,30 @@ function start-aio(){
|
|||
}
|
||||
|
||||
### extra operation functions ###################################
|
||||
function print-user-pass(){
|
||||
echo -e "\n[INFO]basic auth for apiserver enabled\n"
|
||||
sed -n '/BASIC_AUTH_USER/p' $BASEPATH/roles/kube-master/defaults/main.yml
|
||||
sed -n '/BASIC_AUTH_PASS/p' $BASEPATH/roles/kube-master/defaults/main.yml
|
||||
}
|
||||
|
||||
function basic-auth(){
|
||||
OPTIND=2
|
||||
CONFIG=$BASEPATH/roles/kube-master/defaults/main.yml
|
||||
EX_VARS=""
|
||||
while getopts "sSu:p:" OPTION; do
|
||||
case $OPTION in
|
||||
s)
|
||||
grep BASIC_AUTH_ENABLE roles/kube-master/defaults/main.yml|grep yes > /dev/null && { print-user-pass; return 0; }
|
||||
sed -i "s/BASIC_AUTH_ENABLE.*$/BASIC_AUTH_ENABLE: 'yes'/g" $BASEPATH/roles/kube-master/defaults/main.yml
|
||||
EX_VARS="BASIC_AUTH_ENABLE=yes $EX_VARS"
|
||||
ENABLED=yes
|
||||
;;
|
||||
S)
|
||||
grep BASIC_AUTH_ENABLE roles/kube-master/defaults/main.yml|grep no > /dev/null && { echo -e "\n[INFO]basic auth for apiserver disabled\n"; return 0; }
|
||||
sed -i "s/BASIC_AUTH_ENABLE.*$/BASIC_AUTH_ENABLE: 'no'/g" $BASEPATH/roles/kube-master/defaults/main.yml
|
||||
grep BASIC_AUTH_ENABLE $CONFIG|grep no > /dev/null && \
|
||||
{ echo -e "\n[WARN]basic-auth already disabled!\n"; return 1; }
|
||||
EX_VARS="BASIC_AUTH_ENABLE=no $EX_VARS"
|
||||
ENABLED=no
|
||||
;;
|
||||
u)
|
||||
grep BASIC_AUTH_ENABLE roles/kube-master/defaults/main.yml|grep no > /dev/null && { echo -e "\n[INFO]basic auth for apiserver disabled\n"; return 0; }
|
||||
sed -i "s/BASIC_AUTH_USER.*$/BASIC_AUTH_USER: '$OPTARG'/g" $BASEPATH/roles/kube-master/defaults/main.yml
|
||||
EX_VARS="BASIC_AUTH_USER=$OPTARG $EX_VARS"
|
||||
sed -i "s/BASIC_AUTH_USER.*$/BASIC_AUTH_USER: '$OPTARG'/g" $CONFIG
|
||||
;;
|
||||
p)
|
||||
grep BASIC_AUTH_ENABLE roles/kube-master/defaults/main.yml|grep no > /dev/null && { echo -e "\n[INFO]basic auth for apiserver disabled\n"; return 0; }
|
||||
sed -i "s/BASIC_AUTH_PASS.*$/BASIC_AUTH_PASS: '$OPTARG'/g" $BASEPATH/roles/kube-master/defaults/main.yml
|
||||
EX_VARS="BASIC_AUTH_PASS=$OPTARG $EX_VARS"
|
||||
sed -i "s/BASIC_AUTH_PASS.*$/BASIC_AUTH_PASS: '$OPTARG'/g" $CONFIG
|
||||
;;
|
||||
?)
|
||||
help-info basic-auth
|
||||
|
@ -340,7 +339,15 @@ function basic-auth(){
|
|||
esac
|
||||
done
|
||||
|
||||
ansible-playbook $BASEPATH/04.kube-master.yml -t restart_master
|
||||
ansible-playbook $BASEPATH/04.kube-master.yml -t restart_master -e "$EX_VARS" || { return 1; }
|
||||
sed -i "s/BASIC_AUTH_ENABLE.*$/BASIC_AUTH_ENABLE: '$ENABLED'/g" $CONFIG
|
||||
if [[ $ENABLED == yes ]];then
|
||||
echo -e "\n[INFO]basic-auth for apiserver is enabled!"
|
||||
sed -n '/BASIC_AUTH_USER/p' $CONFIG
|
||||
sed -n '/BASIC_AUTH_PASS/p' $CONFIG
|
||||
elif [[ $ENABLED == no ]];then
|
||||
echo -e "\n[INFO]basic-auth for apiserver is disabled!\n"
|
||||
fi
|
||||
}
|
||||
|
||||
### Main Lines ##################################################
|
||||
|
|
Loading…
Reference in New Issue