Skip to content

Commit 0a9ae7b

Browse files
committed
fix: promptSudo for all reporter types
1 parent 5694c98 commit 0a9ae7b

File tree

4 files changed

+5
-11
lines changed

4 files changed

+5
-11
lines changed

src/common/base-command.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ export abstract class BaseCommand extends Command {
4444
ctx.on(Event.SUDO_REQUEST, async (pluginName: string, data: SudoRequestData) => {
4545
try {
4646
const password = (flags.sudoPassword) ?? (await this.reporter.promptSudo(pluginName, data, flags.secure));
47-
if (!password) {
48-
throw new Error(`Unable to get sudo password to run command: ${data.command}`);
49-
}
5047

5148
const result = await SudoUtils.runCommand(data.command, data.options, flags.secure, pluginName, password)
5249
ctx.sudoRequestGranted(pluginName, result);

src/ui/reporters/json-reporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class JsonReporter implements Reporter {
3535
}
3636

3737
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData> {
38-
throw new Error(`Json reporter error: sudo required for command: ${data.command}. Make sure to preconfigure the sudo password for the Json reporter`);
38+
throw new Error(`Json reporter error: sudo required for command: ${data.command}. Make sure to preconfigure the sudo password for the Json reporter using --sudoPassword`);
3939
}
4040

4141
async promptUserForValues(resources: ResourceInfo[], promptType: PromptType): Promise<ResourceConfig[]> {

src/ui/reporters/plain-reporter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ export class PlainReporter implements Reporter {
102102
}
103103
}
104104

105-
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData> {
105+
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<string | undefined> {
106106
console.log(chalk.blue(`Plugin: "${pluginName}" requires root access to run command: "${data.command}"`));
107-
return SudoUtils.runCommand(data.command, data.options, secureMode, pluginName);
107+
return undefined;
108108
}
109109

110110
async promptConfirmation(message: string): Promise<boolean> {

test/orchestrator/mocks/reporter.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ export class MockReporter implements Reporter {
5757
return this.config?.promptConfirmation?.() ?? true;
5858
}
5959

60-
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData> {
61-
return {
62-
status: SpawnStatus.SUCCESS,
63-
data: '',
64-
}
60+
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<string | undefined> {
61+
return '';
6562
}
6663

6764
async promptUserForValues(resourceInfo: ResourceInfo[], promptType: PromptType): Promise<ResourceConfig[]> {

0 commit comments

Comments
 (0)