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
|
||||
fi
|
||||
|
||||
RESULT_JSON=$(docker compose exec -T \
|
||||
-e REG_NODE_ID="$NODE_ID" \
|
||||
-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;
|
||||
RESULT_JSON=$(docker compose exec -T backend-center \
|
||||
npm run -s cli -- node register --node-id "$NODE_ID" --name "$NODE_NAME" --endpoint "$NODE_ENDPOINT")
|
||||
|
||||
const res = await fetch('http://127.0.0.1:7001/api/nodes/register', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'x-fabric-version': '1',
|
||||
},
|
||||
body: JSON.stringify({ nodeId, name, endpoint }),
|
||||
});
|
||||
OK=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(String(!!o.ok));" "$RESULT_JSON")
|
||||
|
||||
const text = await res.text();
|
||||
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
|
||||
if [[ "$OK" != "true" ]]; then
|
||||
echo "registration failed: $RESULT_JSON" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
API_KEY=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(o.data?.apiKey||'');" "$RESULT_JSON")
|
||||
NODE_ID_OUT=$(node -e "const o=JSON.parse(process.argv[1]);process.stdout.write(o.data?.node?.nodeId||'');" "$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.node?.nodeId||'');" "$RESULT_JSON")
|
||||
|
||||
if [[ -z "$API_KEY" ]]; then
|
||||
echo "registration succeeded but no apiKey returned: $RESULT_JSON" >&2
|
||||
|
||||
Reference in New Issue
Block a user