1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/tools/villas-api.sh
Steffen Vogel 0735eb0f89 Make project REUSE compliant
And various other cleanups and harmonizations

Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
2023-09-07 11:16:04 +02:00

33 lines
842 B
Bash
Executable file

#!/bin/bash
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
# SPDX-License-Identifier: Apache-2.0
# 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 .