Created
October 21, 2017 07:29
-
-
Save cormacrelf/b4a3d2a3626e05813637f15290d9dc95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# must have ZEROTIER_API_KEY exported | |
accept='{"rulesSource": "accept;"}' | |
echo "$accept" | curl --silent -H "Authorization: Bearer $ZEROTIER_API_KEY" -d @- https://my.zerotier.com/api/network/ -o net.json | |
# get the id from the output using https://stedolan.github.io/jq/ | |
ID=$(jq -r .id < net.json) | |
echo | |
echo created network $ID | |
assert_rule() { | |
TYPE=$(jq -r .config.rules[0].type < $1) | |
if $([[ "$TYPE" = "$2" ]]); then | |
echo "$1's first rule was $2 (ok)" | |
else | |
echo "FAILED: $1's first rule was meant to be $2" | |
fi | |
} | |
# verify there's exactly one rule compiled | |
assert_rule net.json "ACTION_ACCEPT" | |
drop='{"rulesSource": "drop;"}' | |
# update the network | |
echo "$drop" | curl --silent -H "Authorization: Bearer $ZEROTIER_API_KEY" -d @- https://my.zerotier.com/api/network/$ID -o net2.json | |
# fails | |
# {"type":"internal","message":"Internal error loading network."} | |
echo | |
echo "response from update call:" | |
cat net2.json; echo | |
echo | |
assert_rule net2.json "ACTION_DROP" | |
echo | |
echo "deleting network $ID" | |
curl --silent -H "Authorization: Bearer $ZEROTIER_API_KEY" -X DELETE https://my.zerotier.com/api/network/$ID >/dev/null | |
rm net.json net2.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment