Skip to content

Commit

Permalink
fix: delete commands
Browse files Browse the repository at this point in the history
Signed-off-by: Ivo Yankov <[email protected]>
  • Loading branch information
Ivo-Yankov committed Sep 20, 2024
1 parent 4016963 commit e9e1484
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 52 deletions.
35 changes: 16 additions & 19 deletions src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ export class NodeCommand extends BaseCommand {
flags.endpointType,
flags.localBuildPath,
flags.namespace,
flags.nodeID,
flags.releaseTag
]
}
Expand Down Expand Up @@ -1944,14 +1943,12 @@ export class NodeCommand extends BaseCommand {
return {
title: 'Load context data',
task: async (ctx, task) => {
if (argv.importCtxData) {
const inputDir = argv[flags.inputDir.name]
if (!inputDir) {
throw new FullstackTestingError(`Path to context data not specified. Please set a value for --${flags.inputDir.name}`)
}
const ctxData = JSON.parse(fs.readFileSync(path.join(inputDir, targetFile)))
parser(ctx, ctxData)
const inputDir = argv[flags.inputDir.name]
if (!inputDir) {
throw new FullstackTestingError(`Path to context data not specified. Please set a value for --${flags.inputDir.name}`)
}
const ctxData = JSON.parse(fs.readFileSync(path.join(inputDir, targetFile)))

Check warning on line 1950 in src/commands/node.mjs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/node.mjs#L1950

Detected possible user input going into a `path.join` or `path.resolve` function.
parser(ctx, ctxData)
}
}
}
Expand Down Expand Up @@ -2184,7 +2181,6 @@ export class NodeCommand extends BaseCommand {
async addSubmitTransactions (argv) {
const self = this

argv.importCtxData = true
const transactionTasks = this.getAddTransactionTasks(argv)
const tasks = new Listr([
self.addInitializeTask(argv),
Expand All @@ -2210,7 +2206,6 @@ export class NodeCommand extends BaseCommand {
async addExecute (argv) {
const self = this

argv.importCtxData = true
const executeTasks = this.getAddExecuteTasks(argv)
const tasks = new Listr([
self.addInitializeTask(argv),
Expand Down Expand Up @@ -2574,7 +2569,7 @@ export class NodeCommand extends BaseCommand {
.command({
command: 'delete',
desc: 'Delete a node with a specific version of Hedera platform',
builder: y => flags.setCommandFlags(y, ...NodeCommand.DELETE_FLAGS_LIST),
builder: y => flags.setCommandFlags(y, ...NodeCommand.DELETE_FLAGS_LIST.concat(flags.nodeID)),
handler: argv => {
nodeCmd.logger.debug('==== Running \'node delete\' ===')
nodeCmd.logger.debug(argv)
Expand All @@ -2591,7 +2586,7 @@ export class NodeCommand extends BaseCommand {
.command({
command: 'delete-prepare',
desc: 'Prepares the deletion of a node with a specific version of Hedera platform',
builder: y => flags.setCommandFlags(y, ...NodeCommand.DELETE_PREPARE_FLAGS_LIST),
builder: y => flags.setCommandFlags(y, ...NodeCommand.DELETE_PREPARE_FLAGS_LIST.concat(flags.nodeID)),
handler: argv => {
nodeCmd.logger.debug('==== Running \'node add\' ===')
nodeCmd.logger.debug(argv)
Expand Down Expand Up @@ -3118,13 +3113,15 @@ export class NodeCommand extends BaseCommand {
'freezeAdminPrivateKey',
'keysDir',
'nodeClient',
'nodeId',
'podNames',
'serviceMap',
'stagingDir',
'stagingKeysDir',
'treasuryKey'
])

config.nodeId = argv.nodeId
config.curDate = new Date()
config.existingNodeIds = []

Expand Down Expand Up @@ -3192,6 +3189,13 @@ export class NodeCommand extends BaseCommand {
const self = this

return [
{
title: 'Download generated files from an existing node',
task: async (ctx, task) => {
const config = /** @type {NodeDeleteConfigClass} **/ ctx.config
await this.downloadNodeGeneratedFiles(config)
}
},
{
title: 'Prepare staging directory',
task: async (ctx, parentTask) => {
Expand Down Expand Up @@ -3343,13 +3347,6 @@ export class NodeCommand extends BaseCommand {
await this.prepareUpgradeNetworkNodes(config.freezeAdminPrivateKey, ctx.upgradeZipHash, config.nodeClient)
}
},
{
title: 'Download generated files from an existing node',
task: async (ctx, task) => {
const config = /** @type {NodeDeleteConfigClass} **/ ctx.config
await this.downloadNodeGeneratedFiles(config)
}
},
{
title: 'Send freeze upgrade transaction',
task: async (ctx, task) => {
Expand Down
44 changes: 11 additions & 33 deletions src/core/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as semver from 'semver'
import { Templates } from './templates.mjs'
import { HEDERA_HAPI_PATH, ROOT_CONTAINER, SOLO_LOGS_DIR } from './constants.mjs'
import { constants } from './index.mjs'
import { FileContentsQuery, FileId } from '@hashgraph/sdk'
import {FileContentsQuery, FileId, PrivateKey} from '@hashgraph/sdk'

// cache current directory
const CUR_FILE_DIR = paths.dirname(fileURLToPath(import.meta.url))
Expand Down Expand Up @@ -419,22 +419,11 @@ export function addLoadContextParser (ctx, ctxData) {
export function deleteSaveContextParser (ctx) {
const exportedCtx = {}

const config = /** @type {NodeAddConfigClass} **/ ctx.config
const exportedFields = [
'tlsCertHash',
'upgradeZipHash',
'newNode'
]

exportedCtx.signingCertDer = ctx.signingCertDer.toString()
exportedCtx.gossipEndpoints = ctx.gossipEndpoints.map(ep => `${ep.getDomainName}:${ep.getPort}`)
exportedCtx.grpcServiceEndpoints = ctx.grpcServiceEndpoints.map(ep => `${ep.getDomainName}:${ep.getPort}`)
exportedCtx.adminKey = ctx.adminKey.toString()
const config = /** @type {NodeDeleteConfigClass} **/ ctx.config
exportedCtx.adminKey = config.adminKey.toString()
exportedCtx.existingNodeIds = config.existingNodeIds

for (const prop of exportedFields) {
exportedCtx[prop] = ctx[prop]
}
exportedCtx.upgradeZipHash = ctx.upgradeZipHash
exportedCtx.nodeId = config.nodeId
return exportedCtx
}

Expand All @@ -446,23 +435,12 @@ export function deleteSaveContextParser (ctx) {
* @returns file writable object
*/
export function deleteLoadContextParser (ctx, ctxData) {
const config = /** @type {NodeAddConfigClass} **/ ctx.config
ctx.signingCertDer = new Uint8Array(ctxData.signingCertDer.split(','))
ctx.gossipEndpoints = this.prepareEndpoints(ctx.config.endpointType, ctxData.gossipEndpoints, constants.HEDERA_NODE_INTERNAL_GOSSIP_PORT)
ctx.grpcServiceEndpoints = this.prepareEndpoints(ctx.config.endpointType, ctxData.grpcServiceEndpoints, constants.HEDERA_NODE_EXTERNAL_GOSSIP_PORT)
ctx.adminKey = PrivateKey.fromStringED25519(ctxData.adminKey)
config.nodeId = ctxData.newNode.name
const config = /** @type {NodeDeleteConfigClass} **/ ctx.config
config.adminKey = PrivateKey.fromStringED25519(ctxData.adminKey)
config.nodeId = ctxData.nodeId
config.existingNodeIds = ctxData.existingNodeIds
config.allNodeIds = [...config.existingNodeIds, ctxData.newNode.name]

const fieldsToImport = [
'tlsCertHash',
'upgradeZipHash',
'newNode'
]

for (const prop of fieldsToImport) {
ctx[prop] = ctxData[prop]
}
config.allNodeIds = ctxData.existingNodeIds
ctx.upgradeZipHash = ctxData.upgradeZipHash
config.podNames = {}
}

0 comments on commit e9e1484

Please sign in to comment.