mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
api: add little shell script to query the VILLASnode API
This commit is contained in:
parent
d7deec4318
commit
c71cb752fc
2 changed files with 38 additions and 0 deletions
|
@ -44,3 +44,10 @@ install(
|
|||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
RENAME villas
|
||||
)
|
||||
|
||||
install(
|
||||
PROGRAMS villas-api.sh
|
||||
COMPONENT bin
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
RENAME villas-api
|
||||
)
|
||||
|
|
31
tools/villas-api.sh
Executable file
31
tools/villas-api.sh
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Check if all required commands exist
|
||||
|
||||
if ! command -v curl &> /dev/null; then
|
||||
echo "curl could not be found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "jq could not be found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "usage: villas-api ACTION [REQUEST-JSON]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ACTION=$1
|
||||
REQUEST=${2:-\{\}}
|
||||
ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
|
||||
ENDPOINT=${ENDPOINT:-http://localhost:80/api/v1}
|
||||
|
||||
echo "Issuing API request: action=${ACTION}, id=${ID}, request=${REQUEST}, endpoint=${ENDPOINT}"
|
||||
|
||||
curl -s -X POST --data "{
|
||||
\"action\" : \"${ACTION}\",
|
||||
\"id\": \"${ID}\",
|
||||
\"request\": ${REQUEST}
|
||||
}" ${ENDPOINT} | jq .
|
Loading…
Add table
Reference in a new issue