gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated: -more work on pingen v2 migrati


From: gnunet
Subject: [taler-anastasis] branch master updated: -more work on pingen v2 migration
Date: Mon, 26 Dec 2022 17:44:19 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new c465434  -more work on pingen v2 migration
c465434 is described below

commit c46543428f293bda5c9a11fadf789f58921cce7d
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Mon Dec 26 17:44:12 2022 +0100

    -more work on pingen v2 migration
---
 src/authorization/anastasis-authorization-email.sh |   1 +
 src/authorization/anastasis-authorization-post.sh  | 130 ++++++++++++++-------
 src/authorization/anastasis-authorization-sms.sh   |   1 +
 3 files changed, 91 insertions(+), 41 deletions(-)

diff --git a/src/authorization/anastasis-authorization-email.sh 
b/src/authorization/anastasis-authorization-email.sh
index ae3ecf7..738aaf0 100755
--- a/src/authorization/anastasis-authorization-email.sh
+++ b/src/authorization/anastasis-authorization-email.sh
@@ -1,2 +1,3 @@
 #!/bin/sh
+# This file is in the public domain.
 exec mail -s "Anastasis" -r noreply "$1"
diff --git a/src/authorization/anastasis-authorization-post.sh 
b/src/authorization/anastasis-authorization-post.sh
index 500c2ed..d5bb3a1 100755
--- a/src/authorization/anastasis-authorization-post.sh
+++ b/src/authorization/anastasis-authorization-post.sh
@@ -1,5 +1,6 @@
 #!/bin/bash
-set -eu
+# This file is in the public domain.
+set -eux
 
 # Theses are Anastasis SARL specific, do not share!
 # CLIENT_ID=
@@ -7,57 +8,98 @@ set -eu
 # ORG_ID=
 . pingen-secrets
 
-ENDPOINT=https://api.v2.pingen.com/
+ENDPOINT="https://api.v2.pingen.com";
+LOGS="$PWD/authorization-post.log"
 
 MESSAGE=`cat -`
 DATE=`date +%F`
+ADDR="$1"
+NAME=`echo $ADDR | jq -r .full_name`
+STREET=`echo $ADDR | jq -r .street`
+
+LNUMBER=`echo $STREET | awk '{print $NF}'`
+FNUMBER=`echo $STREET | awk '{print $1}'`
+case $LNUMBER in
+    ''|*[!0-9]*)
+       case $FNUMBER in
+           ''|*[!0-9]*)
+               NUMBER=0
+               ;;
+           *)
+               NUMBER=$FNUMBER
+               ;;
+       esac
+       ;;
+    *)
+       NUMBER=$LNUMBER
+       ;;
+esac
+
+
+CITY=`echo $ADDR | jq -r .city`
+POSTCODE=`echo $ADDR | jq -r .postcode`
+COUNTRY=`echo $ADDR | jq -r .country`
+
+MYDIR=`mktemp -d /tmp/authorization-post-XXXXXX`
+cd "$MYDIR"
+cat - | sed -e "s/%NAME%/$NAME/g" \
+           -e "s/%STREET%/$STREET/g" \
+           -e "s/%POSTCODE%/$POSTCODE/g" \
+           -e "s/%CITY%/$CITY/g" \
+           -e "s/%COUNTRY%/$COUNTRY/g" \
+           -e "s/%MESSAGE%/$MESSAGE/g" > input.tex <<EOF
+\NeedsTeXFormat{LaTeX2e}
+\documentclass[10pt]{letter}
+\date{\today}
+\address{Anastasis SARL \\\\ 7 rue de Mondorf \\\\ 5431 Erpeldange}
+\signature{Anastasis SARL}
+\begin{document}
+\begin{letter}{%NAME% \\\\ %STREET% \\\\ %POSTCODE% %CITY% \\\\ %COUNTRY% }
+\opening{To whom it may concern,}
+%MESSAGE%
+\closing{Best regards}
+\end{letter}
+\end{document}
+EOF
+pdflatex input.tex
 
-ACCESS_TOKEN=`curl -X POST -H "Content-Type: 
application/x-www-form-urlencoded" \
+REPLY=`curl -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" \
     --data-urlencode "scope=letter" \
-    https://identity.pingen.com/auth/access-tokens | jq .access_token`
+    https://identity.pingen.com/auth/access-tokens`
 
-# FIXME: create PDF with:
-#title: "Anastasis",
-#        place: "Luxembourg",
-#        date: $DATE,
-#        content: $MESSAGE,
+ACCESS_TOKEN=`echo $REPLY | jq -r .access_token`
 
-ATTRS=`curl \
-    -X GET "$ENDPOINT/organisations/$ORG_ID/letters" \
-    -H  "Authorization: Bearer $ACCESS_TOKEN" | jq .data.attributes`
+REPLY=`curl \
+    -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`
 
