#!/bin/sh
#-------------------------------------------------------------------------------
#
# Script to connect to IBM Cloud DB, version 2.0
# Author : JJY
#
#-------------------------------------------------------------------------------
#set -vx
##############
#INSTANCIATION
##############
DOMAIN="<domain>"
DATABASE="postgres"
USERNAME="<user_dba>"
while true
do
DATABASE="postgres"
clear
echo "CONNEXION AUX BASES DU CLOUD "
echo " "
echo "CONNEXION A l ECOSYSTEM : <ecosystem>"
echo " "
echo "1 - DEV(dbname) - serveur : <instance> connexion DBA"
echo " "
echo "2 - DEV(dbname) - serveur : <instance> connexion dynamique applicative"
echo " "
echo "3 - QUAL(dbname) - serveur : <instance> connexion DBA"
echo " "
echo "4 - QUAL(dbname) - serveur : <instance> connexion dynamique applicative"
echo " "
echo "0 - TOOLBOX VAULT "
echo " "
echo " Faites votre choix (0 a 4) :"
echo " Taper Q pour quitter."
echo " "
read var
case $var in
1)
echo "Connexion a la base, veuillez patienter..."
export ECOSYSTEM=<ecosystem>;export SERVER=<instance>;export PORT=<port>;
vault read -ns="$VAULT_NAMESPACE/$ECOSYSTEM" database/postgres/$SERVER/static-creds/$USERNAME
secret=$(vault read -ns="$VAULT_NAMESPACE/$ECOSYSTEM" database/postgres/$SERVER/static-creds/$USERNAME | grep password | awk '{print $2}')
export PGPASSWORD=$secret;psql -h $SERVER$DOMAIN -p $PORT -U $USERNAME -d $DATABASE
;;
2)
export ECOSYSTEM=<ecosystem>;export SERVER=<instance>;export PORT=<port>;export DATABASE=<dbname>
echo "Liste des roles:"
vault list -ns=$VAULT_NAMESPACE/$ECOSYSTEM database/postgres/$SERVER/roles
echo " "
echo "A quel role souhaitez-vous vous connecter:"
read ROLE
clear
echo "Connexion a la base en mode dynamique, veuillez patienter..."
var=$(vault read -ns=$VAULT_NAMESPACE/$ECOSYSTEM database/postgres/$SERVER/creds/$ROLE)
username=$(echo "$var" | grep username | awk '{print $2}');
password=$(echo "$var" | grep password | awk '{print $2}');
echo "User is : $username"
echo "Password is : $password"
echo " Tapez entrée pour continuer."
read bidon
export PGPASSWORD=$password;psql -h $SERVER$DOMAIN -p $PORT -U $username -d $DATABASE
;;
3)
echo "Connexion a la base, veuillez patienter..."
export ECOSYSTEM=<ecosystem>;export SERVER=<instance>;export PORT=<port>;
vault read -ns="$VAULT_NAMESPACE/$ECOSYSTEM" database/postgres/$SERVER/static-creds/$USERNAME
secret=$(vault read -ns="$VAULT_NAMESPACE/$ECOSYSTEM" database/postgres/$SERVER/static-creds/$USERNAME | grep password | awk '{print $2}')
export PGPASSWORD=$secret;psql -h $SERVER$DOMAIN -p $PORT -U $USERNAME -d $DATABASE
;;
4)
export ECOSYSTEM=<ecosystem>;export SERVER=<instance>;export PORT=<port>;export DATABASE=<dbname>
echo "Liste des roles:"
vault list -ns=$VAULT_NAMESPACE/$ECOSYSTEM database/postgres/$SERVER/roles
echo " "
echo "A quel role souhaitez-vous vous connecter:"
read ROLE
clear
echo "Connexion a la base en mode dynamique, veuillez patienter..."
var=$(vault read -ns=$VAULT_NAMESPACE/$ECOSYSTEM database/postgres/$SERVER/creds/$ROLE)
username=$(echo "$var" | grep username | awk '{print $2}');
password=$(echo "$var" | grep password | awk '{print $2}');
echo "User is : $username"
echo "Password is : $password"
echo " Tapez entrée pour continuer."
read bidon
export PGPASSWORD=$password;psql -h $SERVER$DOMAIN -p $PORT -U $username -d $DATABASE
;;
0)
./toolbox.sh
echo " Tapez entrée pour continuer."
read bidon
;;
Q)
echo "Merci d'avoir utiliser ce programme."
exit
;;
*)
echo "Merci de renseignez un chiffre entre 0 et 4."
echo " Tapez entrée pour continuer."
read bidon
;;
esac
done
exit
Cloud db
-
Connexions aux db du cloud
-
PostgreSQL in IBM Cloud.
Création d'une base postgresql avec role hvault en mode batch dans le cloud IBM..
-
Deploy new postgreSQL instance dMZR
Deploy new postgreSQL instance dMZR