Added support for Teleport to gs-login

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2024-01-18 09:08:17 +00:00
parent 4bd7292f23
commit 625aa58ce9
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78

View File

@ -62,6 +62,16 @@ case ${#POS_ARGS[@]} in
;; ;;
*) *)
kubectl config delete-context gs-${POS_ARGS[0]} &>/dev/null kubectl config delete-context gs-${POS_ARGS[0]} &>/dev/null
TELEPORT_CLUSTER_NAME="$(echo "${POS_ARGS[@]}" | tr ' ' '-')"
TELEPORT_SUPPORTED=$(tsh kube ls -f json --query "name == \"${TELEPORT_CLUSTER_NAME}\"" 2>/dev/null | jq '. | length')
if [ ${TELEPORT_SUPPORTED} -eq 0 ]; then
# Teleport not supported, old style login
echo "Cluster isn't know to Teleport, using old login method"
opsctl login ${DEBUG} ${POS_ARGS[@]} opsctl login ${DEBUG} ${POS_ARGS[@]}
else
echo "Logging in with Teleport. Cluster: '${TELEPORT_CLUSTER_NAME}'"
tsh kube login ${TELEPORT_CLUSTER_NAME}
fi
;; ;;
esac esac