-UPLOAD_URL=`echo $ATTRS | jq .url`
-URL_SIG=`echo $ATTRS | jq .url_signature`
+curl -X PUT -T input.pdf $UPLOAD_URL
 
-# FIXME: somehow should PUT the file on $UPLOAD_URL here!
-# (not sure how to use URL_SIG, if at all!)
 
-LOGS="authorization-post.log"
-ADDR="$1"
-NAME=`echo $ADDR | jq -r .full_name`
-STREET=`echo $ADDR | jq -r .street`
-CITY=`echo $ADDR | jq -r .city`
-POSTCODE=`echo $ADDR | jq -r .postcode`
-COUNTRY=`echo $ADDR | jq -r .country`
-ADDRESS=`echo -e "$STREET\n$POSTCODE $CITY\n$COUNTRY"`
 RECIPIENT="$(jq -n '
     {
         name: $NAME,
         street: $STREET,
-       number: "",
+       number: $NUMBER,
         city: $CITY,
         zip: $POSTCODE,
         country: $COUNTRY,
     }' \
     --arg NAME "$NAME" \
     --arg STREET "$STREET" \
+    --arg NUMBER "$NUMBER" \
     --arg CITY "$CITY" \
     --arg POSTCODE "$POSTCODE" \
-    --arg COUNTRY "$COUNTRY"
+    --arg COUNTRY "$COUNTRY" \
   )"
+echo RECIPIENT $RECIPIENT
+
 SENDER="$(jq -n '
     {
         name: "Anastasis SARL",
@@ -68,52 +110,58 @@ SENDER="$(jq -n '
        country: "Luxembourg"
     }' 
   )"
+
+echo SENDER $SENDER
+
 REQUEST="$(jq -n '
     {   data: {
         type: "letters",
        attributes: {
-         file_original_name: "wtf.pdf",
-         file_url: "$UPLOAD_URL",
-         file_url_signature: "$URL_SIG",
+         file_original_name: "input.pdf",
+         file_url: $UPLOAD_URL,
+         file_url_signature: $URL_SIG,
          address_position: "right",
          delivery_product: "cheap",
          print_mode: "duplex",
+         auto_send: false,
          print_spectrum: "grayscale",
          meta_data: {
             recipient: $RECIPIENT,
              sender: $SENDER
-          }
+          } } }
     }' \
     --argjson RECIPIENT "$RECIPIENT" \
-    --argjson SENDER "$SENDER" \ 
+    --argjson SENDER "$SENDER" \
     --arg UPLOAD_URL "$UPLOAD_URL" \
-    --arg URL_SIG "$URL_SIG"
+    --arg URL_SIG "$URL_SIG" \
   )"
-REPLY=`mktemp /tmp/authorization-add-replyXXXXXX`
+echo REQUEST $REQUEST
+
 STATUS=$(curl --request POST \
-     --url $ENDPOINT/organizations/${ORG_ID}/letters \
-     --header 'Content-Type: application/json' \
-     --header 'Authorization: Bearer $ACCESS_TOKEN' \
+     --url $ENDPOINT/organisations/${ORG_ID}/letters \
+     --header 'Content-Type: application/vnd.api+json' \
+     --header "Authorization: Bearer $ACCESS_TOKEN" \
      -d "$REQUEST" \
-     -o $REPLY \
+     -o $MYDIR/final-reply.txt \
      -w "%{http_code}" -s)
-cat $REPLY >> $LOGS
+echo STATUS $STATUS
+cat $MYDIR/final-reply.txt >> $LOGS
 case $STATUS in
     201)
         ;;
     *)
         echo "Failed to add letter: $STATUS" >> $LOGS
+       echo $REPLY
         exit 1;
         ;;
 esac
 LETTER_ID=`cat $REPLY | jq -r .data.id`
-rm $REPLY
 
 exit 0
 
 REPLY=`mktemp /tmp/authorization-delete-replyXXXXXX`
 STATUS=$(curl --request POST \
-        --url $ENDPOINT/organizations/$ORG_ID/letters/$LETTER_ID \
+        --url $ENDPOINT/organisations/$ORG_ID/letters/$LETTER_ID \
         -o $REPLY \
         -w "%{http_code}" -s)
 cat $REPLY >> $LOGS
@@ -124,6 +172,6 @@ case $STATUS in
         echo "Failed to delete letter: $STATUS" >> $LOGS
         ;;
 esac
-rm $REPLY
+rm -r $MYDIR
 
 exit 0
diff --git a/src/authorization/anastasis-authorization-sms.sh 
b/src/authorization/anastasis-authorization-sms.sh
index 28da3ed..ddfc649 100755
--- a/src/authorization/anastasis-authorization-sms.sh
+++ b/src/authorization/anastasis-authorization-sms.sh
@@ -1,4 +1,5 @@
 #!/bin/sh
+# This file is in the public domain.
 set -eu
 . telesign-secrets
 # Set AUTH_TOKEN=...

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]