Skip to content

Commit 9c2edf8

Browse files
committed
feat: Added message handlers for press key to continue and codify credentials
1 parent c4c9bba commit 9c2edf8

3 files changed

Lines changed: 40 additions & 5 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-test",
3-
"version": "0.0.50",
3+
"version": "0.0.51",
44
"description": "",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"ajv": "^8.12.0",
1818
"ajv-formats": "^3.0.1",
19-
"codify-schemas": "1.0.61",
19+
"codify-schemas": "1.0.77",
2020
"lodash.matches": "^4.6.0",
2121
"lodash.differencewith": "4.5.0",
2222
"lodash.unionby": "^4.8.0",

src/plugin-process.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { ChildProcess, SpawnOptions, fork, spawn } from 'node:child_process';
1414
import path from 'node:path';
1515

1616
import { CodifyTestUtils } from './test-utils.js';
17+
import fs from 'node:fs/promises';
18+
import * as os from 'node:os';
1719

1820
const ajv = new Ajv.default({
1921
strict: true
@@ -52,7 +54,7 @@ export class PluginProcess {
5254
this.childProcess.stderr?.pipe(process.stderr);
5355
this.childProcess.stdout?.pipe(process.stdout);
5456

55-
this.handleSudoRequests(this.childProcess);
57+
this.handleIncomingRequests(this.childProcess);
5658
}
5759

5860
async initialize(): Promise<InitializeResponseData> {
@@ -99,7 +101,7 @@ export class PluginProcess {
99101
this.childProcess.kill();
100102
}
101103

102-
private handleSudoRequests(process: ChildProcess) {
104+
private handleIncomingRequests(process: ChildProcess) {
103105
// Listen for incoming sudo incoming sudo requests
104106
process.on('message', async (message) => {
105107
if (!ipcMessageValidator(message)) {
@@ -121,6 +123,39 @@ export class PluginProcess {
121123
requestId,
122124
})
123125
}
126+
127+
if (message.cmd === MessageCmd.PRESS_KEY_TO_CONTINUE_REQUEST) {
128+
const { data, requestId } = message;
129+
if (!sudoRequestValidator(data)) {
130+
throw new Error(`Invalid sudo request from plugin. ${JSON.stringify(sudoRequestValidator.errors, null, 2)}`);
131+
}
132+
133+
process.send(<IpcMessageV2>{
134+
cmd: MessageCmd.PRESS_KEY_TO_CONTINUE_REQUEST + '_Response',
135+
data: {},
136+
requestId,
137+
})
138+
}
139+
140+
if (message.cmd === MessageCmd.CODIFY_CREDENTIALS_REQUEST) {
141+
const { requestId } = message;
142+
143+
const loginJson = await fs.readFile(path.join(os.homedir(), '.codify', 'credentials.json'), 'utf8');
144+
if (!loginJson) {
145+
throw new Error('Unable to get login credentials')
146+
}
147+
148+
const login = JSON.parse(loginJson);
149+
if (!login) {
150+
throw new Error('Unable to parse login credentials')
151+
}
152+
153+
process.send(<IpcMessageV2>{
154+
cmd: MessageCmd.CODIFY_CREDENTIALS_REQUEST + '_Response',
155+
data: login.accessToken,
156+
requestId,
157+
})
158+
}
124159
})
125160
}
126161

src/plugin-tester.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ ${JSON.stringify(modifyPlans, null, 2)}`)
179179
}
180180

181181
for (const plan of plans) {
182-
if (plan.operation !== ResourceOperation.DESTROY) {
182+
if (plan.operation !== ResourceOperation.DESTROY && plan.operation !== ResourceOperation.NOOP) {
183183
throw new Error(`Expect resource operation to be 'destroy' but instead received plan: \n ${JSON.stringify(plans, null, 2)}`)
184184
}
185185

0 commit comments

Comments
 (0)