From f581f54f8de3df9787eb2777259912b44c49be0e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 28 Dec 2022 11:27:48 +0100 Subject: -script now works with pingenv2 --- src/authorization/anastasis-authorization-post.sh | 44 +++++++++++++---------- 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'src/authorization') diff --git a/src/authorization/anastasis-authorization-post.sh b/src/authorization/anastasis-authorization-post.sh index f74f382..171fd65 100755 --- a/src/authorization/anastasis-authorization-post.sh +++ b/src/authorization/anastasis-authorization-post.sh @@ -1,6 +1,6 @@ #!/bin/bash # This file is in the public domain. -set -eux +set -eu # Theses are Anastasis SARL specific, do not share! # CLIENT_ID= @@ -49,7 +49,7 @@ cat - | sed -e "s/%NAME%/$NAME/g" \ -e "s/%COUNTRY%/$COUNTRY/g" \ -e "s/%MESSAGE%/$MESSAGE/g" > input.tex < /dev/null 2> /dev/null -REPLY=`curl -X POST -H "Content-Type: application/x-www-form-urlencoded" \ +REPLY=`curl -s -X POST -H "Content-Type: application/x-www-form-urlencoded" \ --data-urlencode "grant_type=client_credentials" \ --data-urlencode "client_id=$CLIENT_ID" \ --data-urlencode "client_secret=$CLIENT_SECRET" \ @@ -81,14 +81,14 @@ REPLY=`curl -X POST -H "Content-Type: application/x-www-form-urlencoded" \ ACCESS_TOKEN=`echo $REPLY | jq -r .access_token` -REPLY=`curl \ +REPLY=`curl -s \ -X GET "$ENDPOINT/file-upload" \ -H "Authorization: Bearer $ACCESS_TOKEN"` ATTRS=`echo $REPLY | jq .data.attributes` UPLOAD_URL=`echo $ATTRS | jq -r .url` URL_SIG=`echo $ATTRS | jq -r .url_signature` -curl -X PUT -T input.pdf $UPLOAD_URL +curl -s -X PUT -T input.pdf $UPLOAD_URL RECIPIENT="$(jq -n ' @@ -139,7 +139,7 @@ REQUEST="$(jq -n ' --arg URL_SIG "$URL_SIG" \ )" -STATUS=$(curl --request POST \ +STATUS=$(curl -s --request POST \ --url $ENDPOINT/organisations/${ORG_ID}/letters \ --header 'Content-Type: application/vnd.api+json' \ --header "Authorization: Bearer $ACCESS_TOKEN" \ @@ -156,22 +156,30 @@ case $STATUS in exit 1; ;; esac -LETTER_ID=`echo $REPLY | jq -r .data.id` - -REPLY=`mktemp /tmp/authorization-delete-replyXXXXXX` -STATUS=$(curl --request DELETE \ - --url $ENDPOINT/organisations/$ORG_ID/letters/$LETTER_ID \ - --header "Authorization: Bearer $ACCESS_TOKEN" \ - -o $REPLY \ - -w "%{http_code}" -s) -cat $REPLY >> $LOGS -case $STATUS in +LETTER_ID=`cat $MYDIR/final-reply.txt | jq -r .data.id` +REPLY=$MYDIR/delete-reply.txt +STATUS=409 +sleep 1; +while test $STATUS = 409; +do + STATUS=$(curl -s --request DELETE \ + --url $ENDPOINT/organisations/$ORG_ID/letters/$LETTER_ID \ + --header "Authorization: Bearer $ACCESS_TOKEN" \ + -o $REPLY \ + -w "%{http_code}" -s) + case $STATUS in 204) + cat $REPLY >> $LOGS ;; + 409) + # Happens, likely still in processing... + ;; *) echo "Failed to delete letter: $STATUS" >> $LOGS ;; -esac + esac +done + rm -r $MYDIR exit 0 -- cgit v1.2.3