From 1ddd468c1f753d06526af8b0a8bfcbf7c34a8393 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Fri, 14 Jan 2022 11:46:26 +0000 Subject: [PATCH] Added API key support to qdata script As with the qort script, it currently needs to be run from either the qortal directory or the tools directory in order to pick up the API key --- tools/qdata | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/qdata b/tools/qdata index b1e9720b..c9745900 100755 --- a/tools/qdata +++ b/tools/qdata @@ -22,6 +22,14 @@ if [ -z "$*" ]; then exit fi +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +if [ -f "apikey.txt" ]; then + apikey=$(cat "apikey.txt") +elif [ -f "${script_dir}/../apikey.txt" ]; then + apikey=$(cat "${script_dir}/../apikey.txt") +fi + method=$1 service=$2 name=$3 @@ -67,7 +75,7 @@ if [[ "${method}" == "POST" ]]; then fi echo "Creating transaction - this can take a while..." - tx_data=$(curl --silent --insecure -X ${method} "http://${host}:${port}/arbitrary/${service}/${name}/${identifier}${type_component}" -d "${data}") + tx_data=$(curl --silent --insecure -X ${method} "http://${host}:${port}/arbitrary/${service}/${name}/${identifier}${type_component}" -H "X-API-KEY: ${apikey}" -d "${data}") if [[ "${tx_data}" == *"error"* || "${tx_data}" == *"ERROR"* ]]; then echo "${tx_data}"; exit @@ -76,7 +84,7 @@ if [[ "${method}" == "POST" ]]; then fi echo "Computing nonce..." - computed_tx_data=$(curl --silent --insecure -X POST "http://${host}:${port}/arbitrary/compute" -H "Content-Type: application/json" -d "${tx_data}") + computed_tx_data=$(curl --silent --insecure -X POST "http://${host}:${port}/arbitrary/compute" -H "Content-Type: application/json" -H "X-API-KEY: ${apikey}" -d "${tx_data}") if [[ "${computed_tx_data}" == *"error"* || "${computed_tx_data}" == *"ERROR"* ]]; then echo "${computed_tx_data}"; exit fi @@ -112,9 +120,9 @@ elif [[ "${method}" == "GET" ]]; then # We use a different API depending on whether or not an identifier is supplied if [ -n "${identifier}" ]; then - response=$(curl --silent --insecure -X GET "http://${host}:${port}/arbitrary/${service}/${name}/${identifier}?rebuild=${rebuild}&filepath=${filepath}") + response=$(curl --silent --insecure -X GET "http://${host}:${port}/arbitrary/${service}/${name}/${identifier}?rebuild=${rebuild}&filepath=${filepath}" -H "X-API-KEY: ${apikey}") else - response=$(curl --silent --insecure -X GET "http://${host}:${port}/arbitrary/${service}/${name}?rebuild=${rebuild}&filepath=${filepath}") + response=$(curl --silent --insecure -X GET "http://${host}:${port}/arbitrary/${service}/${name}?rebuild=${rebuild}&filepath=${filepath}" -H "X-API-KEY: ${apikey}") fi if [ -z "${response}" ]; then