Implement getopts in download_validation_reports.sh for argument parsing.

This commit is contained in:
chubtub 2021-05-04 13:46:09 -04:00
parent 1d33054577
commit 313d274524

View File

@ -5,12 +5,77 @@
#$2 filter end date 'yyyy-mm-dd' #$2 filter end date 'yyyy-mm-dd'
#$3 ACA address, default is localhost if not given #$3 ACA address, default is localhost if not given
if [ -z "$3" ] #check for getopt(1) on local system
getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]
then then
endpoint="https://localhost:8443/HIRS_AttestationCAPortal/portal/validation-reports" echo "getopt is required to use this script, please ensure installation!"
else else
endpoint="https://$3:8443/HIRS_AttestationCAPortal/portal/validation-reports" echo "getopt detected"
fi fi
#set parameter names and call getopts on inputsi, then parse/assign arguments
SHORTOPTS=m:s:
LONGOPTS=start-date:,end-date:,ip:,system-only,component-only,manufacturer:,serial:
PARSED=$(getopt --options=$SHORTOPTS --longoptions=$LONGOPTS --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]
then
exit 2
fi
eval set -- "$PARSED"
startDate=
endDate=
ip=localhost
system=
component=
manufacturer=
serial=
while true
do
case "$1" in
--start-date)
startDate="$2"
shift 2
;;
--end-date)
endDate="$2"
shift 2
;;
--ip)
ip="$2"
shift 2
;;
--system-only)
system=true
shift
;;
--component-only)
component=true
shift
;;
-m|--manufacturer)
manufacturer="$2"
shift 2
;;
-s|--serial)
serial="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
echo "start date: $startDate, end date: $endDate, ip: $ip, system: $system, component: $component, manufacturer: $manufacturer, serial: $serial"
#call ACA for validation report
endpoint="https://$ip:8443/HIRS_AttestationCAPortal/portal/validation-reports"
echo "$endpoint" echo "$endpoint"
content=$(curl --insecure $endpoint/list) content=$(curl --insecure $endpoint/list)
rawTimes=$(jq -r '.data | map(.createTime | tostring) | join(",")' <<< "$content") rawTimes=$(jq -r '.data | map(.createTime | tostring) | join(",")' <<< "$content")
@ -22,5 +87,4 @@ done
deviceNames=$(jq -r '.data | map(.device.name) | join(",")' <<< "$content") deviceNames=$(jq -r '.data | map(.device.name) | join(",")' <<< "$content")
echo "Create times: $createTimes" echo "Create times: $createTimes"
echo "Device names: $deviceNames" echo "Device names: $deviceNames"
curl --data "dateStart=$1&dateEnd=$2&createTimes=$createTimes&deviceNames=$deviceNames" --insecure $endpoint/download curl --data "dateStart=$startDate&dateEnd=$endDate&createTimes=$createTimes&deviceNames=$deviceNames&system=$system&component=$component&manufacturer=$manufacturer&serial=$serial" --insecure $endpoint/download