Skip to content

Commit

Permalink
feat(config): add applyLasp method
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Svetlichny committed Apr 23, 2018
1 parent c41349a commit 171ace3
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,68 @@ Config.prototype._applyHighSecurity = function _applyHighSecurity() {
}
}

var LASP_MAP = {
record_sql: 'record_sql',
attributes_include: 'attributes.include_enabled',
// TODO: rename config key
allow_raw_exception_messages: 'strip_exception_messages.enabled',
custom_events: 'api.custom_events_enabled',
custom_parameters: 'api.custom_attributes_enabled',
live_instrumentation: null,
message_parameters: null,
job_arguments: null
}

Config.prototype.applyLasp = function _applyLasp(policies, callback) {
var config = this

if (!config.security_policies_token) {
return callback(null, null)
}

var missingLASP = []
var missingRequired = []

var res = Object.keys(LASP_MAP).reduce(function applyPolicy(obj, name) {
var policy = policies[name]

if (!policy) {
// agent is expecting a policy that was not sent from server -- fail
missingLASP.push(name)
} else if (!LASP_MAP[name]) {
if (!policy.required) {
// policy is not implemented in agent -- don't send to connect
return obj
}
// policy is required but does not exist in agent -- fail
missingRequired(name)
} else {
// TODO: Apply most secure after connect
obj[name] = policy
}

return obj
}, Object.create(null))

var error = null
if (missingLASP.length) {
error = new Error(
'The agent did not receive one or more security policies that it ' +
'expected and will down: ' + missingLASP.join(', ') + '.'
)
} else if (missingRequired.length) {
error = new Error(
'The agent received one or more required security policies that it ' +
'does not recognize and will shut down: ' + missingRequired.join(', ') +
'. Please check if a newer agent version supports these policies ' +
'or contact support.'
)
}

callback(error, res)
}


/**
* The agent will use the supportability metrics object if it's
* available.
Expand Down

0 comments on commit 171ace3

Please sign in to comment.