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 hyperledger-cacti#789

Signed-off-by: Elena Izaguirre <e.izaguirre.equiza@accenture.com>
  • Loading branch information
elenaizaguirre committed Jan 12, 2022
1 parent 15d4793 commit a35b344
Showing 1 changed file with 13 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,7 @@ export interface IPluginLedgerConnectorCordaOptions
cordaStartCmd?: string;
cordaStopCmd?: string;
apiUrl?: string;
privateKeyPath?: string;
}

export class PluginLedgerConnectorCorda
Expand Down Expand Up @@ -91,6 +94,8 @@ export class PluginLedgerConnectorCorda
`${fnTag} options.prometheusExporter`,
);
this.prometheusExporter.startMetricsCollection();
// if privateKeyPath exists, overwrite privateKey in sshConfigAdminShell
this.readPrivateKey();
}

public getOpenApiSpec(): unknown {
Expand Down Expand Up @@ -146,6 +151,14 @@ export class PluginLedgerConnectorCorda
return webServices;
}

private readPrivateKey(): void {
const { privateKeyPath } = this.options;
if (privateKeyPath) {
const fileContent = fs.readFileSync(privateKeyPath, "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 a35b344

Please sign in to comment.