post_management_api_verifications.sh (1258B)
1 #!/bin/bash 2 # sends POST request to the swiyu verifier and generates a qr code from the verification_url in the response. 3 # 4 # requires: 5 # - jq 6 # - qrencode 7 # 8 # Set VERIFIER to reach a verifier elsewhere than http://localhost:8080. 9 if [ $# -eq 0 ]; then 10 echo "Error: No JSON request file provided" 11 echo "Usage: $0 <json_file>" 12 exit 1 13 fi 14 15 # Determine the input file (add .json if not present and file doesn't exist) 16 if [ -f "$1" ]; then 17 input_file="$1" 18 elif [ -f "${1}.json" ]; then 19 input_file="${1}.json" 20 else 21 echo "Error: File '$1' or '${1}.json' not found" 22 exit 1 23 fi 24 25 base_name="${input_file%.json}" 26 27 response_file="${base_name}_response.json" 28 qr_code_file="${base_name}_qr_code.png" 29 30 VERIFIER=${VERIFIER:-http://localhost:8080} 31 32 curl -s -X POST "$VERIFIER/management/api/verifications" \ 33 -H "Accept: application/json" \ 34 -H "Content-Type: application/json" \ 35 -d @"$input_file" \ 36 | tee "$response_file" | jq -r '.verification_url' | tee /dev/tty | xargs qrencode -o "$qr_code_file" 37 38 # Show the QR code with whatever this system uses for images. 39 if command -v xdg-open >/dev/null 2>&1; then 40 xdg-open "$qr_code_file" 41 elif command -v open >/dev/null 2>&1; then 42 open "$qr_code_file" 43 else 44 echo "QR code written to $qr_code_file" 45 fi 46