Commit baf86d90 authored by yann300's avatar yann300

refactor

parent 850d85fb
...@@ -17,18 +17,13 @@ export class GitClient extends PluginClient { ...@@ -17,18 +17,13 @@ export class GitClient extends PluginClient {
this.readOnly = readOnly this.readOnly = readOnly
} }
command (cmd: string) { execute (cmd: string) {
return new Promise((resolve, reject) => { assertCommand(cmd)
try {
try {
validateCommand(cmd, gitRegex)
} catch (e) {
return reject(e)
}
const options = { cwd: this.currentSharedFolder, shell: true } const options = { cwd: this.currentSharedFolder, shell: true }
const child = spawn(cmd, options) const child = spawn(cmd, options)
let result = '' let result = ''
let error = '' let error = ''
return new Promise((resolve, reject) => {
child.stdout.on('data', (data) => { child.stdout.on('data', (data) => {
result += data.toString() result += data.toString()
}) })
...@@ -42,9 +37,6 @@ export class GitClient extends PluginClient { ...@@ -42,9 +37,6 @@ export class GitClient extends PluginClient {
resolve(result + error) resolve(result + error)
} }
}) })
} catch (e) {
reject(e)
}
}) })
} }
} }
...@@ -52,9 +44,9 @@ export class GitClient extends PluginClient { ...@@ -52,9 +44,9 @@ export class GitClient extends PluginClient {
/** /**
* Validate that command can be run by service * Validate that command can be run by service
* @param cmd * @param cmd
* @param regex
*/ */
function validateCommand (cmd, regex) { function assertCommand (cmd) {
const regex = '^git\\s[^&|;]*$'
if (!RegExp(regex).test(cmd)) { // git then space and then everything else if (!RegExp(regex).test(cmd)) { // git then space and then everything else
throw new Error('Invalid command for service!') throw new Error('Invalid command for service!')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment