Skip to content

Commit

Permalink
close #248. Add optional session key check
Browse files Browse the repository at this point in the history
  • Loading branch information
branciard committed Aug 16, 2020
1 parent 096310c commit a6719ab
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions orchestrator/src/polkadot.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Polkadot {
config.polkadotAdditionalOptions = process.env.POLKADOT_ADDITIONAL_OPTIONS;
config.nodesRole = process.env.NODES_ROLE;
config.nodeId = process.env.NODE_ID;
config.polkadotSessionKeyToCheck = process.env.POLKADOT_SESSION_KEY_TO_CHECK;
config.polkadotUnixUserId = 1000;
config.polkadotUnixGroupId = 1000;
config.polkadotRpcPort = '9993';
Expand Down Expand Up @@ -255,6 +256,30 @@ class Polkadot {
}
}

async checkSessionKeyOnNode (containerName, sessionKey) {
try {
console.log('check Session Key valid On Node for session key value :');
console.log(sessionKey);
// Constructing command check session key
const command = ['curl', 'http://localhost:' + config.polkadotRpcPort, '-H', 'Content-Type:application/json;charset=utf-8', '-d',
`{
"jsonrpc":"2.0",
"id":1,
"method":"author_hasSessionKeys",
"params": [
"${sessionKey}"
]
}`];
// Importing key by executing command in docker container
const result = await this.docker.dockerExecute(containerName, command);
console.log(`Command hasSessionKeys result: "${result}"`);
} catch (error) {
debug('checkSessionKeyOnNode', error);
console.error('Error: Can\'t check session key');
console.error(error);
}
}

// Check if a key file is present in container file system
async checkKeyAdded (mnemonic, crypto, containerName) {
try {
Expand Down Expand Up @@ -536,6 +561,9 @@ class Polkadot {
await new Promise(resolve => setTimeout(resolve, 10000));
await this.polkadotKeysImport(containerName);
}
if (config.polkadotSessionKeyToCheck) {
await this.checkSessionKeyOnNode(containerName, config.polkadotSessionKeyToCheck);
}
} catch (error) {
debug('polkadotStart', error);
throw error;
Expand Down

0 comments on commit a6719ab

Please sign in to comment.