Skip to content

Commit

Permalink
fix(security): upgrade to agent api
Browse files Browse the repository at this point in the history
  • Loading branch information
dszakallas committed Jan 12, 2017
1 parent 305ee50 commit 2531a6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/agent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function Agent (options) {
})

this.security = Security.create({
collectorApi: this._collectorApi,
collectorApi: this._api,
config: this.config
})

Expand Down
24 changes: 12 additions & 12 deletions lib/agent/security/security.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var childProcess = require('child_process')
var fs = require('fs')
var debug = require('debug')('risingstack/trace')
var debug = require('debug')('risingstack/trace:agent:security')
var yaml = require('js-yaml')
var forEach = require('lodash.foreach')
var uniq = require('lodash.uniq')
var inherits = require('util').inherits
var Agent = require('../agent')

function Security (options) {
this.name = 'Security'
this.collectorApi = options.collectorApi
Agent.call(this, 'Security')
}

var self = this
inherits(Security, Agent)

this.timer = {
start: function () { self.sendDependencies() },
restart: function () { /* noop */ },
end: function () { /* noop */ }
}
Security.prototype.initialize = function () {
this.sendDependencies()
}

Security.prototype.collectSnykFlags = function collectSnykFlags (callback) {
Expand All @@ -30,7 +30,7 @@ Security.prototype.collectSnykFlags = function collectSnykFlags (callback) {
try {
patch = yaml.safeLoad(data).patch
} catch (ex) {
debug('error collecting snyk flags', ex)
debug('#collectSnykFlags', 'error collecting snyk flags', ex)
callback(null, [])
return
}
Expand All @@ -50,7 +50,7 @@ Security.prototype.collectSnykFlags = function collectSnykFlags (callback) {
childProcess.execFile('npm', ['ls'].concat(uniq(packageNames)).concat(['--parseable', '--long']), function (_error, stdout, stderr) {
if (_error) {
// ignore
debug('`npm ls <package_names> --long --parseable` returned error', _error)
debug('#collectSnykFlags', '`npm ls <package_names> --long --parseable` returned error', _error)
}

var pkgs = stdout.split('\n')
Expand Down Expand Up @@ -137,13 +137,13 @@ Security.prototype.sendDependencies = function sendDependencies () {
var _this = this
this.collectDependencies(function (error, dependencies) {
if (error) {
debug('error collecting dependencies', error)
debug('#sendDependencies', 'error collecting dependencies', error)
return
}

_this.collectSnykFlags(function (_error, flags) {
if (_error) {
debug('error collecting snyk flags', _error)
debug('#sendDependencies', 'error collecting snyk flags', _error)
// send dependencies without patches
_this.collectorApi.sendDependencies(dependencies)
return
Expand Down
8 changes: 4 additions & 4 deletions lib/agent/security/security.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('The Security module', function () {
collectorApi: collectorApi
})

security.timer.start()
security.initialize()

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

security.timer.start()
security.initialize()

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

security.timer.start()
security.initialize()

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

security.timer.start()
security.initialize()

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

0 comments on commit 2531a6f

Please sign in to comment.