Skip to content

Instantly share code, notes, and snippets.

@chmeee
Last active November 1, 2019 09:14
Show Gist options
  • Save chmeee/52bfcf4046df53192672888e9dd00cae to your computer and use it in GitHub Desktop.
Save chmeee/52bfcf4046df53192672888e9dd00cae to your computer and use it in GitHub Desktop.
Get output from an Azure batch execution
#!/usr/bin/env bash
if [[ $# != 2 ]]; then
echo "Cowardly refusing to run without exactly two arguments"
echo "Syntax: $0 key-string url"
exit 1
fi
API_VERSION="2019-08-01.10.0"
DATE=$(date +"%a, %d %b %Y %T %Z")
KEY=$1
URL="$2?api-version=$API_VERSION"
CANRESOURCE=$(echo -n $URL|sed 's|https:/||;s|\..*\.batch\.azure\.com||;s|\?|\n|s|=|:|')
ACCOUNT=$(echo -n $URL|sed -r 's|https://([^.]*)\..*|\1|')
SIGSTRING="GET\n\n\n\n\n\n\n\n\n\n\n\nocp-date:$DATE\n$CANRESOURCE"
SIGNATURE=$(hmac256 --binary $(echo -n $KEY|base64 -d) <(echo -en $SIGSTRING|iconv -t utf8 -)|base64 -w0)
curl -sLk $URL -H "Authorization: SharedKey $ACCOUNT:$SIGNATURE" -H "ocp-date: $DATE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment