From e796b52bdd211aa6a687117850f712fef9e7d3b2 Mon Sep 17 00:00:00 2001 From: Elena Izaguirre Date: Mon, 17 Jan 2022 08:11:29 +0100 Subject: [PATCH] feat(connector-corda): read privateKey from filesystem Allow plugin-ledger-connector-corda to read privateKey from filesystem instead of obtain it directly from corda-aiio container Relationed with #789 Signed-off-by: Elena Izaguirre --- .../plugin-ledger-connector-corda.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/plugin-ledger-connector-corda.ts b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/plugin-ledger-connector-corda.ts index 5796a889a0f..f480ec86793 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/plugin-ledger-connector-corda.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/main/typescript/plugin-ledger-connector-corda.ts @@ -45,6 +45,8 @@ import { DiagnoseNodeEndpointV1, } from "./web-services/diagnose-node-endpoint-v1"; +import fs from "fs"; + export interface IPluginLedgerConnectorCordaOptions extends ICactusPluginOptions { logLevel?: LogLevelDesc; @@ -54,6 +56,13 @@ export interface IPluginLedgerConnectorCordaOptions cordaStartCmd?: string; cordaStopCmd?: string; apiUrl?: string; + /** + * Path to the file where the private key for the ssh configuration is located + * This property is optional. Its use is not recommended for most cases, it will override the privateKey property of the sshConfigAdminShell. + * @type {string} + * @memberof IPluginLedgerConnectorCordaOptions + */ + sshPrivateKeyPath?: string; } export class PluginLedgerConnectorCorda @@ -91,6 +100,8 @@ export class PluginLedgerConnectorCorda `${fnTag} options.prometheusExporter`, ); this.prometheusExporter.startMetricsCollection(); + // if privateKeyPath exists, overwrite privateKey in sshConfigAdminShell + this.readSshPrivateKeyFromFile(); } public getOpenApiSpec(): unknown { @@ -146,6 +157,16 @@ export class PluginLedgerConnectorCorda return webServices; } + private readSshPrivateKeyFromFile(): void { + const { sshPrivateKeyPath } = this.options; + if (sshPrivateKeyPath) { + const fileContent = fs + .readFileSync(sshPrivateKeyPath, "utf-8") + .toString(); + this.options.sshConfigAdminShell.privateKey = fileContent; + } + } + public async getOrCreateWebServices(): Promise { if (Array.isArray(this.endpoints)) { return this.endpoints;