Created
June 27, 2019 06:55
-
-
Save chmouel/d7c097dd2ffe7a1b4fa4d9e30da02cc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_odo () { | |
local target url username password logged admin t i addusername colortarget=green | |
export EXTRA_PROMPT="" | |
if [[ $1 == "-n" ]] | |
then | |
addusername=yes | |
shift | |
fi | |
if [[ $1 == "-k" ]] | |
then | |
minikube=yes | |
shift | |
fi | |
if [[ $1 == "-a" ]] | |
then | |
admin=t | |
colortarget="red" | |
shift | |
fi | |
target=$1 | |
url=$2 | |
username=$3 | |
password=$4 | |
export KUBECONFIG=${HOME}/.kube/config.${target} | |
if [[ -e ${KUBECONFIG} ]] | |
then | |
token=$(kubectl config view --minify --output 'jsonpath={..token}') | |
if [[ -n ${minikube} ]] | |
then | |
command minikube status | grep -q "host: Running" || echo "Server is not running" && { | |
logged=1 | |
kube=1 | |
} | |
else | |
whoami=$(=oc whoami) | |
fi | |
if [[ -z ${token} && $whoami == "system:admin" ]] | |
then | |
logged=1 | |
fi | |
if [[ -z ${logged} ]] | |
then | |
print -P "%B%F{green}>>>%F{normal} OpenShift: Connecting to ${target} as ${username}" | |
curl -k -s -f -XGET -H "Accept: application/json, */*" -H "Authorization: Bearer ${token}" $(=oc whoami --show-server=true)/oapi/v1/users/~ -o/dev/null && logged=1 | |
fi | |
fi | |
if [[ -z ${logged} && -z ${url} ]] | |
then | |
echo "Cannot log you into ${target}" | |
echo "you need to find other means to connect first" | |
echo "make sure you've set first before you loging the right KUBECONFIG" | |
echo "export KUBECONFIG=${KUBECONFIG}" | |
return | |
fi | |
if [[ -z ${logged} ]] | |
then | |
[[ ${username} == *@redhat.com && -z ${password} ]] && password=$(security find-generic-password -a ${USER} -s "RedHatPass" -w) | |
if [[ -n ${username} && -n ${password} ]] | |
then | |
=oc login -u ${username} -p ${password} ${url} | |
else | |
open ${url} | |
fi | |
fi | |
if [[ -n ${admin} ]] | |
then | |
if [[ -n ${ZSH_VERSION} ]] | |
then | |
autoload -U promptinit | |
promptinit | |
prompt adam1 red | |
fi | |
echo -e "\033]6;1;bg;red;brightness;270\a" | |
echo -e "\033]6;1;bg;green;brightness;60\a" | |
echo -e "\033]6;1;bg;blue;brightness;83\a" | |
echo -ne "\033]0;"*WARNING ${profile:u}*"\007" | |
echo -e "\033]Pg4040ff\033\\" | |
echo -e "\033]Pgff4040\033\\" | |
clear | |
echo "**** YOU ARE ENTERING IN THE WONDERFUL WORLD OF PRODUCTION ***" | |
echo "**** something about responsibility, power and blah blah ***" | |
echo | |
sleep 1 | |
fi | |
title "OpenShift: ${target}" | |
if [[ -n $OSIO_PROJECT ]] | |
then | |
export T=${OSIO_PROJECT} | |
alias opj="oc project $T-jenkins" | |
alias ops="oc project $T-stage" | |
alias op="oc project $T" | |
alias ocpj="oc get pod -owide -n $T-jenkins" | |
alias ocb="oc get bc -owide -n $T" | |
fi | |
if [[ -z ${kube} ]] | |
then | |
export OPENSHIFT_PROJECT=1 | |
[[ -n ${addusername} ]] && EXTRA_PROMPT="${$(oc whoami)//*:/}@" | |
fi | |
EXTRA_PROMPT+="${target}" | |
ocompletion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment