Skip to content

Commit

Permalink
feat(connector-corda): read privateKey from filesystem
Browse files Browse the repository at this point in the history
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 <e.izaguirre.equiza@accenture.com>
  • Loading branch information
elenaizaguirre authored and petermetz committed Jan 18, 2022
1 parent 334593a commit e7e39fd
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import {
DiagnoseNodeEndpointV1,
} from "./web-services/diagnose-node-endpoint-v1";

import fs from "fs";

export interface IPluginLedgerConnectorCordaOptions
extends ICactusPluginOptions {
logLevel?: LogLevelDesc;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<IWebServiceEndpoint[]> {
if (Array.isArray(this.endpoints)) {
return this.endpoints;
Expand Down

0 comments on commit e7e39fd

Please sign in to comment.