chore(script): register guild node via backend-center CLI
This commit is contained in:
@@ -25,42 +25,18 @@ if ! docker compose ps backend-center >/dev/null 2>&1; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RESULT_JSON=$(docker compose exec -T \
|
RESULT_JSON=$(docker compose exec -T backend-center \
|
||||||
-e REG_NODE_ID="$NODE_ID" \
|
npm run -s cli -- node register --node-id "$NODE_ID" --name "$NODE_NAME" --endpoint "$NODE_ENDPOINT")
|
||||||
-e REG_NODE_NAME="$NODE_NAME" \
|
|
||||||
-e REG_NODE_ENDPOINT="$NODE_ENDPOINT" \
|
|
||||||
backend-center node -e "
|
|
||||||
(async () => {
|
|
||||||
const nodeId = process.env.REG_NODE_ID;
|
|
||||||
const name = process.env.REG_NODE_NAME;
|
|
||||||
const endpoint = process.env.REG_NODE_ENDPOINT;
|
|
||||||
|
|
||||||
const res = await fetch('http://127.0.0.1:7001/api/nodes/register', {
|
OK=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(String(!!o.ok));" "$RESULT_JSON")
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'content-type': 'application/json',
|
|
||||||
'x-fabric-version': '1',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ nodeId, name, endpoint }),
|
|
||||||
});
|
|
||||||
|
|
||||||
const text = await res.text();
|
if [[ "$OK" != "true" ]]; then
|
||||||
let data;
|
|
||||||
try { data = JSON.parse(text); } catch { data = { raw: text }; }
|
|
||||||
|
|
||||||
process.stdout.write(JSON.stringify({ status: res.status, data }));
|
|
||||||
})();
|
|
||||||
" )
|
|
||||||
|
|
||||||
STATUS=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(String(o.status));" "$RESULT_JSON")
|
|
||||||
|
|
||||||
if [[ "$STATUS" != "201" ]]; then
|
|
||||||
echo "registration failed: $RESULT_JSON" >&2
|
echo "registration failed: $RESULT_JSON" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
API_KEY=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(o.data?.apiKey||'');" "$RESULT_JSON")
|
API_KEY=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(o.apiKey||'');" "$RESULT_JSON")
|
||||||
NODE_ID_OUT=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(o.data?.node?.nodeId||'');" "$RESULT_JSON")
|
NODE_ID_OUT=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(o.node?.nodeId||'');" "$RESULT_JSON")
|
||||||
|
|
||||||
if [[ -z "$API_KEY" ]]; then
|
if [[ -z "$API_KEY" ]]; then
|
||||||
echo "registration succeeded but no apiKey returned: $RESULT_JSON" >&2
|
echo "registration succeeded but no apiKey returned: $RESULT_JSON" >&2
|
||||||
|
|||||||
Reference in New Issue
Block a user