From 4e394eb5b667010f8cf9642c99543d830523bfbf Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 30 May 2024 16:50:21 +0200 Subject: [PATCH] Checking age of access token in scripts/get-rhel-dvd-iso-image --- scripts/get-rhel-dvd-iso-image | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/scripts/get-rhel-dvd-iso-image b/scripts/get-rhel-dvd-iso-image index 172b9fe..95c486e 100755 --- a/scripts/get-rhel-dvd-iso-image +++ b/scripts/get-rhel-dvd-iso-image @@ -37,6 +37,10 @@ OFFLINE_TOKEN=$( cat <<-EOF OFFLINE_TOKEN=$( echo "${OFFLINE_TOKEN}" | tr -d '[:space:]' ) +DATE_LAST_TOKEN='2024-05-30 10:00:00+02:00' +MAX_DAYS_LAST_TOKEN="29" +RED_HAT_DOWNLOAD_USER="dpx-downloader" + declare -A IMAGE_CHECKSUMS=() IMAGE_CHECKSUMS['rhel-7.9-dvd']='2cb36122a74be084c551bc7173d2d38a1cfb75c8ffbc1489c630c916d1b31b25' @@ -199,6 +203,42 @@ get_options() { } +#------------------------------------------------------------------------------ +check_token_age() { + + empty_line + debug "Checking age of access token ..." + + local last_token_ts= + local current_ts= + local cur_time_diff= + local max_time_diff= + + last_token_ts=$( date -d "${DATE_LAST_TOKEN}" +'%s' ) + current_ts=$( date +'%s' ) + cur_time_diff=$(( current_ts - last_token_ts )) + max_time_diff=$(( MAX_DAYS_LAST_TOKEN * 24 * 60 * 60 )) + + debug "The date of getting the access token is ${CYAN}${cur_time_diff} seconds ago${NORMAL}." + + if [[ "${cur_time_diff}" -gt "${max_time_diff}" ]] ; then + local msg="The current ${RED}access token is too old${NORMAL} - " + msg+="it is from ${CYAN}${DATE_LAST_TOKEN}${NORMAL}. " + msg+="It may be at most ${CYAN}${MAX_DAYS_LAST_TOKEN} days${NORMAL} old." + error "${msg}" + + empty_line + msg="Please log in at Red Hat Customer portal as '${CYAN}${RED_HAT_DOWNLOAD_USER}${NORMAL}', " + msg+="get a new access token and update the token and the date of the last change in this script." + error "${msg}" + empty_line + + exit 6 + fi + +} + + #------------------------------------------------------------------------------ get_access_token() { @@ -287,6 +327,7 @@ main() { get_options "$@" set_locale "en_US.utf8" + check_token_age get_access_token get_image_info download_image -- 2.39.5