Skip to content

Commit afb51d4

Browse files
committed
refactor grpc input to disallow nodeIntegration
1 parent 68e415e commit afb51d4

File tree

6 files changed

+86
-38
lines changed

6 files changed

+86
-38
lines changed

main.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const { InMemoryCache } = require("apollo-cache-inmemory");
4040
const { createHttpLink } = require("apollo-link-http");
4141
const { ApolloLink } = require("apollo-link");
4242

43+
// proto-parser func for parsing .proto files
44+
const protoParserFunc = require('./src/client/protoParser.js');
45+
4346
// require menu file
4447
require("./menu/mainMenu");
4548

@@ -481,6 +484,36 @@ ipcMain.on('confirm-clear-history', (event) => {
481484
mainWindow.webContents.send('clear-history-response', response)
482485
})
483486
.catch(err => console.log(`Error on 'confirm-clear-history': ${err}`));
487+
});
488+
489+
ipcMain.on('import-proto', (event) => {
490+
console.log('import-proto event fired!!')
491+
let importedProto;
492+
dialog.showOpenDialog({
493+
buttonLabel : "Import Proto File",
494+
properties: ['openFile', 'multiSelections'],
495+
filters: [ { name: 'Protos', extensions: ['proto'] } ]
496+
})
497+
.then(filePaths => {
498+
if (!filePaths) return undefined;
499+
// read uploaded proto file & save protoContent in the store
500+
fs.readFile(filePaths.filePaths[0], 'utf-8', (err, file) => {
501+
// handle read error
502+
if (err) {
503+
return console.log('error reading file : ', err);
504+
};
505+
importedProto = file;
506+
protoParserFunc(importedProto)
507+
.then(protoObj => {
508+
console.log('finished with logic. about to send importedProto : ', importedProto, ' and protoObj : ', protoObj)
509+
mainWindow.webContents.send('proto-info', importedProto, protoObj)
510+
})
511+
});
512+
})
513+
.catch(err => {
514+
console.log(err);
515+
})
516+
484517
})
485518

486519
// ipcMain listener that

