[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: start work on pingen v2 migrati
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: start work on pingen v2 migration |
Date: |
Sat, 24 Dec 2022 20:06:57 +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 d2180b4 start work on pingen v2 migration
d2180b4 is described below
commit d2180b4bbf2c7cfba67ef9ed5bf848e9d4e55c00
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Sat Dec 24 20:06:54 2022 +0100
start work on pingen v2 migration
---
src/authorization/anastasis-authorization-post.sh | 129 ++++++++++++++++++++++
src/authorization/anastasis-authorization-sms.sh | 27 +++++
2 files changed, 156 insertions(+)
diff --git a/src/authorization/anastasis-authorization-post.sh
b/src/authorization/anastasis-authorization-post.sh
new file mode 100755
index 0000000..500c2ed
--- /dev/null
+++ b/src/authorization/anastasis-authorization-post.sh
@@ -0,0 +1,129 @@
+#!/bin/bash
+set -eu
+
+# Theses are Anastasis SARL specific, do not share!
+# CLIENT_ID=
+# CLIENT_SECRET=
+# ORG_ID=
+. pingen-secrets
+
+ENDPOINT=https://api.v2.pingen.com/
+
+MESSAGE=`cat -`
+DATE=`date +%F`
+
+ACCESS_TOKEN=`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`
+
+# FIXME: create PDF with:
+#title: "Anastasis",
+# place: "Luxembourg",
+# date: $DATE,
+# content: $MESSAGE,
+
+ATTRS=`curl \
+ -X GET "$ENDPOINT/organisations/$ORG_ID/letters" \
+ -H "Authorization: Bearer $ACCESS_TOKEN" | jq .data.attributes`
+
+UPLOAD_URL=`echo $ATTRS | jq .url`
+URL_SIG=`echo $ATTRS | jq .url_signature`
+
+# 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: "",
+ city: $CITY,
+ zip: $POSTCODE,
+ country: $COUNTRY,
+ }' \
+ --arg NAME "$NAME" \
+ --arg STREET "$STREET" \
+ --arg CITY "$CITY" \
+ --arg POSTCODE "$POSTCODE" \
+ --arg COUNTRY "$COUNTRY"
+ )"
+SENDER="$(jq -n '
+ {
+ name: "Anastasis SARL",
+ street: "Rue de Mondorf",
+ number: "7",
+ zip: "5421",
+ city: "Erpeldange",
+ country: "Luxembourg"
+ }'
+ )"
+REQUEST="$(jq -n '
+ { data: {
+ type: "letters",
+ attributes: {
+ file_original_name: "wtf.pdf",
+ file_url: "$UPLOAD_URL",
+ file_url_signature: "$URL_SIG",
+ address_position: "right",
+ delivery_product: "cheap",
+ print_mode: "duplex",
+ print_spectrum: "grayscale",
+ meta_data: {
+ recipient: $RECIPIENT,
+ sender: $SENDER
+ }
+ }' \
+ --argjson RECIPIENT "$RECIPIENT" \
+ --argjson SENDER "$SENDER" \
+ --arg UPLOAD_URL "$UPLOAD_URL" \
+ --arg URL_SIG "$URL_SIG"
+ )"
+REPLY=`mktemp /tmp/authorization-add-replyXXXXXX`
+STATUS=$(curl --request POST \
+ --url $ENDPOINT/organizations/${ORG_ID}/letters \
+ --header 'Content-Type: application/json' \
+ --header 'Authorization: Bearer $ACCESS_TOKEN' \
+ -d "$REQUEST" \
+ -o $REPLY \
+ -w "%{http_code}" -s)
+cat $REPLY >> $LOGS
+case $STATUS in
+ 201)
+ ;;
+ *)
+ echo "Failed to add letter: $STATUS" >> $LOGS
+ 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 \
+ -o $REPLY \
+ -w "%{http_code}" -s)
+cat $REPLY >> $LOGS
+case $STATUS in
+ 200)
+ ;;
+ *)
+ echo "Failed to delete letter: $STATUS" >> $LOGS
+ ;;
+esac
+rm $REPLY
+
+exit 0
diff --git a/src/authorization/anastasis-authorization-sms.sh
b/src/authorization/anastasis-authorization-sms.sh
new file mode 100755
index 0000000..28da3ed
--- /dev/null
+++ b/src/authorization/anastasis-authorization-sms.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+set -eu
+. telesign-secrets
+# Set AUTH_TOKEN=...
+
+MESSAGE=`cat -`
+TMPFILE=`mktemp /tmp/sms-loggingXXXXXX`
+STATUS=$(curl --request POST \
+ --url https://rest-api.telesign.com/v1/messaging \
+ --header 'authorization: Basic $AUTH_TOKEN' \
+ --header 'content-type: application/x-www-form-urlencoded' \
+ --data account_livecycle_event=transact \
+ --data "message=$MESSAGE" \
+ --data message_type=OTP \
+ --data "phone_number=$1" \
+ -w "%{http_code}" -s -o $TMPFILE)
+echo `cat $TMPFILE` >> /var/log/sms.log
+rm -f $TMPFILE
+case $STATUS in
+ 200|203|250|290|291|295)
+ exit 0;
+ ;;
+ *)
+ exit 1;
+ ;;
+esac
+exit 1
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: start work on pingen v2 migration,
gnunet <=