Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Variables que debes modificar con tus datos
- # Author: Ricardo Carrillo [email protected]
- TENANCY_OCID="ocid1.tenancy.oc1..xxxxxxxxxxxxxxxx"
- USER_OCID="ocid1.user.oc1..aaaaaaaaoh6vmzkzfnd5cuskxnmllluvysotcs57cwc2upn2733ftemidxha"
- FINGERPRINT="XX:XX:a1:e5:0a:XX:XX:c6:4c:ff:XX:52:XX:87:7f:67"
- PRIVATE_KEY_PATH="$HOME/.oci/oci-api.key"
- REGION="us-sanjose-1"
- # Definiendo el periodo de 3 meses, desde la fecha actual, hacia 3 meses atras.
- FILE1="audit-events.json"
- NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
- BEF=$(date -u --date="3 months ago" +"%Y-%m-%dT%H:%M:%SZ")
- # Definiendo el metodo http
- METHOD="GET"
- # Definiendo el REST API
- URL="https://audit.${REGION}.oraclecloud.com/20190901/auditEvents?compartmentId=${TENANCY_OCID}&startTime=${BEF}&endTime=$NOW"
- # Extraer host y path con query de la URL
- HOST=$(echo $URL | awk -F/ '{print $3}')
- PATH_QUERY=$(echo "$URL" | sed -e "s#https\?://$HOST##")
- # Crear la cabecera Date en formato RFC 7231 (UTC)
- DATE=$(LC_ALL=C date -u +"%a, %d %b %Y %H:%M:%S GMT")
- # Construir string para firmar
- SIGNING_STRING="(request-target): ${METHOD,,} $PATH_QUERY
- date: $DATE
- host: $HOST"
- # Firmar el string con RSA-SHA256 y convertiro a base64
- SIGNATURE=$(printf '%s' "$SIGNING_STRING" | openssl dgst -sha256 -sign "$PRIVATE_KEY_PATH" | base64 | tr -d '\n')
- # Construir header Authorization
- KEY_ID="$TENANCY_OCID/$USER_OCID/$FINGERPRINT"
- AUTH_HEADER="Signature version=\"1\",keyId=\"$KEY_ID\",algorithm=\"rsa-sha256\",headers=\"(request-target) date host\",signature=\"$SIGNATURE\""
- echo "Authorization: Signature version=\"1\",keyId=\"$KEY_ID\",algorithm=\"rsa-sha256\",headers=\"(request-target) date host\",signature=\"$SIGNATURE\""
- # Ejecutar curl con headers
- echo curl --location "$URL" \
- --header "Date: $DATE" \
- --header "Host: $HOST" \
- --header "Authorization: $AUTH_HEADER" \
- --header "Content-Type: application/json" | tee $FILE1
Add Comment
Please, Sign In to add comment