From 9a99957e73d1b9cbfa9a109cfb5ee821c454c6b9 Mon Sep 17 00:00:00 2001 From: Akos Kitta <1405703+kittaakos@users.noreply.github.com> Date: Sun, 20 Aug 2023 21:53:43 +0200 Subject: [PATCH] fix: incorrect certificate flashing command string (#2181) Use a `string` array of command flags instead of the concatenated final `string` command. Ref: arduino/arduino-ide#2067 Closes arduino/arduino-ide#2179 Signed-off-by: Akos Kitta --- .../browser/contributions/upload-certificate.ts | 13 ++++++------- .../common/protocol/arduino-firmware-uploader.ts | 13 +++++++++---- .../src/node/arduino-firmware-uploader-impl.ts | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/upload-certificate.ts b/arduino-ide-extension/src/browser/contributions/upload-certificate.ts index 7e1400932..a6385cb2a 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-certificate.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-certificate.ts @@ -16,7 +16,10 @@ import { arduinoCert, certificateList, } from '../dialogs/certificate-uploader/utils'; -import { ArduinoFirmwareUploader } from '../../common/protocol/arduino-firmware-uploader'; +import { + ArduinoFirmwareUploader, + UploadCertificateParams, +} from '../../common/protocol/arduino-firmware-uploader'; import { nls } from '@theia/core/lib/common'; @injectable() @@ -74,12 +77,8 @@ export class UploadCertificate extends Contribution { }); registry.registerCommand(UploadCertificate.Commands.UPLOAD_CERT, { - execute: async ({ fqbn, address, urls }) => { - return this.arduinoFirmwareUploader.uploadCertificates( - `-b ${fqbn} -a ${address} ${urls - .map((url: string) => `-u ${url}`) - .join(' ')}` - ); + execute: async (params: UploadCertificateParams) => { + return this.arduinoFirmwareUploader.uploadCertificates(params); }, }); diff --git a/arduino-ide-extension/src/common/protocol/arduino-firmware-uploader.ts b/arduino-ide-extension/src/common/protocol/arduino-firmware-uploader.ts index 3cf9437d3..7e24afcb3 100644 --- a/arduino-ide-extension/src/common/protocol/arduino-firmware-uploader.ts +++ b/arduino-ide-extension/src/common/protocol/arduino-firmware-uploader.ts @@ -1,19 +1,24 @@ -import { Port } from "./boards-service"; +import type { Port } from './boards-service'; export const ArduinoFirmwareUploaderPath = '/services/arduino-firmware-uploader'; export const ArduinoFirmwareUploader = Symbol('ArduinoFirmwareUploader'); -export type FirmwareInfo = { +export interface FirmwareInfo { board_name: string; board_fqbn: string; module: string; firmware_version: string; Latest: boolean; -}; +} +export interface UploadCertificateParams { + readonly fqbn: string; + readonly address: string; + readonly urls: readonly string[]; +} export interface ArduinoFirmwareUploader { list(fqbn?: string): Promise; flash(firmware: FirmwareInfo, port: Port): Promise; - uploadCertificates(command: string): Promise; + uploadCertificates(params: UploadCertificateParams): Promise; updatableBoards(): Promise; availableFirmwares(fqbn: string): Promise; } diff --git a/arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts b/arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts index d1c1d0cb5..5def6a74b 100644 --- a/arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts +++ b/arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts @@ -4,6 +4,7 @@ import type { Port } from '../common/protocol'; import { ArduinoFirmwareUploader, FirmwareInfo, + UploadCertificateParams, } from '../common/protocol/arduino-firmware-uploader'; import { spawnCommand } from './exec-util'; import { MonitorManager } from './monitor-manager'; @@ -17,8 +18,17 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader { @inject(MonitorManager) private readonly monitorManager: MonitorManager; - async uploadCertificates(command: string): Promise { - return await this.runCommand(['certificates', 'flash', command]); + async uploadCertificates(params: UploadCertificateParams): Promise { + const { fqbn, address, urls } = params; + return await this.runCommand([ + 'certificates', + 'flash', + '-b', + fqbn, + '-a', + address, + ...urls.flatMap((url) => ['-u', url]), + ]); } async list(fqbn?: string): Promise {