From e957497c2140fb897c9100e5c83e77e3e298e78e Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Fri, 7 Jan 2022 01:33:40 -0800 Subject: [PATCH 1/3] CRC commands does not work in case of full path has spaces This PR fixes #2319. Signed-off-by: Denis Golovin dgolovin@redhat.com --- package-lock.json | 21 +++----- package.json | 6 +++ src/webview/cluster/app/clusterView.tsx | 47 +++++++++++++---- src/webview/cluster/clusterViewLoader.ts | 66 ++++++++++++++---------- 4 files changed, 90 insertions(+), 50 deletions(-) diff --git a/package-lock.json b/package-lock.json index 375f1d582..70137363d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59,7 +59,7 @@ "@types/targz": "^1.0.1", "@types/tmp": "0.2.2", "@types/validator": "^13.7.0", - "@types/vscode": "^1.62.0", + "@types/vscode": "1.62.0", "@typescript-eslint/eslint-plugin": "^5.6.0", "@typescript-eslint/parser": "^5.6.0", "babel-loader": "^8.2.3", @@ -2059,8 +2059,6 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.8.2.tgz", "integrity": "sha512-x9VuX+R/jcFj1DHo/fCp99esgGDWiHENrKxaCENuCxpoMCmAt/COCGVDwA7kleEpEzJjDnvh3yGoOuLu0Dtllw==", "dev": true, - "optional": true, - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", @@ -2076,9 +2074,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true, - "optional": true, - "peer": true + "dev": true }, "node_modules/ajv-keywords": { "version": "3.5.2", @@ -16219,14 +16215,15 @@ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", "dev": true, - "requires": {}, + "requires": { + "ajv": "^8.0.0" + }, "dependencies": { "ajv": { - "version": "https://registry.npmjs.org/ajv/-/ajv-8.8.2.tgz", + "version": "8.8.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.8.2.tgz", "integrity": "sha512-x9VuX+R/jcFj1DHo/fCp99esgGDWiHENrKxaCENuCxpoMCmAt/COCGVDwA7kleEpEzJjDnvh3yGoOuLu0Dtllw==", "dev": true, - "optional": true, - "peer": true, "requires": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", @@ -16238,9 +16235,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true, - "optional": true, - "peer": true + "dev": true } } }, diff --git a/package.json b/package.json index 8b98bd3ed..a7307f176 100644 --- a/package.json +++ b/package.json @@ -1574,6 +1574,12 @@ "type": "number", "default": 9216, "description": "MiB of memory to allocate to the OpenShift cluster as selected during the first run" + }, + "openshiftConnector.crcNameserver": { + "Title": "CRC Domain Name Server", + "type": "strint", + "default": "", + "description": "IP address/name of DNS to use with CRC" } } } diff --git a/src/webview/cluster/app/clusterView.tsx b/src/webview/cluster/app/clusterView.tsx index 268ffd6b4..7ad12fabd 100644 --- a/src/webview/cluster/app/clusterView.tsx +++ b/src/webview/cluster/app/clusterView.tsx @@ -78,7 +78,9 @@ export default function addClusterView(props) { const [statusError, setStatusError] = React.useState(false); React.useEffect(() => { - props.vscode.postMessage({action: 'checksetting'}); + props.vscode.postMessage({ + action: 'checksetting' + }); }, []); const steps = getSteps(); @@ -168,14 +170,18 @@ export default function addClusterView(props) { setProgress(true); setCrcStartError(false); if (settingPresent) { - props.vscode.postMessage({action: 'crcStart', isSetting: true }); + props.vscode.postMessage({ + action: 'crcStart', isSetting: true + }); } else { - const crcStartCommand = (crcNameserver === '') ? `${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -ojson`: - `${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -n ${crcNameserver} -ojson`; + const nameServerOpt = crcNameserver ? `-n ${crcNameserver}` : ''; props.vscode.postMessage({ action: 'crcStart', - data: crcStartCommand, + data: { + tool: fileName, + options: `start -p "${pullSecretPath}" -c ${cpuSize} -m ${memory} ${nameServerOpt} -o json` + }, pullSecret: pullSecretPath, crcLoc: fileName, cpuSize, @@ -220,23 +226,44 @@ export default function addClusterView(props) { const handleStopProcess = () => { setStopProgress(true); setCrcStopError(false); - props.vscode.postMessage({action: 'crcStop', data: `${fileName}`}); + props.vscode.postMessage({ + action: 'crcStop', + data: { + tool: fileName + } + }); } const handleCrcSetup = () => { - props.vscode.postMessage({action: 'crcSetup', data: `${fileName}` }) + props.vscode.postMessage({ + action: 'crcSetup', + data: { + tool: fileName + } + }) } const handleCrcLogin = (loginDetails, clusterUrl) => { - props.vscode.postMessage({action: 'crcLogin', data: loginDetails, url: clusterUrl }) + props.vscode.postMessage({ + action: 'crcLogin', + data: loginDetails, + url: clusterUrl + }) } const handleRefresh = () => { setStatusSkeleton(true); if (settingPresent) { - props.vscode.postMessage({action: 'checksetting'}); + props.vscode.postMessage({ + action: 'checksetting' + }); } else { - props.vscode.postMessage({action: 'checkcrcstatus', data: `${fileName}`}); + props.vscode.postMessage({ + action: 'checkcrcstatus', + data: { + tool: fileName + } + }); } } diff --git a/src/webview/cluster/clusterViewLoader.ts b/src/webview/cluster/clusterViewLoader.ts index 3ab327285..b346afc79 100644 --- a/src/webview/cluster/clusterViewLoader.ts +++ b/src/webview/cluster/clusterViewLoader.ts @@ -99,7 +99,7 @@ export default class ClusterViewLoader { @vsCommand('openshift.explorer.addCluster.crcSetup') static async crcSetup(event: any) { const terminal: vscode.Terminal = WindowUtil.createTerminal('OpenShift: CRC Setup', undefined); - terminal.sendText(`${event.data} setup`); + terminal.sendText(`"${event.data.tool}" setup`); terminal.show(); } @@ -112,13 +112,15 @@ export default class ClusterViewLoader { const pullSecretFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcPullSecretPath'); const cpuFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcCpuCores'); const memoryFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcMemoryAllocated'); - const crcOptions = ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, '-ojson']; + const nameserver = vscode.workspace.getConfiguration('openshiftConnector').get('crcNameserver'); + const nameserverOption = nameserver ? ['-n', nameserver] : []; + const crcOptions = ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, ...nameserverOption, '-ojson']; + startProcess = spawn(`${binaryFromSetting}`, crcOptions); - channel.append(`\n\n${binaryFromSetting} ${crcOptions.join(' ')}\n`); + channel.append(`\n\n"${binaryFromSetting}" ${crcOptions.join(' ')}\n`); } else { - const [tool, ...params] = event.data.split(' '); - startProcess = spawn(tool, params); - channel.append(`\n\n${tool} ${params.join(' ')}\n`); + startProcess = spawn(`${event.data.tool}`, event.data.options.split(' ')); + channel.append(`\n\n"${event.data.tool}" ${event.data.options}\n`); } startProcess.stdout.setEncoding('utf8'); startProcess.stderr.setEncoding('utf8'); @@ -137,32 +139,42 @@ export default class ClusterViewLoader { const binaryLoc = event.isSetting ? vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation'): event.crcLoc; ClusterViewLoader.checkCrcStatus(binaryLoc, 'crcstartstatus', panel); }); + startProcess.on('error', (err) => { + console.log(err); + }); } @vsCommand('openshift.explorer.addCluster.crcStop') static async crcStop(event) { let filePath: string; channel.show(); - if (event.data === '') { + if (event.data.tool === '') { filePath = vscode.workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation'); } else { - filePath = event.data; + filePath = event.data.tool; + } + try { + const stopProcess = spawn(`${filePath}`, ['stop']); + channel.append(`\n\n"${filePath}" stop\n`); + stopProcess.stdout.setEncoding('utf8'); + stopProcess.stderr.setEncoding('utf8'); + stopProcess.stdout.on('data', (chunk) => { + channel.append(chunk); + }); + stopProcess.stderr.on('data', (chunk) => { + channel.append(chunk); + }); + stopProcess.on('close', (code) => { + // eslint-disable-next-line no-console + console.log(`crc stop exited with code ${code}`); + ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel); + }); + stopProcess.on('error', (err) => { + console.log(err); + }); + } catch(err) { + console.log(err); } - const stopProcess = spawn(`${filePath}`, ['stop']); - channel.append(`\n\n$${filePath} stop\n`); - stopProcess.stdout.setEncoding('utf8'); - stopProcess.stderr.setEncoding('utf8'); - stopProcess.stdout.on('data', (chunk) => { - channel.append(chunk); - }); - stopProcess.stderr.on('data', (chunk) => { - channel.append(chunk); - }); - stopProcess.on('close', (code) => { - // eslint-disable-next-line no-console - console.log(`crc stop exited with code ${code}`); - ClusterViewLoader.checkCrcStatus(filePath, 'crcstopstatus', panel); - }); } static async crcSaveSettings(event) { @@ -199,11 +211,11 @@ export default class ClusterViewLoader { public static async checkCrcStatus(filePath: string, postCommand: string, p: vscode.WebviewPanel | undefined = undefined) { const crcCredArray = []; - const crcVerInfo = await CliChannel.getInstance().execute(`${filePath} version -ojson`); - channel.append(`\n\n${filePath} version -ojson\n`); + const crcVerInfo = await CliChannel.getInstance().execute(`"${filePath}" version -ojson`); + channel.append(`\n\n"${filePath}" version -ojson\n`); channel.append(crcVerInfo.stdout); - const result = await CliChannel.getInstance().execute(`${filePath} status -ojson`); - channel.append(`\n\n${filePath} status -ojson\n`); + const result = await CliChannel.getInstance().execute(`"${filePath}" status -ojson`); + channel.append(`\n\n"${filePath}" status -ojson\n`); channel.append(result.stdout); if (result.error || crcVerInfo.error) { p.webview.postMessage({action: postCommand, errorStatus: true}); From 51d35d547055503db28573f75f99c83fb3c7f30f Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Fri, 7 Jan 2022 20:19:40 -0800 Subject: [PATCH 2/3] Add double quotes when calling crc commands Signed-off-by: Denis Golovin dgolovin@redhat.com --- src/webview/cluster/clusterViewLoader.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/webview/cluster/clusterViewLoader.ts b/src/webview/cluster/clusterViewLoader.ts index b346afc79..0d3a2a654 100644 --- a/src/webview/cluster/clusterViewLoader.ts +++ b/src/webview/cluster/clusterViewLoader.ts @@ -114,7 +114,7 @@ export default class ClusterViewLoader { const memoryFromSetting = vscode.workspace.getConfiguration('openshiftConnector').get('crcMemoryAllocated'); const nameserver = vscode.workspace.getConfiguration('openshiftConnector').get('crcNameserver'); const nameserverOption = nameserver ? ['-n', nameserver] : []; - const crcOptions = ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, ...nameserverOption, '-ojson']; + const crcOptions = ['start', '-p', `${pullSecretFromSetting}`, '-c', `${cpuFromSetting}`, '-m', `${memoryFromSetting}`, ...nameserverOption, '-o json']; startProcess = spawn(`${binaryFromSetting}`, crcOptions); channel.append(`\n\n"${binaryFromSetting}" ${crcOptions.join(' ')}\n`); @@ -211,11 +211,11 @@ export default class ClusterViewLoader { public static async checkCrcStatus(filePath: string, postCommand: string, p: vscode.WebviewPanel | undefined = undefined) { const crcCredArray = []; - const crcVerInfo = await CliChannel.getInstance().execute(`"${filePath}" version -ojson`); - channel.append(`\n\n"${filePath}" version -ojson\n`); + const crcVerInfo = await CliChannel.getInstance().execute(`"${filePath}" version -o json`); + channel.append(`\n\n"${filePath}" version -o json\n`); channel.append(crcVerInfo.stdout); - const result = await CliChannel.getInstance().execute(`"${filePath}" status -ojson`); - channel.append(`\n\n"${filePath}" status -ojson\n`); + const result = await CliChannel.getInstance().execute(`"${filePath}" status -o json`); + channel.append(`\n\n"${filePath}" status -o json\n`); channel.append(result.stdout); if (result.error || crcVerInfo.error) { p.webview.postMessage({action: postCommand, errorStatus: true}); @@ -228,7 +228,7 @@ export default class ClusterViewLoader { creds: crcCredArray }); } - const crcCreds = await CliChannel.getInstance().execute(`${filePath} console --credentials -ojson`); + const crcCreds = await CliChannel.getInstance().execute(`"${filePath}" console --credentials -o json`); if (!crcCreds.error) { try { crcCredArray.push(JSON.parse(crcCreds.stdout).clusterConfig); From 117ab9c4d2ba24679cf62eac082e8a7f23be4ca9 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Fri, 7 Jan 2022 23:48:58 -0800 Subject: [PATCH 3/3] Fix typo in setting typeconfiguration property type Signed-off-by: Denis Golovin dgolovin@redhat.com --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a7307f176..c1141cc94 100644 --- a/package.json +++ b/package.json @@ -1577,7 +1577,7 @@ }, "openshiftConnector.crcNameserver": { "Title": "CRC Domain Name Server", - "type": "strint", + "type": "string", "default": "", "description": "IP address/name of DNS to use with CRC" }