Skip to content

Instantly share code, notes, and snippets.

@pierre-emmanuelJ
Last active July 2, 2025 08:43
Show Gist options
  • Save pierre-emmanuelJ/7434dd70eb121d3e3851ba1f38f45811 to your computer and use it in GitHub Desktop.
Save pierre-emmanuelJ/7434dd70eb121d3e3851ba1f38f45811 to your computer and use it in GitHub Desktop.
A Bash script to generate and send authenticated HTTP requests to the Exoscale API v2 using HMAC-SHA256 signatures.
#!/bin/bash
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
echo "Usage: $0 <method> <url-path> [expiration]"
echo "Example: $0 GET instance 1717430400"
echo "Parameters:"
echo " method - HTTP method (GET, POST, PUT, DELETE)"
echo " url-path - API path without /v2/ prefix"
echo " expiration - (optional) Unix epoch timestamp (default: now + 300s)"
exit 1
fi
host="https://api-ch-gva-2.exoscale.com"
method="$1"
url="/v2/$2"
if [ -n "$3" ]; then
expiration="$3"
else
expiration=$(($(date +%s) + 300))
fi
if [ -z "$EXOSCALE_API_KEY" ] || [ -z "$EXOSCALE_API_SECRET" ]; then
echo "Error: EXOSCALE_API_KEY and EXOSCALE_API_SECRET environment variables must be set."
exit 1
fi
key="$EXOSCALE_API_KEY"
secret="$EXOSCALE_API_SECRET"
body=""
qparams=""
rheaders=""
msg="$method $url
$body
$qparams
$rheaders
$expiration"
signature=$( echo -n "$msg" | openssl dgst -sha256 -hmac "$secret" -binary | base64 )
authHeader="Authorization: EXO2-HMAC-SHA256 credential=$key,expires=$expiration,signature=$signature"
echo "########"
echo SIGNATURE: curl -v -X "$method" -H "\"$authHeader\"" "${host}${url}"
echo "########"
curl -X "$method" -H "$authHeader" "${host}${url}" && echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment