2021-03-04 19:55:51 +00:00
#!/bin/bash
#User input parameters:
#$1 filter start date 'yyyy-mm-dd'
#$2 filter end date 'yyyy-mm-dd'
2021-03-16 14:16:17 +00:00
#$3 ACA address, default is localhost if not given
2021-03-04 19:55:51 +00:00
2021-05-04 17:46:09 +00:00
#check for getopt(1) on local system
getopt --test > /dev/null
if [ [ ${ PIPESTATUS [0] } -ne 4 ] ]
then
echo "getopt is required to use this script, please ensure installation!"
else
echo "getopt detected"
2021-03-16 14:16:17 +00:00
fi
2021-05-04 17:46:09 +00:00
#set parameter names and call getopts on inputsi, then parse/assign arguments
2021-05-10 17:53:18 +00:00
SHORTOPTS = m:s:h
LONGOPTS = start-date:,end-date:,ip:,system-only,component-only,manufacturer:,serial:,help
2021-05-04 17:46:09 +00:00
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 =
2021-05-10 17:53:18 +00:00
helpText = "\n\n\nHELP MENU\n\nThe following options are available:\n--start-date\t\t<yyyy-mm-dd>\tDefault: 1970-01-01\tThe earliest date to return validation reports from.\n"
helpText += "--end-date\t\t<yyyy-mm-dd>\tDefault: current time\tThe latest date to return validation reports from.\n"
helpText += "--ip\t\t\t<ACA address>\tDefault: localhost\tThe IP address where the ACA is located.\n"
helpText += "--system-only\t\t\t\t\t\t\tReturn only system information from validation reports.\n"
helpText += "--component-only\t\t\t\t\t\tReturn only component information from validation reports.\n"
helpText += "-m|--manufacturer\t<manufacturer's name>\t\t\tReturn only the validation report of the device from this manufacturer.\n"
helpText += "-s|--serial\t\t<serial number>\t\t\t\tReturn only the validation report of the device with this serial number.\n"
2021-05-04 17:46:09 +00:00
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
; ;
2021-05-10 17:53:18 +00:00
-h| --help)
printf " $helpText "
exit 0
; ;
2021-05-04 17:46:09 +00:00
--)
shift
break
; ;
*)
echo "Programming error"
exit 3
; ;
esac
done
2021-05-11 17:06:21 +00:00
#echo "start date: $startDate, end date: $endDate, ip: $ip, system: $system, component: $component, manufacturer: $manufacturer, serial: $serial"
2021-05-04 17:46:09 +00:00
#call ACA for validation report
endpoint = " https:// $ip :8443/HIRS_AttestationCAPortal/portal/validation-reports "
2021-03-16 14:16:17 +00:00
echo " $endpoint "
2021-03-04 19:55:51 +00:00
content = $( curl --insecure $endpoint /list)
2021-05-10 17:53:18 +00:00
#Parse JSON response for create times and device names
2021-03-04 19:55:51 +00:00
rawTimes = $( jq -r '.data | map(.createTime | tostring) | join(",")' <<< " $content " )
createTimes = ""
for i in ${ rawTimes //,/ }
do
createTimes += " $( date -u +"%Y-%m-%d %H:%M:%S" -d @" $(( $i / 1000 )) " ) , "
done
deviceNames = $( jq -r '.data | map(.device.name) | join(",")' <<< " $content " )
2021-05-10 17:53:18 +00:00
2021-03-04 19:55:51 +00:00
echo " Create times: $createTimes "
echo " Device names: $deviceNames "
2021-05-04 17:46:09 +00:00
curl --data " dateStart= $startDate &dateEnd= $endDate &createTimes= $createTimes &deviceNames= $deviceNames &system= $system &component= $component &manufacturer= $manufacturer &serial= $serial " --insecure $endpoint /download