From a136a4e42d302b7c72c50153b0207e4f832f0b48 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Thu, 14 Oct 2021 14:33:23 +0200 Subject: [PATCH] add nanoseconds in hashed base data; add url param -h and -v --- bin/getfile.sh | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/bin/getfile.sh b/bin/getfile.sh index db49400..8960a46 100755 --- a/bin/getfile.sh +++ b/bin/getfile.sh @@ -3,16 +3,23 @@ # # API CLIENT :: GET A CI FILE FROM PACKAGE SERVER # +# Source: https://git-repo.iml.unibe.ch/iml-open-source/imldeployment-client/ # ---------------------------------------------------------------------- # 2021-03-31 v1.0 <axel.hahn@iml.unibe.ch> init # 2021-04-13 v1.1 <axel.hahn@iml.unibe.ch> add support for custom config # 2021-04-15 v1.2 <axel.hahn@iml.unibe.ch> added debugging of curl request +# 2021-10-14 v1.3 <axel.hahn@iml.unibe.ch> add nanoseconds in hashed base data # ====================================================================== # ---------------------------------------------------------------------- # CONFIG # ---------------------------------------------------------------------- +version="v1.3" +about="CI PACKAGE GETTER $version; +(c) 2021 Institute for Medical Education (IML); University of Bern; +GNU GPL 3.0" + line="----------------------------------------------------------------------" bDebug=0 customconfig= @@ -25,8 +32,9 @@ customconfig= function showhelp(){ self=$( basename $0 ) -echo " -CIPGK GETTER +echo "$line +$about +$line Get packages from a software sattelite of IML ci server. @@ -36,6 +44,9 @@ SYNTAX: OPTIONS: + -h Show this help + -v Show version + -c CFGFILE load custom config file after defaults in $self.cfg -d enable debug infos -e PHASE phase; overrides env variable IMLCI_PHASE @@ -45,7 +56,7 @@ OPTIONS: -p PROJECT ci project id; overrides env variable IMLCI_PROJECT -s SECRET override secret in IMLCI_PKG_SECRET -u URL URL of iml ci server without trailing /; overrides env variable IMLCI_URL - + VALUES: CFGFILE custom config file. It is useful to handle files of different @@ -92,7 +103,15 @@ EXAMPLES: " } - +# make an http request to fetch the software +# +# param string method; should be GET +# param string request url (without protocol and server) +# param string optional: filename for output data +# param string optional: secret; default: it will be generated +# +# global int bDebug (0|1) +# global string line string for a line with dashes function makeRequest(){ local apiMethod=$1 @@ -113,7 +132,7 @@ function makeRequest(){ # --- date in http format LANG=en_EN # export TZ=GMT - apiTS=`date "+%a, %d %b %Y %H:%M:%S %Z"` + apiTS=`date "+%a, %d %b %Y %H:%M:%S.%N %Z"` # --- generate data to hash: method + uri + timestamp; delimited with line break @@ -121,6 +140,11 @@ data="${apiMethod} ${apiRequest} ${apiTS} " + # these ase non critical data ... it does not show the ${secret} + if [ "$bDebug" = "1" ]; then + echo "RAW data for hashed secret:" + echo "$data" + fi # generate hash - split in 2 commands (piping "cut" sends additional line break) myHash=`echo -n "$data" | openssl sha1 -hmac "${secret}" | cut -f 2 -d" "` @@ -134,7 +158,7 @@ ${apiTS} curl \ -H "Accept: application/json" -H "Content-Type: application/json" \ -H "Date: ${apiTS}" \ - -H "Authorization: demo-bash-client:${myHash}" \ + -H "Authorization: bash-client:${myHash}" \ -X $apiMethod \ -o "${tmpdownloadfile}" \ $moreheaders \ @@ -186,12 +210,15 @@ if [ $# -lt 1 ]; then fi -while getopts "c:de:f:l:o:p:s:u:" option; do +while getopts "c:de:f:hl:o:p:s:u:v" option; do case ${option} in c) customconfig="$OPTARG" ;; d) bDebug=1 ;; e) export IMLCI_PHASE=$OPTARG ;; f) export IMLCI_FILE=$OPTARG ;; + h) showhelp + exit 0 + ;; l) case $OPTARG in phases) IMLCI_PHASE='' @@ -216,6 +243,7 @@ while getopts "c:de:f:l:o:p:s:u:" option; do p) export IMLCI_PROJECT=$OPTARG ;; s) export IMLCI_PKG_SECRET=$OPTARG ;; u) export IMLCI_URL=$OPTARG ;; + v) echo $about; exit 0 ;; *) echo ERROR: invalid option [${option}] echo -- GitLab