constellation/hack/find-image/find-image.sh
Malte Poll 4a8ebfd921 OS images: use "ref", "stream" and "version"
Switch azure default region to west us
Update find-image script to work with new API spec
Add version for every os image build
generate measurements: Use new API paths
CLI: config fetch measurements: Use image short versions to fetch measurements
CLI: allows shortnames to specify image in config
Image build pipeline: Change paths to contain "ref" and "stream"
2022-12-09 13:37:43 +01:00

63 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright (c) Edgeless Systems GmbH
#
# SPDX-License-Identifier: AGPL-3.0-only
# Usage: find-image.sh
set -euo pipefail
shopt -s inherit_errexit
ref="-"
stream="stable"
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-r | --ref)
ref="$2"
shift # past argument
shift # past value
;;
-s | --stream)
stream="$2"
shift # past argument
shift # past value
;;
-*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
ref=$(echo -n "${ref}" | tr -c '[:alnum:]' '-')
base_url="https://cdn.confidential.cloud"
latest_path="constellation/v1/ref/${ref}/stream/${stream}/versions/latest/image.json"
latest_url="${base_url}/${latest_path}"
latest_status=$(curl -s -o /dev/null -w "%{http_code}" "${latest_url}")
if [[ ${latest_status} != "200" ]]; then
echo "No image found for ref ${ref} and stream ${stream} (${latest_status})"
exit 1
fi
latest_version=$(curl -sL "${latest_url}" | jq -r '.version')
shortname=""
if [[ ${ref} != "-" ]]; then
shortname+="ref/${ref}/"
fi
if [[ ${stream} != "stable" ]]; then
shortname+="stream/${stream}/"
fi
shortname+="${latest_version}"
echo "${shortname}"