2021-11-29 08:07:17 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-03-11 18:38:32 +00:00
|
|
|
source .utils
|
|
|
|
|
2021-12-07 10:08:44 +00:00
|
|
|
DEBUG=""
|
2021-11-29 08:07:17 +00:00
|
|
|
|
|
|
|
print_usage() {
|
2022-03-11 18:38:32 +00:00
|
|
|
orange "gs-login - login to Giant Swarm managed clusters"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo " "
|
2022-03-11 18:38:32 +00:00
|
|
|
underline "Usage:"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "gs-login [INSTALLATION] [WORKLOAD CLUSTER] [ORGANISATION]"
|
|
|
|
echo " "
|
2022-03-11 18:38:32 +00:00
|
|
|
underline "Examples:"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "> gs-login gauss"
|
|
|
|
echo "> gs-login gauss mywc1"
|
|
|
|
echo " "
|
2022-03-11 18:38:32 +00:00
|
|
|
underline "Options:"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "-h, --help show this help text"
|
|
|
|
}
|
|
|
|
|
2021-12-07 10:08:44 +00:00
|
|
|
POS_ARGS=()
|
|
|
|
|
2021-11-29 08:07:17 +00:00
|
|
|
while test $# -gt 0; do
|
|
|
|
case "$1" in
|
|
|
|
-t|--ttl)
|
|
|
|
shift
|
2022-02-22 10:16:24 +00:00
|
|
|
echo "-t / --ttl no longer handled"
|
2021-11-29 08:07:17 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-g|--certificate-group)
|
|
|
|
shift
|
2022-02-22 10:16:24 +00:00
|
|
|
echo "-g / --certificate-group no longer handled"
|
2021-11-29 08:07:17 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2021-12-07 10:08:44 +00:00
|
|
|
--debug)
|
2022-02-22 10:16:24 +00:00
|
|
|
DEBUG="--level=debug"
|
2021-12-07 10:08:44 +00:00
|
|
|
shift
|
2021-12-07 12:44:20 +00:00
|
|
|
;;
|
2021-12-07 10:08:44 +00:00
|
|
|
/)
|
|
|
|
# We want to ignore slash seperators between MC and WC
|
|
|
|
shift
|
|
|
|
;;
|
2021-11-29 08:07:17 +00:00
|
|
|
*)
|
2021-12-07 10:08:44 +00:00
|
|
|
POS_ARGS+=(`echo $1 | tr '/' ' '`)
|
|
|
|
shift
|
2021-11-29 08:07:17 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-12-14 08:07:58 +00:00
|
|
|
if [ ${#POS_ARGS[@]} -eq 0 ]; then
|
|
|
|
POS_ARGS+=(`opsctl list installations --short | tr ' ' '\n' | fzf`)
|
|
|
|
fi
|
|
|
|
|
2021-12-07 10:08:44 +00:00
|
|
|
case ${#POS_ARGS[@]} in
|
2022-02-22 10:16:24 +00:00
|
|
|
0)
|
2021-11-29 08:07:17 +00:00
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
;;
|
2022-02-22 10:16:24 +00:00
|
|
|
*)
|
2022-03-01 11:49:13 +00:00
|
|
|
kubectl config delete-context gs-${POS_ARGS[0]} &>/dev/null
|
2022-02-22 10:16:24 +00:00
|
|
|
opsctl login ${DEBUG} ${POS_ARGS[@]}
|
|
|
|
;;
|
2021-11-29 08:07:17 +00:00
|
|
|
esac
|