summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-12-28 11:27:48 +0100
committerChristian Grothoff <christian@grothoff.org>2022-12-28 11:27:48 +0100
commitf581f54f8de3df9787eb2777259912b44c49be0e (patch)
tree380025799472d0ecc81e45db43837fd043bafa3a
parent780e28adf6acc89b3e28a009f5e275765448c872 (diff)
downloadanastasis-f581f54f8de3df9787eb2777259912b44c49be0e.tar.gz
anastasis-f581f54f8de3df9787eb2777259912b44c49be0e.tar.bz2
anastasis-f581f54f8de3df9787eb2777259912b44c49be0e.zip
-script now works with pingenv2
-rwxr-xr-xsrc/authorization/anastasis-authorization-post.sh44
1 files changed, 26 insertions, 18 deletions
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 <<EOF
\NeedsTeXFormat{LaTeX2e}
-\documentclass[fontsize=11pt,a4paper,DE]{scrlttr2}
+\documentclass[fontsize=11pt,a4paper]{scrlttr2}
\makeatletter
\KOMAoptions{foldmarks=off}
%\@setplength{toaddrvpos}{30mm}
@@ -70,9 +70,9 @@ cat - | sed -e "s/%NAME%/$NAME/g" \
\end{letter}
\end{document}
EOF
-pdflatex input.tex
+pdflatex 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