Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creator node availability verification route (#1013)
Availability verification route intended for use by service providers deploying new nodes
- Loading branch information
1 parent
53988c9
commit 7183909
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const axios = require('axios') | ||
const { generateTimestampAndSignature } = require('../src/apiSigning') | ||
const { promisify } = require('util') | ||
|
||
const crypto = require('crypto') | ||
|
||
const PRIVATE_KEY = process.env.delegatePrivateKey | ||
const CREATOR_NODE_ENDPOINT = process.env.creatorNodeEndpoint | ||
const randomBytes = promisify(crypto.randomBytes) | ||
|
||
/** | ||
* Process command line args and issue duration health check | ||
*/ | ||
async function run () { | ||
try { | ||
parseEnvVarsAndArgs() | ||
} catch (e) { | ||
console.error(`\nIncorrect script usage: ${e.message}`) | ||
console.error(`Script usage: node verifyHealthcheckDuration.js`) | ||
return | ||
} | ||
|
||
try { | ||
// Generate signature using local key | ||
const randomBytesToSign = (await randomBytes(18)).toString() | ||
const signedLocalData = generateTimestampAndSignature({ randomBytesToSign }, PRIVATE_KEY) | ||
// Add randomBytes to outgoing request parameters | ||
const reqParam = signedLocalData | ||
reqParam.randomBytes = randomBytesToSign | ||
let requestConfig = { | ||
url: `${CREATOR_NODE_ENDPOINT}/health_check/duration`, | ||
method: 'get', | ||
params: reqParam, | ||
responseType: 'json' | ||
} | ||
let resp = await axios(requestConfig) | ||
let data = resp.data | ||
console.dir(data, { depth: 5 }) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} | ||
|
||
/** | ||
* Parses the environment variables and command line args | ||
* export creatorNodeEndpoint=http://cn1_creator-node_1:4000 | ||
* export delegatePrivateKey=f0b743ce8adb7938f1212f188347a63... | ||
* NOTE: DO NOT PREFIX PRIVATE KEY WITH 0x | ||
*/ | ||
function parseEnvVarsAndArgs () { | ||
if (!CREATOR_NODE_ENDPOINT || !PRIVATE_KEY) { | ||
let errorMsg = `creatorNodeEndpoint [${CREATOR_NODE_ENDPOINT}] or delegatePrivateKey [${PRIVATE_KEY}] have not been exported. ` | ||
errorMsg += "Please export environment variables 'delegatePrivateKey' and 'creatorNodeEndpoint'." | ||
throw new Error(errorMsg) | ||
} | ||
} | ||
|
||
run() |
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
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