Created
August 17, 2022 08:29
-
-
Save OleksandrKucherenko/95bc19b9ee32af9f3c82ac1845c1dfe7 to your computer and use it in GitHub Desktop.
Sample script that demonstrate usage of the Logger feature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#set -x # Uncomment to DEBUG | |
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
source "$SCRIPT_DIR/logger.sh" | |
logger token "$@" # controlled by DEBUG=token,* | |
logger refresh "$@" # controlled by DEBUG=refresh,* | |
# terminal colors and utility functions, like: cl_grey, cl_reset | |
source "$SCRIPT_DIR/common.sh" | |
token_file=.secrets/tokenfile.json | |
token=$(cat "$token_file") | |
# extract JWT | |
access_token=$(echo "${token}" | jq -r '.access_token') | |
# sample 1 | |
if [[ "$access_token" == "null" ]]; then | |
echo "Error. No access token found in provided JSON." | |
echoToken "${cl_grey}| STDOUT & STDERR:${cl_reset}" >&2 | |
echoToken "${cl_grey}| ${token}${cl_reset}" | |
exit 1 | |
fi | |
# sample 2 | |
echo "[--] Processing file: ${cl_yellow}$token_file${cl_reset}" | |
json=$(cat $token_file) | |
echoRefresh "${cl_grey}| FILE CONTENT (trimmed):${cl_reset}" >&2 | |
echo "${json}" | while read -r line; do echoRefresh "${cl_grey}| ${cl_reset}${line}" >&2; done |
Author
OleksandrKucherenko
commented
Aug 17, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment