Bachelorthesis_Code/requests.sh
cami a1a719088d
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Added some more options to requests-script
2021-07-23 00:51:28 +02:00

52 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
ACTION=$1
VALUE=$2
ACTIONS=(login register rcvpw username data csv)
print_help(){
echo "Usage: $0 ACTION [TOKEN|INPUT_TYPE]"
echo
echo "available actions:"
for el in "${ACTIONS[@]}"; do
echo - "$el"
done
exit 1
}
if [[ -z $1 ]]; then
print_help
fi
case $ACTION in
"${ACTIONS[0]}") # login
echo "login action"
curl localhost:5050/api/login -X POST -d '{"username":"test","password":"test"}'
;;
"${ACTIONS[1]}") # register
echo "register action"
curl localhost:5050/api/register -X POST -d '{"username":"test","password":"test"}'
;;
"${ACTIONS[2]}") # reveice password
echo "rcv_pw action"
curl localhost:5050/api/protected/rcv_pw
;;
"${ACTIONS[3]}") # get current username
echo "get username action"
curl localhost:5050/api/username -X GET -H "Authorization: Bearer $VALUE"
;;
"${ACTIONS[4]}") # get all data from behametricsserver
echo "get data action"
curl localhost:5000/data
;;
"${ACTIONS[5]}") # get all data from behametricsserver
echo "get data action"
curl localhost:5000/data/csv/"${VALUE}"
;;
*)
echo "Error: Action not available"
echo
print_help
;;
esac