Skip to content

Commit aaa40c4

Browse files
Added sudo error. Sudo error is returned by codify spawn when a library attempts to use sudo (which is forbidden). (#6)
1 parent 28d28e6 commit aaa40c4

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-lib",
3-
"version": "1.0.57",
3+
"version": "1.0.59",
44
"description": "",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -14,7 +14,7 @@
1414
"dependencies": {
1515
"ajv": "^8.12.0",
1616
"ajv-formats": "^2.1.1",
17-
"codify-schemas": "1.0.33",
17+
"codify-schemas": "1.0.38",
1818
"@npmcli/promise-spawn": "^7.0.1"
1919
},
2020
"devDependencies": {

src/entities/errors.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class SudoError extends Error {
2+
command: string;
3+
4+
constructor(command: string) {
5+
super();
6+
this.command = command;
7+
}
8+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './entities/change-set.js'
88
export * from './entities/plan.js'
99
export * from './entities/plan-types.js'
1010
export * from './entities/stateful-parameter.js'
11+
export * from './entities/errors.js'
1112

1213
export * from './utils/test-utils.js'
1314
export * from './utils/utils.js'

src/messages/handlers.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
ValidateResponseDataSchema
1616
} from 'codify-schemas';
1717
import Ajv2020, { SchemaObject, ValidateFunction } from 'ajv/dist/2020.js';
18+
import { SudoError } from '../entities/errors.js';
1819

1920
const SupportedRequests: Record<string, { requestValidator: SchemaObject; responseValidator: SchemaObject; handler: (plugin: Plugin, data: any) => Promise<unknown> }> = {
2021
'initialize': {
@@ -115,6 +116,14 @@ export class MessageHandler {
115116
// @ts-ignore
116117
const cmd = message.cmd + '_Response';
117118

119+
if (e instanceof SudoError) {
120+
process.send?.({
121+
cmd,
122+
status: MessageStatus.ERROR,
123+
data: `Plugin: '${this.plugin.name}'. Forbidden usage of sudo for command '${e.command}'. Please contact the plugin developer to fix this.`,
124+
})
125+
}
126+
118127
const isDebug = process.env.DEBUG?.includes('*') ?? false;
119128

120129
process.send?.({

0 commit comments

Comments
 (0)