From 482b226cdc042d8b89b4433fe323fc9641796820 Mon Sep 17 00:00:00 2001 From: Olivier Grand Date: Wed, 16 May 2018 15:28:51 +0200 Subject: [PATCH] fix log-* tools with uaa/ldap on bosh directors --- scripts/log-bosh | 35 +++++++++++------------------------ scripts/log-cf | 7 +++---- scripts/log-credhub | 2 +- scripts/log-fly | 9 +++------ scripts/log-mc | 5 ++--- scripts/log-openstack | 11 +++-------- 6 files changed, 23 insertions(+), 46 deletions(-) diff --git a/scripts/log-bosh b/scripts/log-bosh index f00bf43..0ec0a15 100644 --- a/scripts/log-bosh +++ b/scripts/log-bosh @@ -29,36 +29,23 @@ else printf "%b7%b : expe\n" "${GREEN}${BOLD}" "${STD}" printf "\n%bYour choice :%b " "${GREEN}${BOLD}" "${STD}" ; read choice case "${choice}" in - 1) BOSH_TARGET="micro" ; BOSH_CLIENT="admin" ;; - 2) BOSH_TARGET="master" ; BOSH_CLIENT="${MY_BOSH_USER}" ;; - 3) BOSH_TARGET="ops" ; BOSH_CLIENT="${MY_BOSH_USER}" ;; - 4) BOSH_TARGET="kubo" ; BOSH_CLIENT="admin" ;; - 5) BOSH_TARGET="coab" ; BOSH_CLIENT="${MY_BOSH_USER}" ;; - 6) BOSH_TARGET="ondemand" ; BOSH_CLIENT="${MY_BOSH_USER}" ;; - 7) BOSH_TARGET="expe" ; BOSH_CLIENT="${MY_BOSH_USER}" ;; + 1) BOSH_TARGET="micro" ;; + 2) BOSH_TARGET="master" ;; + 3) BOSH_TARGET="ops" ;; + 4) BOSH_TARGET="kubo" ;; + 5) BOSH_TARGET="coab" ;; + 6) BOSH_TARGET="ondemand" ;; + 7) BOSH_TARGET="expe" ;; *) flag=0 ;; esac done - flag=0 - while [ ${flag} = 0 ] ; do - clear - printf "%bEnter \"${BOSH_CLIENT}\" Password on \"${BOSH_TARGET}\" :%b " "${REVERSE}${YELLOW}" "${STD}" ; read -s BOSH_CLIENT_SECRET - if [ "${BOSH_CLIENT_SECRET}" != "" ] ; then - flag=1 - fi - done - - #--- BOSH variables (used by bosh cli V2) - export BOSH_ENVIRONMENT=`host bosh-${BOSH_TARGET}.internal.paas | awk '{print $4}'` - export BOSH_CLIENT - export BOSH_CLIENT_SECRET - export BOSH_CA_CERT - #--- Login to the director and list active deployments + export BOSH_ENVIRONMENT=`host bosh-${BOSH_TARGET}.internal.paas | awk '{print $4}'` bosh alias-env ${BOSH_TARGET} > /dev/null 2>&1 - bosh log-in > /dev/null 2>&1 - if [ $? = 1 ] ; then + printf "%bEnter CF LDAP user and password :%b\n" "${REVERSE}${YELLOW}" "${STD}" + bosh log-in + if [ $? != 0 ] ; then printf "\n\n%bERROR : Log to bosh director \"${BOSH_TARGET}\" failed whith user \"${BOSH_CLIENT}\".%b\n\n" "${RED}" "${STD}" else #--- Select specific deployment (BOSH_DEPLOYMENT variable) diff --git a/scripts/log-cf b/scripts/log-cf index d256456..6212417 100644 --- a/scripts/log-cf +++ b/scripts/log-cf @@ -15,8 +15,7 @@ getCredhub() { #--- Test if parameter exist with non empty value, else get it from credhub if [ "${!1}" = "" ] ; then credhubGet=`credhub g -n $2 2>&1` - result=`echo "${credhubGet}" | grep "Credential not found"` - if [ "${result}" = "" ] ; then + if [ $? = 0 ] ; then credhubValue=`echo "${credhubGet}" | grep "value: " | awk '{print $2}'` eval $1=`echo "${credhubGet}" | grep "value: " | awk '{print $2}'` else @@ -34,7 +33,7 @@ if [ $? != 0 ] ; then credhub api --server=https://credhub.internal.paas:8844 > /dev/null 2>&1 credhub login if [ $? != 0 ] ; then - printf "\n%bERROR : Bad LDAP authentication.\nConnexion failed.%b\n\n" "${RED}" "${STD}" + printf "\n%bERROR : Bad LDAP authentication.%b\n\n" "${RED}" "${STD}" flagError=1 fi fi @@ -53,7 +52,7 @@ if [ "${flagError}" = "0" ] ; then getCredhub "SYSTEM_DOMAIN" "/secrets/cloudfoundry_system_domain" if [ ${flagError} = 0 ] ; then cf login -a https://api.${SYSTEM_DOMAIN} -u ${CF_USER} - if [ $? = 1 ] ; then + if [ $? != 0 ] ; then printf "\n%bERROR : Connexion failed.%b\n\n" "${RED}" "${STD}" else printf "\n\n" diff --git a/scripts/log-credhub b/scripts/log-credhub index a778807..5800b1a 100644 --- a/scripts/log-credhub +++ b/scripts/log-credhub @@ -18,7 +18,7 @@ if [ $? != 0 ] ; then credhub api --server=https://credhub.internal.paas:8844 > /dev/null 2>&1 credhub login if [ $? != 0 ] ; then - printf "\n%bERROR : Bad LDAP authentication.\nConnexion failed.%b\n\n" "${RED}" "${STD}" + printf "\n%bERROR : Bad LDAP authentication.%b\n\n" "${RED}" "${STD}" else printf "\n\n" fi diff --git a/scripts/log-fly b/scripts/log-fly index 3161d4e..0617520 100644 --- a/scripts/log-fly +++ b/scripts/log-fly @@ -11,14 +11,11 @@ export STD='\033[0m' export BOLD='\033[1m' export REVERSE='\033[7m' -flagError=0 - getCredhub() { #--- Test if parameter exist with non empty value, else get it from credhub if [ "${!1}" = "" ] ; then credhubGet=`credhub g -n $2 2>&1` - result=`echo "${credhubGet}" | grep "Credential not found"` - if [ "${result}" = "" ] ; then + if [ $? = 0 ] ; then credhubValue=`echo "${credhubGet}" | grep "value: " | awk '{print $2}'` eval $1=`echo "${credhubGet}" | grep "value: " | awk '{print $2}'` else @@ -36,7 +33,7 @@ if [ $? != 0 ] ; then credhub api --server=https://credhub.internal.paas:8844 > /dev/null 2>&1 credhub login if [ $? != 0 ] ; then - printf "\n%bERROR : Bad LDAP authentication.\nConnexion failed.%b\n\n" "${RED}" "${STD}" + printf "\n%bERROR : Bad LDAP authentication.%b\n\n" "${RED}" "${STD}" flagError=1 fi fi @@ -56,7 +53,7 @@ if [ ${flagError} = 0 ] ; then done fi fly login -c https://elpaaso-concourse-micro.${OPS_DOMAIN} -k -u atc -p ${FLY_PASSWORD} - if [ $? = 1 ] ; then + if [ $? != 0 ] ; then FLY_PASSWORD="" printf "\n\n%bERROR : Connexion failed.%b\n\n" "${RED}" "${STD}" else diff --git a/scripts/log-mc b/scripts/log-mc index 913cdcb..fb73f16 100644 --- a/scripts/log-mc +++ b/scripts/log-mc @@ -15,8 +15,7 @@ getCredhub() { #--- Test if parameter exist with non empty value, else get it from credhub if [ "${!1}" = "" ] ; then credhubGet=`credhub g -n $2 2>&1` - result=`echo "${credhubGet}" | grep "Credential not found"` - if [ "${result}" = "" ] ; then + if [ $? = 0 ] ; then credhubValue=`echo "${credhubGet}" | grep "value: " | awk '{print $2}'` eval $1=`echo "${credhubGet}" | grep "value: " | awk '{print $2}'` else @@ -34,7 +33,7 @@ if [ $? != 0 ] ; then credhub api --server=https://credhub.internal.paas:8844 > /dev/null 2>&1 credhub login if [ $? != 0 ] ; then - printf "\n%bERROR : Bad LDAP authentication.\nConnexion failed.%b\n\n" "${RED}" "${STD}" + printf "\n%bERROR : Bad LDAP authentication.%b\n\n" "${RED}" "${STD}" flagError=1 fi fi diff --git a/scripts/log-openstack b/scripts/log-openstack index 2441ac6..f28ff2f 100644 --- a/scripts/log-openstack +++ b/scripts/log-openstack @@ -11,20 +11,15 @@ export STD='\033[0m' export BOLD='\033[1m' export REVERSE='\033[7m' -flagError=0 - getCredhub() { #--- Test if parameter exist with non empty value, else get it from credhub if [ "${!1}" = "" ] ; then credhubGet=`credhub g -n $2 2>&1` - result=`echo "${credhubGet}" | grep "Credential not found"` - if [ "${result}" = "" ] ; then + if [ $? = 0 ] ; then credhubValue=`echo "${credhubGet}" | grep "value: " | awk '{print $2}'` eval $1=`echo "${credhubGet}" | grep "value: " | awk '{print $2}'` else - if [ "$3" != "test" ] ; then - printf "\n\n%bERROR : \"$2\" credhub value unknown.%b\n\n" "${RED}" "${STD}" - fi + printf "\n\n%bERROR : \"$2\" credhub value unknown.%b\n\n" "${RED}" "${STD}" flagError=1 fi fi @@ -38,7 +33,7 @@ if [ $? != 0 ] ; then credhub api --server=https://credhub.internal.paas:8844 > /dev/null 2>&1 credhub login if [ $? != 0 ] ; then - printf "\n%bERROR : Bad LDAP authentication.\nConnexion failed.%b\n\n" "${RED}" "${STD}" + printf "\n%bERROR : Bad LDAP authentication.%b\n\n" "${RED}" "${STD}" flagError=1 fi fi