-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: report commands before execute (#134)
* refactor: remove useless branch and code * feat: feflow report
- Loading branch information
1 parent
7d5d511
commit ca20a16
Showing
5 changed files
with
84 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export default { | ||
REPORT_URL: 'http://193.112.196.252/api/v1/report/command' | ||
REPORT_URL: 'http://193.112.196.252/api/v1/report/command', | ||
REPORT_PROXY: 'http://127.0.0.1:12639' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,70 @@ | ||
import rp from 'request-promise'; | ||
import URI from './config'; | ||
import shell from 'shelljs'; | ||
|
||
export default { | ||
report(param) { | ||
console.log('param', param); | ||
log: {}, | ||
report(param, log) { | ||
this.log = log || {}; | ||
const proxyIsOn = shell | ||
.exec(`curl ${URI.REPORT_PROXY}`, { silent: true }) | ||
.stdout.trim(); | ||
|
||
if (proxyIsOn) { | ||
log.debug('Report, chose proxy curl'); | ||
this.reportWithProxy(param); | ||
} else { | ||
log.debug('Report, chose normal http'); | ||
this.reportWithoutProxy(param); | ||
} | ||
}, | ||
reportWithoutProxy(param) { | ||
rp({ | ||
method: 'POST', | ||
uri: URI.REPORT_URL, | ||
body: param, | ||
json: true | ||
}) | ||
.then(res => { | ||
console.log('got report response', res); | ||
this.log.debug('got report response', res); | ||
}) | ||
.catch(e => { | ||
console.log('rp report fail', e); | ||
this.log.debug('feflow report fail', e); | ||
}); | ||
}, | ||
reportWithProxy(param) { | ||
let dataString = ''; | ||
// get formated report params | ||
Object.keys(param).forEach(key => { | ||
let value = param[key]; | ||
value = typeof value == 'object' ? JSON.stringify(value) : value; | ||
if (value != undefined) { | ||
dataString += `&${key}=${value}`; | ||
} | ||
}); | ||
|
||
const cmdWithProxy = []; | ||
|
||
// curl | ||
cmdWithProxy.push('curl'); | ||
|
||
// proxy | ||
cmdWithProxy.push('-x'); | ||
cmdWithProxy.push(URI.REPORT_PROXY); | ||
|
||
// url | ||
cmdWithProxy.push(URI.REPORT_URL); | ||
|
||
// params | ||
cmdWithProxy.push('-d'); | ||
cmdWithProxy.push("'" + dataString.slice(1) + "'"); | ||
|
||
this.log.debug("cmdWithProxy.join(' ')", cmdWithProxy.join(' ')); | ||
|
||
const res = shell | ||
.exec(cmdWithProxy.join(' '), { silent: true }) | ||
.stdout.trim(); | ||
|
||
this.log.debug('res', res); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters