#!/bin/bash if [ "$1" == "--show-password" ]; then HSADMINNG_JWT_SHOW_PASSWORD=yes shift else HSADMINNG_JWT_SHOW_PASSWORD= fi if [ "$1" == "--trace" ]; then function trace() { echo "$*" >&2 } function doCurl() { set -x if [ -z "$HSADMINNG_JWT_ASSUME" ]; then curl --fail-with-body \ --header "Authorization: Bearer $HSADMINNG_JWT_TOKEN" \ "$@" else curl --fail-with-body \ --header "Authorization: Bearer $HSADMINNG_JWT_TOKEN" \ --header "assumed-roles: $HSADMINNG_JWT_ASSUME" \ "$@" fi set +x echo } shift else function trace() { : # noop } function doCurl() { if [ -z "$HSADMINNG_JWT_ASSUME" ]; then curl --fail-with-body --header "Authorization: Bearer $HSADMINNG_JWT_TOKEN" "$@" else curl --fail-with-body \ --header "Authorization: Bearer $HSADMINNG_JWT_TOKEN" \ --header "assumed-roles: $HSADMINNG_JWT_ASSUME" \ "$@" echo fi } fi export HSADMINNG_JWT_ASSUME_HEADER if [ -f ~/.cas-curl-assume ]; then HSADMINNG_JWT_ASSUME="$(cat ~/.cas-curl-assume)" else HSADMINNG_JWT_ASSUME= fi if [ -z "$HSADMINNG_JWT_TOKEN_URL" ]; then cat >&2 <> EOF exit 1 fi function jwtCurlDocumentation() { cat <> [parameters] commands: EOF # filters out help texts (containing double-# and following lines with leading single-#) from the commands itself # (the '' makes sure that this line is not found, just the lines with actual help texts) sed -n '/#''#/ {x; p; x; s/#''#//; p; :a; n; /^[[:space:]]*#/!b; s/^[[:space:]]*#//; p; ba}' <$0 } function jwtLogin() { # JWT token exists and not expired? if [ -f ~/.jwt-token ]; then # Check if token is still valid (simple expiry check - you might want to add JWT parsing for more precise validation) if find ~/.jwt-token -type f -size +0c -mmin -55 2>/dev/null | grep -q .; then HSADMINNG_JWT_TOKEN=$(<~/.jwt-token) return fi fi if [ -z "$HSADMINNG_JWT_USERNAME" ]; then read -e -p "Username: " HSADMINNG_JWT_USERNAME fi if [ -z "$HSADMINNG_JWT_PASSWORD" ]; then read -s -e -p "Password: " HSADMINNG_JWT_PASSWORD fi if [ "$HSADMINNG_JWT_SHOW_PASSWORD" == "yes" ]; then HSADMINNG_JWT_PASSWORD_DISPLAY=$HSADMINNG_JWT_PASSWORD else HSADMINNG_JWT_PASSWORD_DISPLAY="<