diff --git a/extension/fabric/FabricEnvironment.ts b/extension/fabric/FabricEnvironment.ts index 3defc3d5fa..858353b2b7 100644 --- a/extension/fabric/FabricEnvironment.ts +++ b/extension/fabric/FabricEnvironment.ts @@ -42,27 +42,36 @@ export class FabricEnvironment extends EventEmitter { } public async getNodes(withoutIdentitiies: boolean = false): Promise { - const nodesPath: string = path.resolve(this.path, 'nodes'); - const nodesExist: boolean = await fs.pathExists(nodesPath); - if (!nodesExist) { - return []; - } - let nodePaths: string[] = await fs.readdir(nodesPath); - nodePaths = nodePaths - .sort() - .filter((nodePath: string) => !nodePath.startsWith('.')) - .map((nodePath: string) => path.resolve(this.path, 'nodes', nodePath)); - const nodes: FabricNode[] = []; - for (const nodePath of nodePaths) { - const node: FabricNode = await fs.readJson(nodePath); - nodes.push(node); - } - - if (withoutIdentitiies) { - return nodes.filter((node: FabricNode) => (!node.wallet || !node.identity)); - } else { - return nodes; + const rootNodesPath: string = path.resolve(this.path, 'nodes'); + async function loadNodes(nodesPath: string): Promise { + const nodesExist: boolean = await fs.pathExists(nodesPath); + if (!nodesExist) { + return []; + } + let nodePaths: string[] = await fs.readdir(nodesPath); + nodePaths = nodePaths + .sort() + .filter((nodePath: string) => !nodePath.startsWith('.')) + .map((nodePath: string) => path.resolve(nodesPath, nodePath)); + const nodes: FabricNode[] = []; + for (const nodePath of nodePaths) { + const stats: fs.Stats = await fs.lstat(nodePath); + if (stats.isDirectory()) { + const subNodes: FabricNode[] = await loadNodes(nodePath); + nodes.push(...subNodes); + } else if (stats.isFile() && nodePath.endsWith('.json')) { + const node: FabricNode = await fs.readJson(nodePath); + nodes.push(node); + } + } + + if (withoutIdentitiies) { + return nodes.filter((node: FabricNode) => (!node.wallet || !node.identity)); + } else { + return nodes; + } } + return loadNodes(rootNodesPath); } public async updateNode(node: FabricNode): Promise { diff --git a/test/data/yofn/nodes/junkfile.bin b/test/data/yofn/nodes/junkfile.bin new file mode 100644 index 0000000000..fddce6f185 --- /dev/null +++ b/test/data/yofn/nodes/junkfile.bin @@ -0,0 +1,4 @@ +i am an orderer +and i'm hashing a block +hashy hashy block +hashy hashy block \ No newline at end of file diff --git a/test/data/yofn/nodes/orderer/junkfile.bin b/test/data/yofn/nodes/orderer/junkfile.bin new file mode 100644 index 0000000000..fddce6f185 --- /dev/null +++ b/test/data/yofn/nodes/orderer/junkfile.bin @@ -0,0 +1,4 @@ +i am an orderer +and i'm hashing a block +hashy hashy block +hashy hashy block \ No newline at end of file diff --git a/test/data/yofn/nodes/orderer.example.com.json b/test/data/yofn/nodes/orderer/orderer.example.com.json similarity index 100% rename from test/data/yofn/nodes/orderer.example.com.json rename to test/data/yofn/nodes/orderer/orderer.example.com.json diff --git a/test/data/yofn/nodes/ca.org1.example.com.json b/test/data/yofn/nodes/org1/ca.org1.example.com.json similarity index 100% rename from test/data/yofn/nodes/ca.org1.example.com.json rename to test/data/yofn/nodes/org1/ca.org1.example.com.json diff --git a/test/data/yofn/nodes/couchdb.json b/test/data/yofn/nodes/org1/couchdb.json similarity index 100% rename from test/data/yofn/nodes/couchdb.json rename to test/data/yofn/nodes/org1/couchdb.json diff --git a/test/data/yofn/nodes/org1/junkfile.bin b/test/data/yofn/nodes/org1/junkfile.bin new file mode 100644 index 0000000000..fddce6f185 --- /dev/null +++ b/test/data/yofn/nodes/org1/junkfile.bin @@ -0,0 +1,4 @@ +i am an orderer +and i'm hashing a block +hashy hashy block +hashy hashy block \ No newline at end of file diff --git a/test/data/yofn/nodes/peer0.org1.example.com.json b/test/data/yofn/nodes/org1/peer0.org1.example.com.json similarity index 100% rename from test/data/yofn/nodes/peer0.org1.example.com.json rename to test/data/yofn/nodes/org1/peer0.org1.example.com.json