Skip to content

Commit

Permalink
refactored to extract methods for TODO
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Jan 7, 2025
1 parent 214fe28 commit 754ac73
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
39 changes: 30 additions & 9 deletions src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,19 +872,13 @@ export class NodeCommandTasks {

setupNetworkNodes(nodeAliasesProperty: string) {
return new Task('Setup network nodes', async (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
// TODO extract method
const networkNodeServiceMap = await this.accountManager.getNodeServiceMap(ctx.config.namespace);

const genesisNetworkData = await GenesisNetworkDataConstructor.initialize(
await this.generateGenesisNetworkJson(
ctx.config.namespace,
ctx.config.nodeAliases,
this.keyManager,
ctx.config.keysDir,
networkNodeServiceMap,
ctx.config.stagingDir,
);

const genesisNetworkJson = path.join(ctx.config.stagingDir, 'genesis-network.json');
fs.writeFileSync(genesisNetworkJson, genesisNetworkData.toJSON());

const subTasks = [];
for (const nodeAlias of ctx.config[nodeAliasesProperty]) {
const podName = ctx.config.podNames[nodeAlias];
Expand All @@ -902,6 +896,33 @@ export class NodeCommandTasks {
});
}

/**
* Generate genesis network json file
* @private
* @param namespace - namespace
* @param nodeAliases - node aliases
* @param keysDir - keys directory
* @param stagingDir - staging directory
*/
private async generateGenesisNetworkJson(
namespace: string,
nodeAliases: NodeAliases,
keysDir: string,
stagingDir: string,
) {
const networkNodeServiceMap = await this.accountManager.getNodeServiceMap(namespace);

const genesisNetworkData = await GenesisNetworkDataConstructor.initialize(
nodeAliases,
this.keyManager,
keysDir,
networkNodeServiceMap,
);

const genesisNetworkJson = path.join(stagingDir, 'genesis-network.json');

Check warning on line 922 in src/commands/node/tasks.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/node/tasks.ts#L922

Detected possible user input going into a `path.join` or `path.resolve` function.
fs.writeFileSync(genesisNetworkJson, genesisNetworkData.toJSON());

Check warning on line 923 in src/commands/node/tasks.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/node/tasks.ts#L923

The application dynamically constructs file or path information.
}

prepareStagingDirectory(nodeAliasesProperty: any) {
return new Task('Prepare staging directory', (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
const config = ctx.config;
Expand Down
14 changes: 12 additions & 2 deletions src/core/platform_installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ export class PlatformInstaller {
{
title: 'Copy configuration files',
task: async () => {
const genesisNetworkJson = [path.join(stagingDir, 'genesis-network.json')];
await self.copyFiles(podName, genesisNetworkJson, `${constants.HEDERA_HAPI_PATH}/data/config`);
await this.copyConfigurationFiles(stagingDir, podName);
},
},
{
Expand All @@ -303,6 +302,17 @@ export class PlatformInstaller {
);
}

/**
* Copy configuration files to the network consensus node pod
* @param stagingDir - staging directory path
* @param podName - network consensus node pod name
* @private
*/
private async copyConfigurationFiles(stagingDir: string, podName: `network-node${number}-0`) {
const genesisNetworkJson = [path.join(stagingDir, 'genesis-network.json')];

Check warning on line 312 in src/core/platform_installer.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/core/platform_installer.ts#L312

Detected possible user input going into a `path.join` or `path.resolve` function.
await this.copyFiles(podName, genesisNetworkJson, `${constants.HEDERA_HAPI_PATH}/data/config`);
}

/**
* Return a list of task to copy the node keys to the staging directory
*
Expand Down

0 comments on commit 754ac73

Please sign in to comment.