-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudgovrc.in
108 lines (97 loc) · 2.83 KB
/
cloudgovrc.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
export scripts_dir="$HOME/Projects/cloud-gov/cg-scripts"
alias jump-prod="pushd $scripts_dir; ./jumpbox cloud.gov production; popd"
alias jump-dev="pushd $scripts_dir; ./jumpbox cloud.gov development; popd"
for e in staging tooling master westb westc easta eastb master-west master-east tooling-west tooling-east
do
alias jump-$e="pushd $scripts_dir; ./jumpbox cloud.gov $e; popd"
done
function cf_target {
local cf_config
local cf_api
local cf_org
local cf_space
local cf_home
cf_home="default"
if [ -z "$CF_HOME" ]; then
cf_config=${HOME}/.cf/config.json
else
cf_config="${CF_HOME}/.cf/config.json"
cf_home="$(basename $CF_HOME)"
fi
cf_api=$(cat ${cf_config} | jq -r .Target| grep -v null | sed 's_https://__')
cf_org=$(cat ${cf_config} | jq -r .OrganizationFields.Name)
cf_space=$(cat ${cf_config} | jq -r .SpaceFields.Name)
printf "\e[36m${cf_org}/${cf_space} (${cf_home})\e[0m"
}
function cf_go_fail() {
echo $@
return -1
}
CF_GO_HOME=$HOME/.cf_go
CGAPI=https://api.fr.cloud.gov
function cf_go_create() {
local cf_env
local cf_go_env
cf_env=$1
echo "Creating cf_go env $1 with current target"
cf_go_env="$HOME/.cf_go/$cf_env"
[ -d $cf_go_env ] && cf_go_fail "Env directory, $cf_go_env, already exists"
mkdir -p $cf_go_env
chmod 700 $cf_go_env
export CF_HOME=$cf_go_env/
cf api $CGAPI
cf login --sso
}
function cf_go() {
local OPTIND opt
while getopts "c:d:l" opt; do
case $opt in
c) echo "-c CREATE with value $OPTARG"
cf_go_create $OPTARG
export PS1="[\u@\h $(cf_target) \W]\n > "
return
;;
d) echo "-d DELETE with value $OPTARG"
/bin/rm -rf $CF_GO_HOME/$OPTARG
unset CF_HOME
export PS1="[\u@\h $(cf_target) \W]\n > "
return
;;
l) printf "$O envs: "
/bin/ls $CF_GO_HOME
return
;;
?) echo "USAGE: cf_go [-d|-c env] (-l) env"
echo " env # Switch to existing env"
echo " -c env # Create env"
echo " -d env # Delete env"
echo " -l # List envs"
return
;;
esac
done
shift $((OPTIND-1))
echo "cf switch $1"
if [ "$1" = "default" ]; then
unset CF_HOME
else
export CF_HOME=$CF_GO_HOME/$1
fi
export PS1="[\u@\h $(cf_target) \W]\n > "
}
function cf_gox() {
target=$1
case $target in
fr|fr-stage)
export CF_HOME="$HOME/.cfall/$target"
[ -d $CF_HOME ] || mkdir -p $CF_HOME
chmod 700 $CF_HOME
cf target || cf login -a api.$target.cloud.gov --sso
;;
*)
echo Whoops, expected 'cf_go (fr|fr-stage)'
return 1
;;
esac
}
starship_precmd_user_func="cf_target"