11var childProcess = require ( 'child_process' )
22var fs = require ( 'fs' )
3- var debug = require ( 'debug' ) ( 'risingstack/trace' )
3+ var debug = require ( 'debug' ) ( 'risingstack/trace:agent:security ' )
44var yaml = require ( 'js-yaml' )
55var forEach = require ( 'lodash.foreach' )
66var uniq = require ( 'lodash.uniq' )
7+ var inherits = require ( 'util' ) . inherits
8+ var Agent = require ( '../agent' )
79
810function Security ( options ) {
9- this . name = 'Security'
1011 this . collectorApi = options . collectorApi
12+ Agent . call ( this , 'Security' )
13+ }
1114
12- var self = this
15+ inherits ( Security , Agent )
1316
14- this . timer = {
15- start : function ( ) { self . sendDependencies ( ) } ,
16- restart : function ( ) { /* noop */ } ,
17- end : function ( ) { /* noop */ }
18- }
17+ Security . prototype . initialize = function ( ) {
18+ this . sendDependencies ( )
1919}
2020
2121Security . prototype . collectSnykFlags = function collectSnykFlags ( callback ) {
@@ -30,7 +30,7 @@ Security.prototype.collectSnykFlags = function collectSnykFlags (callback) {
3030 try {
3131 patch = yaml . safeLoad ( data ) . patch
3232 } catch ( ex ) {
33- debug ( 'error collecting snyk flags' , ex )
33+ debug ( '#collectSnykFlags' , ' error collecting snyk flags', ex )
3434 callback ( null , [ ] )
3535 return
3636 }
@@ -50,7 +50,7 @@ Security.prototype.collectSnykFlags = function collectSnykFlags (callback) {
5050 childProcess . execFile ( 'npm' , [ 'ls' ] . concat ( uniq ( packageNames ) ) . concat ( [ '--parseable' , '--long' ] ) , function ( _error , stdout , stderr ) {
5151 if ( _error ) {
5252 // ignore
53- debug ( '`npm ls <package_names> --long --parseable` returned error' , _error )
53+ debug ( '#collectSnykFlags' , ' `npm ls <package_names> --long --parseable` returned error', _error )
5454 }
5555
5656 var pkgs = stdout . split ( '\n' )
@@ -137,13 +137,13 @@ Security.prototype.sendDependencies = function sendDependencies () {
137137 var _this = this
138138 this . collectDependencies ( function ( error , dependencies ) {
139139 if ( error ) {
140- debug ( 'error collecting dependencies' , error )
140+ debug ( '#sendDependencies' , ' error collecting dependencies', error )
141141 return
142142 }
143143
144144 _this . collectSnykFlags ( function ( _error , flags ) {
145145 if ( _error ) {
146- debug ( 'error collecting snyk flags' , _error )
146+ debug ( '#sendDependencies' , ' error collecting snyk flags', _error )
147147 // send dependencies without patches
148148 _this . collectorApi . sendDependencies ( dependencies )
149149 return
0 commit comments