Skip to content

Commit 426e8f3

Browse files
committed
moved copyGossipKeysToStaging from node.mjs to key_manager.mjs
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent b76fbf9 commit 426e8f3

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

src/commands/node.mjs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ export class NodeCommand extends BaseCommand {
456456
return subTasks
457457
}
458458

459-
// TODO: move to KeyManager
459+
// TODO: duplicate into network deploy
460460
async initializeSetup (config, k8) {
461461
// compute other config parameters
462462
config.keysDir = path.join(validatePath(config.cacheDir), 'keys')
@@ -781,7 +781,7 @@ export class NodeCommand extends BaseCommand {
781781
title: 'Copy Gossip keys to staging',
782782
task: async (ctx, _) => {
783783
const config = /** @type {NodeSetupConfigClass} **/ ctx.config
784-
await this.copyGossipKeysToStaging(config.keyFormat, config.keysDir, config.stagingKeysDir, ctx.config.nodeIds)
784+
await this.keyManager.copyGossipKeysToStaging(config.keyFormat, config.keysDir, config.stagingKeysDir, ctx.config.nodeIds)
785785
}
786786
},
787787
{
@@ -1868,7 +1868,7 @@ export class NodeCommand extends BaseCommand {
18681868
task: async (ctx, _) => {
18691869
const config = /** @type {NodeAddConfigClass} **/ ctx.config
18701870

1871-
await this.copyGossipKeysToStaging(config.keyFormat, config.keysDir, config.stagingKeysDir, config.allNodeIds)
1871+
await this.keyManager.copyGossipKeysToStaging(config.keyFormat, config.keysDir, config.stagingKeysDir, config.allNodeIds)
18721872
}
18731873
},
18741874
{
@@ -2133,34 +2133,6 @@ export class NodeCommand extends BaseCommand {
21332133
}
21342134
}
21352135

2136-
// TODO: move to KeyManager
2137-
async copyGossipKeysToStaging (keyFormat, keysDir, stagingKeysDir, nodeIds) {
2138-
// copy gossip keys to the staging
2139-
for (const nodeId of nodeIds) {
2140-
switch (keyFormat) {
2141-
case constants.KEY_FORMAT_PEM: {
2142-
const signingKeyFiles = this.keyManager.prepareNodeKeyFilePaths(nodeId, keysDir, constants.SIGNING_KEY_PREFIX)
2143-
await this.keyManager.copyNodeKeysToStaging(signingKeyFiles, stagingKeysDir)
2144-
2145-
// generate missing agreement keys
2146-
const agreementKeyFiles = this.keyManager.prepareNodeKeyFilePaths(nodeId, keysDir, constants.AGREEMENT_KEY_PREFIX)
2147-
await this.keyManager.copyNodeKeysToStaging(agreementKeyFiles, stagingKeysDir)
2148-
break
2149-
}
2150-
2151-
case constants.KEY_FORMAT_PFX: {
2152-
const privateKeyFile = Templates.renderGossipPfxPrivateKeyFile(nodeId)
2153-
fs.cpSync(path.join(keysDir, privateKeyFile), path.join(stagingKeysDir, privateKeyFile))
2154-
fs.cpSync(path.join(keysDir, constants.PUBLIC_PFX), path.join(stagingKeysDir, constants.PUBLIC_PFX))
2155-
break
2156-
}
2157-
2158-
default:
2159-
throw new FullstackTestingError(`Unsupported key-format ${keyFormat}`)
2160-
}
2161-
}
2162-
}
2163-
21642136
// Command Definition
21652137
/**
21662138
* Return Yargs command definition for 'node' command

src/core/key_manager.mjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,4 +677,31 @@ export class KeyManager {
677677
fs.cpSync(keyFile, path.join(destDir, fileName))
678678
}
679679
}
680+
681+
async copyGossipKeysToStaging (keyFormat, keysDir, stagingKeysDir, nodeIds) {
682+
// copy gossip keys to the staging
683+
for (const nodeId of nodeIds) {
684+
switch (keyFormat) {
685+
case constants.KEY_FORMAT_PEM: {
686+
const signingKeyFiles = this.prepareNodeKeyFilePaths(nodeId, keysDir, constants.SIGNING_KEY_PREFIX)
687+
await this.copyNodeKeysToStaging(signingKeyFiles, stagingKeysDir)
688+
689+
// generate missing agreement keys
690+
const agreementKeyFiles = this.prepareNodeKeyFilePaths(nodeId, keysDir, constants.AGREEMENT_KEY_PREFIX)
691+
await this.copyNodeKeysToStaging(agreementKeyFiles, stagingKeysDir)
692+
break
693+
}
694+
695+
case constants.KEY_FORMAT_PFX: {
696+
const privateKeyFile = Templates.renderGossipPfxPrivateKeyFile(nodeId)
697+
fs.cpSync(path.join(keysDir, privateKeyFile), path.join(stagingKeysDir, privateKeyFile))
698+
fs.cpSync(path.join(keysDir, constants.PUBLIC_PFX), path.join(stagingKeysDir, constants.PUBLIC_PFX))
699+
break
700+
}
701+
702+
default:
703+
throw new FullstackTestingError(`Unsupported key-format ${keyFormat}`)
704+
}
705+
}
706+
}
680707
}

0 commit comments

Comments
 (0)