Skip to content

Commit 70a4716

Browse files
committed
moved taskGenerateTLSKeys from node.mjs to key_manager.mjs
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent e4f8b4d commit 70a4716

File tree

2 files changed

+45
-46
lines changed

2 files changed

+45
-46
lines changed

src/commands/node.mjs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -315,49 +315,6 @@ export class NodeCommand extends BaseCommand {
315315
})
316316
}
317317

318-
/**
319-
* Return a list of subtasks to generate gRPC TLS keys
320-
*
321-
* WARNING: These tasks should run in sequence
322-
*
323-
* @param nodeIds node ids
324-
* @param keysDir keys directory
325-
* @param curDate current date
326-
* @return return a list of subtasks
327-
* @private
328-
*/
329-
// TODO move to KeyManager
330-
taskGenerateTLSKeys (nodeIds, keysDir, curDate = new Date()) {
331-
// check if nodeIds is an array of strings
332-
if (!Array.isArray(nodeIds) || !nodeIds.every((nodeId) => typeof nodeId === 'string')) {
333-
throw new FullstackTestingError('nodeIds must be an array of strings')
334-
}
335-
const self = this
336-
const nodeKeyFiles = new Map()
337-
const subTasks = []
338-
339-
subTasks.push({
340-
title: 'Backup old files',
341-
task: () => helpers.backupOldTlsKeys(nodeIds, keysDir, curDate)
342-
}
343-
)
344-
345-
for (const nodeId of nodeIds) {
346-
subTasks.push({
347-
title: `TLS key for node: ${chalk.yellow(nodeId)}`,
348-
task: async () => {
349-
const tlsKey = await self.keyManager.generateGrpcTLSKey(nodeId)
350-
const tlsKeyFiles = await self.keyManager.storeTLSKey(nodeId, tlsKey, keysDir)
351-
nodeKeyFiles.set(nodeId, {
352-
tlsKeyFiles
353-
})
354-
}
355-
})
356-
}
357-
358-
return subTasks
359-
}
360-
361318
// TODO: duplicate into network deploy
362319
async initializeSetup (config, k8) {
363320
// compute other config parameters
@@ -662,7 +619,7 @@ export class NodeCommand extends BaseCommand {
662619
title: 'Generate gRPC TLS keys',
663620
task: async (ctx, parentTask) => {
664621
const config = ctx.config
665-
const subTasks = self.taskGenerateTLSKeys(config.nodeIds, config.keysDir, config.curDate)
622+
const subTasks = self.keyManager.taskGenerateTLSKeys(config.nodeIds, config.keysDir, config.curDate)
666623
// set up the sub-tasks
667624
return parentTask.newListr(subTasks, {
668625
concurrent: false,
@@ -1038,7 +995,7 @@ export class NodeCommand extends BaseCommand {
1038995
title: 'Generate gRPC TLS keys',
1039996
task: async (ctx, parentTask) => {
1040997
const config = ctx.config
1041-
const subTasks = self.taskGenerateTLSKeys(config.nodeIds, config.keysDir, config.curDate)
998+
const subTasks = self.keyManager.taskGenerateTLSKeys(config.nodeIds, config.keysDir, config.curDate)
1042999
// set up the sub-tasks
10431000
return parentTask.newListr(subTasks, {
10441001
concurrent: true,
@@ -1502,7 +1459,7 @@ export class NodeCommand extends BaseCommand {
15021459
title: 'Generate gRPC TLS key',
15031460
task: async (ctx, parentTask) => {
15041461
const config = /** @type {NodeAddConfigClass} **/ ctx.config
1505-
const subTasks = self.taskGenerateTLSKeys([config.nodeId], config.keysDir, config.curDate)
1462+
const subTasks = self.keyManager.taskGenerateTLSKeys([config.nodeId], config.keysDir, config.curDate)
15061463
// set up the sub-tasks
15071464
return parentTask.newListr(subTasks, {
15081465
concurrent: false,

src/core/key_manager.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,4 +807,46 @@ export class KeyManager {
807807

808808
return subTasks
809809
}
810+
811+
/**
812+
* Return a list of subtasks to generate gRPC TLS keys
813+
*
814+
* WARNING: These tasks should run in sequence
815+
*
816+
* @param nodeIds node ids
817+
* @param keysDir keys directory
818+
* @param curDate current date
819+
* @return return a list of subtasks
820+
* @private
821+
*/
822+
taskGenerateTLSKeys (nodeIds, keysDir, curDate = new Date()) {
823+
// check if nodeIds is an array of strings
824+
if (!Array.isArray(nodeIds) || !nodeIds.every((nodeId) => typeof nodeId === 'string')) {
825+
throw new FullstackTestingError('nodeIds must be an array of strings')
826+
}
827+
const self = this
828+
const nodeKeyFiles = new Map()
829+
const subTasks = []
830+
831+
subTasks.push({
832+
title: 'Backup old files',
833+
task: () => helpers.backupOldTlsKeys(nodeIds, keysDir, curDate)
834+
}
835+
)
836+
837+
for (const nodeId of nodeIds) {
838+
subTasks.push({
839+
title: `TLS key for node: ${chalk.yellow(nodeId)}`,
840+
task: async () => {
841+
const tlsKey = await self.generateGrpcTLSKey(nodeId)
842+
const tlsKeyFiles = await self.storeTLSKey(nodeId, tlsKey, keysDir)
843+
nodeKeyFiles.set(nodeId, {
844+
tlsKeyFiles
845+
})
846+
}
847+
})
848+
}
849+
850+
return subTasks
851+
}
810852
}

0 commit comments

Comments
 (0)