From bb84cc0800ac0d0c992a64cdd796466050b367af Mon Sep 17 00:00:00 2001 From: Eyal Kapon Date: Mon, 26 Aug 2024 09:48:01 +0300 Subject: [PATCH] Bug fix/windows username not recognized (#107) * added quotes for windows users with spcaes * added a modification that will maybe work * application now works with usernames with spaces * removed echos and console logs from code --- client/src/api/config.ts | 2 +- host/windows/readconf.bat | 8 ++++---- host/windows/runcli.bat | 16 +++++++++------- host/windows/scanpermissions.bat | 10 ++++++---- host/windows/writeconf.bat | 10 ++++++---- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/client/src/api/config.ts b/client/src/api/config.ts index a62a23e..c21f201 100644 --- a/client/src/api/config.ts +++ b/client/src/api/config.ts @@ -1,4 +1,4 @@ -import { execOnHost, isWindows, throwErrorAsString, ddClient, ddToast } from './utils'; +import { execOnHost, isWindows, throwErrorAsString, ddClient } from './utils'; import { ExtensionConfig } from '../types'; /** * There are two kinds of configurations that are managed and used in the extension: diff --git a/host/windows/readconf.bat b/host/windows/readconf.bat index dfd5d8e..2537ea1 100644 --- a/host/windows/readconf.bat +++ b/host/windows/readconf.bat @@ -1,8 +1,8 @@ @ECHO OFF :: Prints the extension configuration to stdout (in JSON format). +set "HOME_DIR=%USERPROFILE%\.jfrog-docker-desktop-extension" +set "CONF_FILE=%HOME_DIR%\jfrog-docker-desktop-extension.conf" -set HOME_DIR=%USERPROFILE%\.jfrog-docker-desktop-extension -set CONF_FILE=%HOME_DIR%\jfrog-docker-desktop-extension.conf - -type %CONF_FILE% +:: Use quotes around the CONF_FILE variable to handle paths with spaces. +type "%CONF_FILE%" \ No newline at end of file diff --git a/host/windows/runcli.bat b/host/windows/runcli.bat index afdc084..26af3c5 100644 --- a/host/windows/runcli.bat +++ b/host/windows/runcli.bat @@ -1,17 +1,19 @@ @ECHO OFF :: Runs JFrog CLI with the given arguments. The JFrog CLI's home directory is the extension's home directory. - -set HOME_DIR=%USERPROFILE%\.jfrog-docker-desktop-extension -set LOGS_DIR=%HOME_DIR%\logs - -set JFROG_CLI_HOME_DIR=%HOME_DIR% +set "HOME_DIR=%USERPROFILE%\.jfrog-docker-desktop-extension" +set "LOGS_DIR=%HOME_DIR%\logs" +set "JFROG_CLI_HOME_DIR=%HOME_DIR%" set JFROG_CLI_USER_AGENT=jfrog-docker-extension set JFROG_CLI_LOG_LEVEL=DEBUG set CI=true -if not exist %LOGS_DIR% mkdir %LOGS_DIR% +:: Create logs directory if it doesn't exist, handling paths with spaces. +if not exist "%LOGS_DIR%" mkdir "%LOGS_DIR%" + +:: Get the current datetime in a specific format for the log file name. for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I set LOG_FILE_PATH=%LOGS_DIR%\jfrog-docker-desktop-extension.%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2%.%datetime:~8,2%-%datetime:~10,2%.log -%~dp0jf %* 2>> %LOG_FILE_PATH% +:: Run the JFrog CLI with the given arguments, redirecting stderr to the log file. +"%~dp0/jf" %* 2>> "%LOG_FILE_PATH%" \ No newline at end of file diff --git a/host/windows/scanpermissions.bat b/host/windows/scanpermissions.bat index b8a5d00..6f64c74 100644 --- a/host/windows/scanpermissions.bat +++ b/host/windows/scanpermissions.bat @@ -1,7 +1,9 @@ @ECHO OFF -:: Checks whether the user has permissions to run scans in Xray. The return value (in stdout) is the HTTP code returned from Xray. +:: Checks whether the user has permissions to run scans in Xray. +:: The return value (in stdout) is the HTTP code returned from Xray. +set "JFROG_CLI_HOME_DIR=%USERPROFILE%\.jfrog-docker-desktop-extension" -set JFROG_CLI_HOME_DIR=%USERPROFILE%\.jfrog-docker-desktop-extension - -%~dp0jf xr curl --server-id validation -X POST -H "Content-Type:application/json" -d {\"component_details\":[{\"component_id\":\"testComponent\"}]} api/v1/summary/component -s --output nul -w %%{exitcode},%%{http_code} +:: Run the JFrog CLI with the specified command. +:: Handle paths with spaces by wrapping the command in quotes. +"%~dp0jf" xr curl --server-id validation -X POST -H "Content-Type:application/json" -d "{\"component_details\":[{\"component_id\":\"testComponent\"}]}" api/v1/summary/component -s --output nul -w %%{exitcode},%%{http_code} \ No newline at end of file diff --git a/host/windows/writeconf.bat b/host/windows/writeconf.bat index ce118da..cc5bdc9 100644 --- a/host/windows/writeconf.bat +++ b/host/windows/writeconf.bat @@ -1,9 +1,11 @@ @ECHO OFF :: Gets the extension configuration (in JSON format) as an argument and writes it to the configuration file. +set "HOME_DIR=%USERPROFILE%\.jfrog-docker-desktop-extension" +set "CONF_FILE=%HOME_DIR%\jfrog-docker-desktop-extension.conf" -set HOME_DIR=%USERPROFILE%\.jfrog-docker-desktop-extension -set CONF_FILE=%HOME_DIR%\jfrog-docker-desktop-extension.conf +:: Create the HOME_DIR if it doesn't exist, handling paths with spaces +if not exist "%HOME_DIR%" mkdir "%HOME_DIR%" -if not exist %HOME_DIR% mkdir %HOME_DIR% -echo %* > %CONF_FILE% +:: Write the provided configuration to the CONF_FILE, handling paths with spaces +echo %* > "%CONF_FILE%" \ No newline at end of file