aboutsummaryrefslogtreecommitdiff
path: root/src/kyclogic/taler-exchange-kyc-oauth2-nda.sh
blob: 5af785f1933bec0ac0b81b7f608b561df165660b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# This file is in the public domain.
#
# This code converts (some of) the JSON output from NDA into the GNU Taler
# specific KYC attribute data (again in JSON format).
#

# Die if anything goes wrong.
set -eu

# First, extract everything from stdin.
J=$(jq '{"status":.status,"id":.data.id,"last":.data.last_name,"first":.data.first_name,"phone":.data.phone}')

STATUS=$(echo "$J" | jq -r '.status')
if [ "$STATUS" != "success" ]
then
  return 1
fi

# Next, combine some fields into larger values.
FULLNAME=$(echo "$J" | jq -r '[.first_name,.last_name]|join(" ")')

echo "$J" \
    | jq \
          --arg full_name "${FULLNAME}" \
          '{$full_name,"phone":.phone,"id":.id}' \
    | jq \
          'del(..|select(.==null))'

exit 0