Skip to content

Commit

Permalink
More upgrading to v2.8.x compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisjbell committed Dec 19, 2022
1 parent 88d3f97 commit b7c812b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 61 deletions.
49 changes: 19 additions & 30 deletions hooks/addon
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,24 @@ unset BOSH_CLIENT_SECRET
BOSH_URL="https://$(lookup params.static_ip):25555"
export BOSH_URL

# the bosh() helper that Genesis gives us is opinionated;
# great for things that are wanting to deal with the _parent_
# BOSH director, but wholly useless for this kit.
#
# let's override it, shall we?
#
# While post-genesis-v2.8.6 it is recommended that the `genesis bosh` command
# is used, there are some addons than need a bosh that uses alias instead of
# environment variables to authenticate. To this end, we need to override the
# bosh() helper that Genesis gives us so that we can use it in is raw form.
# Lets store the original genesis bosh in genesis_bosh and override it with
# what we need
test -n "$(declare -f "bosh")" || return
eval "${_/bosh/genesis_bosh}"
bosh() {
[[ -n "${GENESIS_SHOW_BOSH_CMD:-}" ]] && \
describe >&2 "#M{BOSH>} $GENESIS_BOSH_COMMAND $*"
command "$GENESIS_BOSH_COMMAND" "$@"
}
export -f bosh

target_bosh() {
BOSH_ENVIRONMENT="$BOSH_URL"
BOSH_CA_CERT=$(safe read "${GENESIS_SECRETS_BASE}ssl/ca:certificate")
BOSH_CLIENT="admin"
BOSH_CLIENT_SECRET="$(safe read "${GENESIS_SECRETS_BASE}users/admin:password")"
export BOSH_ENVIRONMENT BOSH_CA_CERT BOSH_CLIENT BOSH_CLIENT_SECRET
}
export -f target_bosh
export -f genesis_bosh

setup_alias() {
(
target_bosh
bosh alias-env --tty "$GENESIS_ENVIRONMENT"| grep -v '^User'
)
genesis_bosh -A alias-env --tty "$GENESIS_ENVIRONMENT"| grep -v '^User'
}

has_alias() {
Expand All @@ -66,35 +57,31 @@ login() {
bosh -e "$GENESIS_ENVIRONMENT" login
}

list() {
case $GENESIS_ADDON_SCRIPT in
(list)
print_addon_descriptions \
"alias" "Set up a local bosh alias for a director" \
"login" "Log into an (aliased) director" \
"logout" "Log out of an (aliased) director"
}

case $GENESIS_ADDON_SCRIPT in
list)
list
exit 0
;;

alias)
(alias)
setup_alias
;;

login)
(login)
has_alias || setup_alias >/dev/null
login
;;

logout)
(logout)
has_alias || setup_alias >/dev/null
bosh -e "$GENESIS_ENVIRONMENT" logout
;;


ssh) # DO NOT LIST THIS IN 'list'...
(ssh) # DO NOT LIST THIS IN 'list'...
echo ; describe "#G{Accessing $GENESIS_ENVIRONMENT BOSH director via SSH...}" ; echo

touch .key
Expand All @@ -108,5 +95,7 @@ ssh) # DO NOT LIST THIS IN 'list'...
exec ssh "netop@$ip" -o StrictHostKeyChecking=no -i .key
;;

*) run_extended_addon;;
(*)
run_extended_addon
;;
esac
5 changes: 2 additions & 3 deletions hooks/addon-resurrection
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ if [[ -n "${1:-}" ]] ; then
*)
bail "" "#R{[ERROR]} Expecting one of the following argements: on (aka: yes|true|enabled|1) or off (aka: no|false|disabled|0)"
esac
target_bosh
bosh update-resurrection "$state"
genesis_bosh -A update-resurrection "$state"
echo ""
exit 0
fi
Expand All @@ -62,7 +61,7 @@ elif [[ "${GENESIS_USE_CREATE_ENV:=0}" == '1' ]] ; then

else
# Do it the slow way...
ssh_cmd=( "${GENESIS_CALLBACK_BIN}" "-C" "${GENESIS_ROOT}" "bosh" "${GENESIS_ENVIRONMENT}" "ssh" "-c" )
ssh_cmd=( "${GENESIS_CALL_BIN}" "${GENESIS_ENV_REF}" "bosh" "-A" "ssh" "-c" )
fi

describe "Connecting to PostgreSQL database on BOSH director..."
Expand Down
22 changes: 5 additions & 17 deletions hooks/addon-runtime-config~rc
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,26 @@ params_dns_cache="$(lookup params.dns_cache 'true')"
exodus="$(exodus --all)"
IFS=',' read -ra features <<< "$(echo "$exodus" | jq -r .features)"

