Last active
November 1, 2019 09:14
-
-
Save chmeee/52bfcf4046df53192672888e9dd00cae to your computer and use it in GitHub Desktop.
Get output from an Azure batch execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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