telebit/examples/mgmt-add-device.sh

29 lines
696 B
Bash
Raw Permalink Normal View History

2022-06-07 08:27:05 +00:00
#!/bin/bash
set -e
set -u
2020-07-22 08:05:30 +00:00
source .env
# 1. (srv) create a new shared key for a given slug
# 2. (dev) try to update via ping
# 3. (dev) use key to exchange machine id
# 4. (dev) use key to connect to remote
# 5. (dev) ping occasionally
2022-06-07 08:27:05 +00:00
TOKEN="$(
go run cmd/signjwt/*.go \
--expires-in 1m \
--vendor-id "$VENDOR_ID" \
--secret "$RELAY_SECRET" \
--machine-ppid "$RELAY_SECRET"
)"
echo "${TOKEN}"
2020-07-22 08:05:30 +00:00
2020-11-13 11:26:25 +00:00
MGMT_URL=${MGMT_URL:-"http://mgmt.example.com:6468/api"}
2020-07-22 08:05:30 +00:00
CLIENT_SUBJECT=${CLIENT_SUBJECT:-"newbie"}
curl -X POST "$MGMT_URL/devices" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
2022-06-07 08:27:05 +00:00
-d '{ "slug": "'"$CLIENT_SUBJECT"'" }'