target_bosh_from_exodus() {
local exodus
exodus="${1:?"${FUNCNAME[0]} called without specifying exodus data"}"
BOSH_ENVIRONMENT="$(jq -r '.url' <<<"$exodus")"
BOSH_CA_CERT="$(jq -r '.ca_cert' <<<"$exodus")"
BOSH_CLIENT="$(jq -r '.admin_username' <<<"$exodus")"
BOSH_CLIENT_SECRET="$(jq -r '.admin_password' <<<"$exodus")"
export BOSH_ENVIRONMENT BOSH_CA_CERT BOSH_CLIENT BOSH_CLIENT_SECRET
}

upload_runtime_config() {
name="${1:-default}"
contents="$2"
target_bosh_from_exodus "$exodus"
bosh update-runtime-config --tty --name="${name}" <(echo "$contents")
genesis_bosh -A update-runtime-config --tty --name="${name}" <(echo "$contents")

}
remove_runtime_config() {
name="${1:-default}"
target_bosh_from_exodus "$exodus"
if [[ -n "$(bosh configs --type=runtime --name="$name")" ]] ; then
if [[ -n "$(genesis_bosh -A configs --type=runtime --name="$name")" ]] ; then
describe >&2 "" "Removing existing '$name' runtime:" "- ---"
get_runtime_config "$name" 2>&1 | sed -e 's/\(.*\)/- \1/' >&2
echo >&2 ''
bosh delete-config --type=runtime --name="$name"
genesis_bosh -A delete-config --type=runtime --name="$name"
fi
}

get_runtime_config() {
name="${1:-default}"
(set +e
target_bosh_from_exodus "$exodus"
bosh config --type=runtime --name="$name" ) \
genesis_bosh -A config --type=runtime --name="$name" ) \
| tail -n+5 | sed -e 's/\s\+$//' | spruce merge
}

Expand Down
6 changes: 1 addition & 5 deletions hooks/lib-addon-stemcells.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ __stemcell_upload() {
[[ "${#@}" -gt 1 ]] && bosh_args+=("--sha1" "$2")
bosh_args+=("$url")
describe "Starting upload:"
BOSH_ENVIRONMENT=$BOSH_URL \
BOSH_CA_CERT=$(safe read "${GENESIS_SECRETS_BASE}ssl/ca:certificate") \
BOSH_CLIENT="admin" \
BOSH_CLIENT_SECRET="$(safe read "${GENESIS_SECRETS_BASE}users/admin:password")" \
bosh "${bosh_args[@]}"
genesis_bosh -A "${bosh_args[@]}"
return $?
}

Expand Down
12 changes: 6 additions & 6 deletions hooks/post-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@ if [[ $GENESIS_DEPLOY_RC == 0 ]]; then
"" \
"For details about the deployment, run" \
"" \
" #G{$GENESIS_CALL info $GENESIS_ENVIRONMENT}" \
" #G{$GENESIS_CALL_ENV info}" \
"" \
"To set up a named alias for this director, run" \
"" \
" #G{$GENESIS_CALL do $GENESIS_ENVIRONMENT -- alias}" \
" #G{$GENESIS_CALL_ENV do -- alias}" \
"" \
"To log into the BOSH director, as the admin user, run" \
"" \
" #G{$GENESIS_CALL do $GENESIS_ENVIRONMENT -- login}" \
" #G{$GENESIS_CALL_ENV do -- login}" \
"" \
"If this is a new BOSH director, you can upload" \
"stemcells by running" \
"" \
" #G{$GENESIS_CALL do $GENESIS_ENVIRONMENT -- upload-stemcells}" \
" #G{$GENESIS_CALL_ENV do -- upload-stemcells}" \
"" \
"This BOSH director provides a Credhub secrets store." \
"You can log into it by running" \
"" \
" #G{$GENESIS_CALL do $GENESIS_ENVIRONMENT -- credhub-login}" \
" #G{$GENESIS_CALL_ENV do -- credhub-login}" \
""

if want_feature vault-credhub-proxy ; then
describe "It also provides a vault-credhub-proxy server, which" \
"allows you to access credhub via #C{safe}. To login, run" \
"" \
" #G{$GENESIS_CALL do $GENESIS_ENVIRONMENT -- vault-proxy-login}" \
" #G{$GENESIS_CALL_ENV do -- vault-proxy-login}" \
""
fi

Expand Down

0 comments on commit b7c812b

Please sign in to comment.