From a6719ab678351c816bb1035e75f2fddb692beb5d Mon Sep 17 00:00:00 2001 From: francois branciard Date: Sun, 16 Aug 2020 23:08:55 +0200 Subject: [PATCH] close #248. Add optional session key check --- orchestrator/src/polkadot.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/orchestrator/src/polkadot.js b/orchestrator/src/polkadot.js index 330dbb3..3566524 100644 --- a/orchestrator/src/polkadot.js +++ b/orchestrator/src/polkadot.js @@ -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'; @@ -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 { @@ -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;