Skip to content

Commit

Permalink
fix: incorrect certificate flashing command string (#2181)
Browse files Browse the repository at this point in the history
Use a `string` array of command flags instead of the concatenated final
`string` command.

Ref: #2067
Closes #2179

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
kittaakos authored Aug 20, 2023
1 parent b256655 commit 9a99957
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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<FirmwareInfo[]>;
flash(firmware: FirmwareInfo, port: Port): Promise<string>;
uploadCertificates(command: string): Promise<any>;
uploadCertificates(params: UploadCertificateParams): Promise<unknown>;
updatableBoards(): Promise<string[]>;
availableFirmwares(fqbn: string): Promise<FirmwareInfo[]>;
}
14 changes: 12 additions & 2 deletions arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,8 +18,17 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
@inject(MonitorManager)
private readonly monitorManager: MonitorManager;

async uploadCertificates(command: string): Promise<string> {
return await this.runCommand(['certificates', 'flash', command]);
async uploadCertificates(params: UploadCertificateParams): Promise<string> {
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<FirmwareInfo[]> {
Expand Down

0 comments on commit 9a99957

Please sign in to comment.