]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Checking age of access token in scripts/get-rhel-dvd-iso-image
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 30 May 2024 14:50:21 +0000 (16:50 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 30 May 2024 14:50:21 +0000 (16:50 +0200)
scripts/get-rhel-dvd-iso-image

index 172b9fe900665495aa3a6e4e4b7ba5b4f7312bfc..95c486e9d9f6366678000914b7f4f47718e84714 100755 (executable)
@@ -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