#!/bin/sh
if [ "$#" -lt 2 ]
then
echo "Usage: $0 JWT_FILE HOST_ID [NAME] [PHONE_NUMBER] [MAILING_ADDRESS] [COMPANY] [TITLE]"
exit 1
fi
jwt_filepath=$1
HOST_ID=$2
NAME="${3:-Sadly Unnamed, Jr.}"
PHONE_NUMBER="${4:-888-555-1212}"
MAILING_ADDRESS="${5:-111 Main St., Anytown, WA, 33333}"
COMPANY="${6:-Swiggy}"
TITLE="${7:-Associate Junior Intern}"
SERVER_URL="${SWGY_SERVER:-http://127.0.0.1}"
if ! test -f $jwt_filepath;
then
echo "Cannot read $jwt_filepath"
exit 1
fi
#
# Read the JWT token from the JSON file
access_token=$(jq -r '.access_token' "$jwt_filepath")
token_type=$(jq -r '.token_type' "$jwt_filepath")
# Check if token_type is "bearer"
if [ "$token_type" != "bearer" ]; then
echo "Error: invalid token_type"
exit 1
fi
#
# Set the Authorization header to the JWT token
authorization="Authorization: Bearer $access_token"
curl -k -vvv -X "PUT" -H "$authorization" -H "Content-Type: application/json" -d \
"{ \"conference-id\":\"${CONFERENCE_ID}\", \"name\":\"${NAME}\", \"mailing-address\":\"${MAILING_ADDRESS}\", \"phone-number\":\"${PHONE_NUMBER}\", \"company\":\"${COMPANY}\", \"title\":\"${TITLE}\"}" \
${SERVER_URL}/api/hosts/${HOST_ID}