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 { const options = { cwd: this.currentSharedFolder, shell: true }
try { const child = spawn(cmd, options)
validateCommand(cmd, gitRegex) let result = ''
} catch (e) { let error = ''
return reject(e) return new Promise((resolve, reject) => {
}
const options = { cwd: this.currentSharedFolder, shell: true }
const child = spawn(cmd, options)
let result = ''
let error = ''
child.stdout.on('data', (data) => { child.stdout.on('data', (data) => {
result += data.toString() result += data.toString()
}) })
...@@ -41,20 +36,17 @@ export class GitClient extends PluginClient { ...@@ -41,20 +36,17 @@ export class GitClient extends PluginClient {
} else { } else {
resolve(result + error) resolve(result + error)
} }
}) })
} catch (e) {
reject(e)
}
}) })
} }
} }
/** /**
* 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