preload.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ contextBridge.exposeInMainWorld(
44
'api', {
55
send: (channel, data) => {
66
// allowlist channels
7-
const allowedChannels = ['toMain', 'confirm-clear-history' ];
7+
const allowedChannels = ['toMain', 'confirm-clear-history', 'import-proto' ];
88
if (allowedChannels.includes(channel)) {
99
ipcRenderer.send(channel, data);
1010
}
1111
},
1212
receive: (channel, cb) => {
1313
console.log('listening on channel : ', channel)
1414
// allowlist channels
15-
const allowedChannels = ['fromMain', 'add-collection', 'clear-history-response'];
15+
const allowedChannels = ['fromMain', 'add-collection', 'clear-history-response', 'proto-info'];
1616
if (allowedChannels.includes(channel)){
1717
ipcRenderer.on(channel, (event, ...args) => cb(...args));
1818
}

src/client/components/composer/ComposerContainer.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { connect } from "react-redux";
33
import * as actions from "../../actions/actions";
44

55
import ComposerNewRequest from "./NewRequest/ComposerNewRequest.jsx";
6-
import ComposerWarning from "./Warning/ComposerWarning.jsx";
6+
// import ComposerWarning from "./Warning/ComposerWarning.jsx";
77

88
const mapStateToProps = (store) => ({
99
reqResArray: store.business.reqResArray,
@@ -99,12 +99,12 @@ class ComposerContainer extends Component {
9999
break;
100100
}
101101
case "Warning": {
102-
composerContents = (
103-
<ComposerWarning
104-
warningMessage={this.props.warningMessage}
105-
setComposerDisplay={this.props.setComposerDisplay}
106-
/>
107-
);
102+
// composerContents = (
103+
// // <ComposerWarning
104+
// // warningMessage={this.props.warningMessage}
105+
// // setComposerDisplay={this.props.setComposerDisplay}
106+
// // />
107+
// );
108108
break;
109109
}
110110
default:

src/client/components/composer/NewRequest/GRPCProtoEntryForm.jsx

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React, { Component } from 'react';
2-
import { remote } from 'electron';
3-
import fs from 'fs';
2+
// import { remote } from 'electron';
3+
// import fs from 'fs';
44
import GRPCAutoInputForm from "./GRPCAutoInputForm.jsx";
5-
import protoParserFunc from "../../../../client/protoParser.js";
5+
// import protoParserFunc from "../../../protoParser.js";
66
import dropDownArrow from '../../../../assets/icons/arrow_drop_down_white_192x192.png';
77

8+
const { api } = window;
9+
810
class GRPCProtoEntryForm extends Component {
911
constructor(props) {
1012
super(props);
@@ -44,30 +46,43 @@ class GRPCProtoEntryForm extends Component {
4446
protoContent: ''
4547
});
4648
}
47-
// use electron dialog to import files that has .proto ext only
48-
remote.dialog.showOpenDialog({
49-
buttonLabel : "Import Proto File",
50-
properties: ['openFile', 'multiSelections'],
51-
filters: [ { name: 'Protos', extensions: ['proto'] } ]
52-
})
53-
.then(filePaths => {
54-
if (!filePaths) return;
55-
// read uploaded proto file & save protoContent in the store
56-
const importedProto = fs.readFileSync(filePaths.filePaths[0], 'utf-8');
49+
50+
api.receive('proto-info', (readProto, parsedProto) => {
51+
console.log('received from main readProto : ', readProto, 'and parsed Proto : ', parsedProto)
5752
this.props.setNewRequestStreams({
5853
...this.props.newRequestStreams,
59-
protoContent: importedProto
54+
protoContent: readProto,
55+
services: parsedProto.serviceArr,
56+
protoPath: parsedProto.protoPath
6057
});
61-
// parse proto file via protoParserFunc imported from protoParser.js & save parsed proto file details in the store
62-
protoParserFunc(this.props.newRequestStreams.protoContent)
63-
.then(data => {
64-
this.props.setNewRequestStreams({
65-
...this.props.newRequestStreams,
66-
services: data.serviceArr,
67-
protoPath: data.protoPath
68-
})
69-
}).catch((err) => console.log(err));
7058
});
59+
60+
api.send('import-proto');
61+
62+
// // use electron dialog to import files that has .proto ext only
63+
// remote.dialog.showOpenDialog({
64+
// buttonLabel : "Import Proto File",
65+
// properties: ['openFile', 'multiSelections'],
66+
// filters: [ { name: 'Protos', extensions: ['proto'] } ]
67+
// })
68+
// .then(filePaths => {
69+
// if (!filePaths) return;
70+
// // read uploaded proto file & save protoContent in the store
71+
// const importedProto = fs.readFileSync(filePaths.filePaths[0], 'utf-8');
72+
// this.props.setNewRequestStreams({
73+
// ...this.props.newRequestStreams,
74+
// protoContent: importedProto
75+
// });
76+
// // parse proto file via protoParserFunc imported from protoParser.js & save parsed proto file details in the store
77+
// protoParserFunc(this.props.newRequestStreams.protoContent)
78+
// .then(data => {
79+
// this.props.setNewRequestStreams({
80+
// ...this.props.newRequestStreams,
81+
// services: data.serviceArr,
82+
// protoPath: data.protoPath
83+
// })
84+
// }).catch((err) => console.log(err));
85+
// });
7186
}
7287

7388
// saves protoContent in the store whenever client make changes to proto file or pastes a copy

src/client/components/containers/SidebarContainer.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
2-
// import ComposerContainer from '../composer/ComposerContainer.jsx';
2+
import ComposerContainer from '../composer/ComposerContainer.jsx';
33
import HistoryContainer from './HistoryContainer.jsx';
4-
// import CollectionsContainer from './CollectionsContainer.jsx';
4+
import CollectionsContainer from './CollectionsContainer.jsx';
55

66
class SidebarContainer extends Component {
77
constructor(props) {
@@ -11,8 +11,8 @@ class SidebarContainer extends Component {
1111
render(props) {
1212
return (
1313
<div className="sidebar_composer-console">
14-
{/* <ComposerContainer />
15-
<CollectionsContainer /> */}
14+
<ComposerContainer />
15+
<CollectionsContainer />
1616
<HistoryContainer />
1717
</div>
1818
);

src/client/protoParser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require("fs");
22
const grpc = require("@grpc/grpc-js");
33
const protoLoader = require("@grpc/proto-loader");
44
const path = require("path");
5-
const uuid = require("uuid");
5+
// const uuid = require("uuid");
66

77
async function protoParserFunc(protoBodyData) {
88
// define storage for .proto parsed content
@@ -169,4 +169,4 @@ async function protoParserFunc(protoBodyData) {
169169

170170
// console.log(tempData);
171171
// protoParserFunc(tempData).catch((err) => console.log(err));
172-
export default protoParserFunc;
172+
module.exports = protoParserFunc;

0 commit comments

Comments
 (0)