Better config handling
This commit is contained in:
parent
d4393db6b2
commit
28edbbc425
45
ctctl
45
ctctl
|
@ -34,6 +34,26 @@ enter_ct(){
|
|||
done
|
||||
}
|
||||
|
||||
|
||||
load_config(){
|
||||
if [ -n "${CTCTL_DOMAIN}" -a -n "${CTCTL_ENV}" ]; then
|
||||
# Load env configuration
|
||||
if [ -e ~/.ctctl/${TARGET_DOM}/${CTCTL_ENV}.conf ]; then
|
||||
set -o allexport
|
||||
source ~/.ctctl/${TARGET_DOM}/${CTCTL_ENV}.conf
|
||||
set +o allexport
|
||||
fi
|
||||
|
||||
# Load post login configuration
|
||||
if [ -e ~/.ctctl/${CTCTL_DOMAIN}/ctctl.local.conf ]; then
|
||||
set -o allexport
|
||||
source ~/.ctctl/${CTCTL_DOMAIN}/ctctl.local.conf
|
||||
set +o allexport
|
||||
fi
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
# Switch to a target environment (either from no current, or from another current env)
|
||||
switch_env(){
|
||||
TARGET_DOM=$1
|
||||
|
@ -65,7 +85,7 @@ switch_env(){
|
|||
|
||||
export CTCTL_DOMAIN=${TARGET_DOM}
|
||||
|
||||
# Load pre login env configuration
|
||||
# Load default config
|
||||
set -o allexport
|
||||
source ~/.ctctl/${CTCTL_DOMAIN}/ctctl.conf
|
||||
set +o allexport
|
||||
|
@ -90,13 +110,6 @@ switch_env(){
|
|||
fi
|
||||
export CTCTL_ENV=${TARGET_ENV}
|
||||
|
||||
# Load env configuration
|
||||
if [ -e ~/.ctctl/${TARGET_DOM}/${CTCTL_ENV}.conf ]; then
|
||||
set -o allexport
|
||||
source ~/.ctctl/${TARGET_DOM}/${CTCTL_ENV}.conf
|
||||
set +o allexport
|
||||
fi
|
||||
|
||||
# Load pre login env configuration
|
||||
if [ -e ~/.ctctl/${CTCTL_DOMAIN}/pre-login.conf ]; then
|
||||
set -o allexport
|
||||
|
@ -126,13 +139,8 @@ switch_env(){
|
|||
esac
|
||||
|
||||
auth_env
|
||||
load_config
|
||||
|
||||
# Load post login configuration
|
||||
if [ -e ~/.ctctl/${CTCTL_DOMAIN}/ctctl.local.conf ]; then
|
||||
set -o allexport
|
||||
source ~/.ctctl/${CTCTL_DOMAIN}/ctctl.local.conf
|
||||
set +o allexport
|
||||
fi
|
||||
export PS1="[${CTCTL_DOMAIN} \[\e[${COLOR}m\](${CTCTL_ENV})\[\e[m\] \W]\$ "
|
||||
}
|
||||
|
||||
|
@ -346,9 +354,9 @@ load_consul_conf(){
|
|||
|
||||
# Support storing consul config in subdir eg consul/config/service-defaults/foo.hcl
|
||||
# Or you can even omit service and use consul/config/defaults/bar.hcl, consul/config/intentions/bar.hcl
|
||||
for KIND in service-defaults defaults service intentions intentions service-router router service-resolver resolver; do
|
||||
if [ -d ./consul/config/{$KIND} ]; then
|
||||
for FILE in $(ls ./consul/config/{$KIND}/*.hcl 2>/dev/null); do
|
||||
for KIND in service-defaults defaults service-intentions intentions service-router router service-resolver resolver; do
|
||||
if [ -d ./consul/config/${KIND} ]; then
|
||||
for FILE in $(ls ./consul/config/${KIND}/*.hcl 2>/dev/null); do
|
||||
echo "Loading consul conf from ${FILE}"
|
||||
TEMP=$(mktemp)
|
||||
replace_conf_var ${FILE} > ${TEMP}
|
||||
|
@ -545,6 +553,9 @@ get_job_list(){
|
|||
echo $JOBS
|
||||
}
|
||||
|
||||
# Load configuration
|
||||
load_config
|
||||
|
||||
case $1 in
|
||||
current)
|
||||
current_env
|
||||
|
|
Loading…
Reference in New Issue