Skip to content

Commit 2531a6f

Browse files
committed
fix(security): upgrade to agent api
1 parent 305ee50 commit 2531a6f

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

lib/agent/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function Agent (options) {
6969
})
7070

7171
this.security = Security.create({
72-
collectorApi: this._collectorApi,
72+
collectorApi: this._api,
7373
config: this.config
7474
})
7575

lib/agent/security/security.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
var childProcess = require('child_process')
22
var fs = require('fs')
3-
var debug = require('debug')('risingstack/trace')
3+
var debug = require('debug')('risingstack/trace:agent:security')
44
var yaml = require('js-yaml')
55
var forEach = require('lodash.foreach')
66
var uniq = require('lodash.uniq')
7+
var inherits = require('util').inherits
8+
var Agent = require('../agent')
79

810
function 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

2121
Security.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

lib/agent/security/security.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('The Security module', function () {
7272
collectorApi: collectorApi
7373
})
7474

75-
security.timer.start()
75+
security.initialize()
7676

7777
expect(fs.readFile).to.have.been.calledWithMatch('.snyk')
7878
expect(fs.readdir).to.have.been.calledWithMatch('/project/node_modules/vuln')
@@ -130,7 +130,7 @@ describe('The Security module', function () {
130130
collectorApi: collectorApi
131131
})
132132

133-
security.timer.start()
133+
security.initialize()
134134

135135
expect(fs.readFile).to.have.been.calledWithMatch('.snyk')
136136
expect(childProcess.execFile).to.have.been.calledWithMatch('npm', ['ls', '--json', '--production'])
@@ -181,7 +181,7 @@ describe('The Security module', function () {
181181
collectorApi: collectorApi
182182
})
183183

184-
security.timer.start()
184+
security.initialize()
185185

186186
expect(fs.readFile).to.have.been.calledWithMatch('.snyk')
187187
expect(childProcess.execFile).to.have.been.calledWithMatch('npm', ['ls', '--json', '--production'])
@@ -232,7 +232,7 @@ describe('The Security module', function () {
232232
collectorApi: collectorApi
233233
})
234234

235-
security.timer.start()
235+
security.initialize()
236236

237237
expect(fs.readFile).to.have.been.calledWithMatch('.snyk')
238238
expect(childProcess.execFile).to.have.been.calledWithMatch('npm', ['ls', '--json', '--production'])

0 commit comments

Comments
 (0)