diff --git a/src/commands/base.mjs b/src/commands/base.mjs index c6fa118ad..e4e4f18ee 100644 --- a/src/commands/base.mjs +++ b/src/commands/base.mjs @@ -65,14 +65,14 @@ export class BaseCommand extends ShellRunner { let error = null try { - this.logger.debug(`==== Start: '${argv._.join(' ')}' ===`) + this.logger.debug(`==== Start: '${argv._.join(' ')}' ===`, { config: this.configManager.config, argv }) await ConfigManager.acquireProcessLock(this.logger) await handleFunc(argv) } catch (e) { error = new FullstackTestingError(`Error occurred: ${e.message}`, e) } finally { await ConfigManager.releaseProcessLock(this.logger) - this.logger.debug(`==== End: '${argv._.join(' ')}' ===`) + this.logger.debug(`==== End: '${argv._.join(' ')}' ===`, { config: this.configManager.config, argv }) } if (error) { diff --git a/src/core/config_manager.mjs b/src/core/config_manager.mjs index 8202ea364..b873e29f4 100644 --- a/src/core/config_manager.mjs +++ b/src/core/config_manager.mjs @@ -116,7 +116,7 @@ export class ConfigManager { case 'string': if (flag.name === flags.chartDirectory.name || flag.name === flags.cacheDir.name) { this.logger.debug(`Resolving directory path for '${flag.name}': ${val}`) - val = path.resolve(val) + val = path.resolve(path.normalize(val)) } this.logger.debug(`Setting flag '${flag.name}' of type '${flag.definition.type}': ${val}`) this.config.flags[flag.name] = `${val}` // force convert to string @@ -156,6 +156,8 @@ export class ConfigManager { if (persist) { this.persist() } + + this.logger.debug('Updated cached config', { argv, config: this.config }) } } @@ -235,18 +237,18 @@ export class ConfigManager { */ static acquireProcessLock (logger) { const pid = process.pid.toString() - - if (!fs.existsSync(constants.SOLO_PID_FILE)) { - fs.writeFileSync(constants.SOLO_PID_FILE, pid) + const pidFile = path.normalize(constants.SOLO_PID_FILE) + if (!fs.existsSync(pidFile)) { + fs.writeFileSync(pidFile, pid) logger.debug(`Acquired process lock '${pid}'`, { - pidFile: constants.SOLO_PID_FILE, + pidFile, pid }) return true } // pid lock exists - const existingPid = fs.readFileSync(constants.SOLO_PID_FILE).toString() + const existingPid = fs.readFileSync(pidFile).toString() logger.showUserError(new FullstackTestingError(`Process lock exists: ${constants.SOLO_PID_FILE}` + `\nEnsure process '${existingPid}' is not running [ ps -p ${existingPid} ]`)) process.exit(1) @@ -262,20 +264,21 @@ export class ConfigManager { * @return {Promise} */ static releaseProcessLock (logger) { - if (fs.existsSync(constants.SOLO_PID_FILE)) { - const existingPid = fs.readFileSync(constants.SOLO_PID_FILE).toString() + const pidFile = path.normalize(constants.SOLO_PID_FILE) + if (fs.existsSync(pidFile)) { + const existingPid = fs.readFileSync(pidFile).toString() const pid = process.pid.toString() if (existingPid === process.pid.toString()) { logger.debug(`Releasing process lock '${pid}'`, { - pidFile: constants.SOLO_PID_FILE, + pidFile, pid }) - fs.rmSync(constants.SOLO_PID_FILE) + fs.rmSync(pidFile) } else { logger.warn(`Unable to release process lock '${pid}'.\nEnsure process '${existingPid}' is not running [ps -p ${existingPid}]`, { - pidFile: constants.SOLO_PID_FILE, + pidFile, pid, existingPid }) diff --git a/src/core/constants.mjs b/src/core/constants.mjs index 1a39a49d6..c03b5bdfb 100644 --- a/src/core/constants.mjs +++ b/src/core/constants.mjs @@ -20,20 +20,29 @@ import * as path from 'path' import { fileURLToPath } from 'url' import chalk from 'chalk' +function sanitizePath (p) { + if (!p.startsWith(process.env.HOME)) { + console.log(`Path must starts with '${process.env.HOME}', found '${p}'`) + process.exit(1) + } + + return path.resolve(path.normalize(p)) +} + // -------------------- solo related constants --------------------------------------------------------------------- export const CUR_FILE_DIR = path.dirname(fileURLToPath(import.meta.url)) export const USER = `${process.env.USER}` // force it to be a string export const USER_SANITIZED = USER.replace(/[\W_]+/g, '-') -export const SOLO_HOME_DIR = path.join(process.env.HOME, '.solo') -export const SOLO_LOGS_DIR = path.join(SOLO_HOME_DIR, 'logs') +export const SOLO_HOME_DIR = sanitizePath(path.join(process.env.HOME, '.solo')) +export const SOLO_LOGS_DIR = sanitizePath(path.join(SOLO_HOME_DIR, 'logs')) -export const SOLO_PID_FILE = path.join(SOLO_HOME_DIR, 'solo.pid') -export const SOLO_CACHE_DIR = path.join(SOLO_HOME_DIR, 'cache') +export const SOLO_PID_FILE = sanitizePath(path.join(SOLO_HOME_DIR, 'solo.pid')) +export const SOLO_CACHE_DIR = sanitizePath(path.join(SOLO_HOME_DIR, 'cache')) export const DEFAULT_NAMESPACE = 'default' export const HELM = 'helm' export const CWD = process.cwd() -export const SOLO_CONFIG_FILE = path.join(SOLO_HOME_DIR, 'solo.config') -export const RESOURCES_DIR = path.normalize(path.join(CUR_FILE_DIR, '/../../resources')) +export const SOLO_CONFIG_FILE = sanitizePath(path.join(SOLO_HOME_DIR, 'solo.config')) +export const RESOURCES_DIR = sanitizePath(path.join(CUR_FILE_DIR, '/../../resources')) export const ROOT_CONTAINER = 'root-container'