2023-07-04 16:35:12 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
image=$@
|
|
|
|
|
|
|
|
image_information=$(oras discover --artifact-type application/json "$image")
|
|
|
|
#printf "$image_information\n"
|
|
|
|
printf "Found image $image...\n"
|
|
|
|
|
|
|
|
report_digest=$(echo "$image_information" | tail -n1 | awk -F ' ' '{print $2}')
|
|
|
|
#printf "$report_digest\n"
|
|
|
|
printf "Found digests for scan report...\n"
|
|
|
|
|
2023-07-04 17:18:15 +00:00
|
|
|
extra_vars=""
|
|
|
|
|
2023-07-04 19:43:16 +00:00
|
|
|
if [ ! -z $REGISTRY_USERNAME ]; then
|
|
|
|
printf "Found registry username...\n"
|
2023-07-04 17:18:15 +00:00
|
|
|
extra_vars="$extra_vars --username $REGISTRY_USERNAME"
|
|
|
|
fi
|
|
|
|
|
2023-07-04 19:43:16 +00:00
|
|
|
if [ ! -z REGISTRY_PASSWORD ]; then
|
|
|
|
printf "Found registry password\n"
|
2023-07-04 19:51:49 +00:00
|
|
|
extra_vars="$extra_vars --password $REGISTRY_PASSWORD"
|
2023-07-04 17:18:15 +00:00
|
|
|
fi
|
|
|
|
|
2023-07-04 17:21:12 +00:00
|
|
|
|
2023-07-04 19:43:16 +00:00
|
|
|
printf "Cleaning result file, if it already exists...\n"
|
2023-07-04 17:21:12 +00:00
|
|
|
if [ -e result.json ]; then
|
|
|
|
rm result.json
|
|
|
|
fi
|
2023-07-04 19:43:16 +00:00
|
|
|
|
|
|
|
image_base=$(echo "$image" | awk -F ':' '{print $1}')
|
|
|
|
printf "Pulling $image_base:@$report_digest...\n"
|
2023-07-04 17:21:12 +00:00
|
|
|
oras pull $extra_vars $image_base:@$report_digest
|
|
|
|
|
2023-07-04 19:43:16 +00:00
|
|
|
printf "Checking for result file..."
|
2023-07-04 17:21:12 +00:00
|
|
|
if [ -e result.json ]; then
|
2023-07-04 19:43:16 +00:00
|
|
|
printf "Result file found !"
|
2023-07-04 17:21:12 +00:00
|
|
|
exit 0
|
|
|
|
else
|
2023-07-04 19:43:16 +00:00
|
|
|
printf "Result file not found !"
|
2023-07-04 17:21:12 +00:00
|
|
|
exit 1
|
|
|
|
fi
|