80 lines
1.6 KiB
Bash
80 lines
1.6 KiB
Bash
|
#! /usr/bin/env bash
|
||
|
|
||
|
set -o errexit
|
||
|
set -o nounset
|
||
|
set -o pipefail
|
||
|
shopt -s inherit_errexit
|
||
|
|
||
|
: "${DOMAIN:?specify domain name}"
|
||
|
readonly SERVICE_NAME="${1:?service name not given error}"
|
||
|
readonly AUTH_HEADER="Authorization: Bearer ${API_TOKEN:?not set error}"
|
||
|
QUERY=$(cat << EOF
|
||
|
mutation EnableServices {
|
||
|
__typename
|
||
|
services {
|
||
|
enableService(serviceId: \"${SERVICE_NAME}\") {
|
||
|
code
|
||
|
message
|
||
|
success
|
||
|
service {
|
||
|
id
|
||
|
isEnabled
|
||
|
status
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
EOF
|
||
|
)
|
||
|
|
||
|
# shellcheck disable=SC2086,SC2116
|
||
|
REQUEST=$(cat << EOF
|
||
|
{
|
||
|
"query": "$(echo $QUERY)",
|
||
|
"variables": null,
|
||
|
"operationName": "EnableServices"
|
||
|
}
|
||
|
EOF
|
||
|
)
|
||
|
readonly REQUEST
|
||
|
|
||
|
EXPECTED_RESPONSE=$(cat << EOF
|
||
|
{
|
||
|
"data": {
|
||
|
"__typename": "Mutation",
|
||
|
"services": {
|
||
|
"enableService": {
|
||
|
"code": 200,
|
||
|
"message": "Service enabled.",
|
||
|
"service": {
|
||
|
"id": "${SERVICE_NAME}",
|
||
|
"isEnabled": true,
|
||
|
"status": "OFF"
|
||
|
},
|
||
|
"success": true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
EOF
|
||
|
)
|
||
|
|
||
|
received_response="$(curl --show-error -s "https://api.$DOMAIN/graphql" \
|
||
|
--compressed \
|
||
|
-H 'Content-Type: application/json' \
|
||
|
--data-raw "$REQUEST" -k -H "$AUTH_HEADER")"
|
||
|
|
||
|
sorted_response="$(jq --sort-keys <<<"$received_response")" \
|
||
|
|| { echo "error"; echo "$received_response"; echo -e "QUERY:\n$QUERY"; exit 1; }
|
||
|
|
||
|
jq <<<"$sorted_response"
|
||
|
|
||
|
if diff -w -u --color <(printf "%s\n" "$EXPECTED_RESPONSE") <(printf "%s\n" "$sorted_response") 2>/dev/null
|
||
|
then
|
||
|
echo -e "\e[1;32mOK"
|
||
|
else
|
||
|
echo -e "\e[1;31mFAIL: response does not match!"
|
||
|
jd -color <(printf "%s\n" "$EXPECTED_RESPONSE") <(printf "%s" "$sorted_response")
|
||
|
exit 1
|
||
|
fi
|