Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
) {
let meta = getMetadata(path.slice(0, path.length - 1).join('.'))
let fromDefaults = _.get(app.deltaCache.defaults, path.join('.'))
if (meta || fromDefaults) {
res.json({...meta, ...fromDefaults})
return
}
}
if (
path.length > 5 &&
path[path.length - 1] === 'units' &&
path[path.length - 2] === 'meta'
) {
let units = _.get(app.deltaCache.defaults, path.join('.'))
if (!units) {
units = getUnits(path.slice(0, path.length - 2).join('.'))
}
if (units) {
res.json(units)
return
}
}
if ( path[0] === 'vessels' && path[1] === 'self' ) {
path[1] = app.selfId
}
function sendResult(last, aPath) {
if (last) {
// tslint:disable-next-line: forin
for (const i in aPath) {
const p = aPath[i]
const chai = require('chai')
chai.Should()
chai.use(require('chai-things'))
chai.use(require('@signalk/signalk-schema').chaiModule)
const freeport = require('freeport-promise')
const startServerP = require('./servertestutilities').startServerP
const rp = require('request-promise')
const uuid = 'urn:mrn:signalk:uuid:c0d79334-4e25-4245-8892-54e8ccc8021d'
const delta = {
context: 'vessels.' + uuid,
updates: [
{
source: {
pgn: 128275,
label: '/dev/actisense',
src: '115'
},
const chai = require('chai')
chai.Should()
chai.use(require('chai-things'))
chai.use(require('@signalk/signalk-schema').chaiModule)
const _ = require('lodash')
const assert = require('assert')
const freeport = require('freeport-promise')
const WebSocket = require('ws')
const rp = require('request-promise')
const startServerP = require('./servertestutilities').startServerP
const testDelta = {
context: 'vessels.self',
updates: [
{
timestamp: '2014-05-03T09:14:11.100Z',
values: [
{
path: 'navigation.trip.log',
value: 43374
msg.updates.forEach(update => {
let source = update.$source
if (!source && update.source) {
source = getSourceId(update.source)
}
if (source) {
update.values.forEach(valuePath => {
if (!pathSources[valuePath.path]) {
pathSources[valuePath.path] = {}
}
if (
!pathSources[valuePath.path][source] ||
pathSources[valuePath.path][source] !== spark
) {
if (pathSources[valuePath.path][source]) {
console.log(
`WARNING: got a new ws client for path ${valuePath.path} source ${source}`
)
}
if (path === 'self') {
return res.json(`vessels.${app.selfId}`)
}
path =
path.length > 0
? path
.replace(/\/$/, '')
.split('/')
: []
if (
path.length > 4 &&
path[path.length - 1] === 'meta'
) {
let meta = getMetadata(path.slice(0, path.length - 1).join('.'))
let fromDefaults = _.get(app.deltaCache.defaults, path.join('.'))
if (meta || fromDefaults) {
res.json({...meta, ...fromDefaults})
return
}
}
if (
path.length > 5 &&
path[path.length - 1] === 'units' &&
path[path.length - 2] === 'meta'
) {
let units = _.get(app.deltaCache.defaults, path.join('.'))
if (!units) {
units = getUnits(path.slice(0, path.length - 2).join('.'))
}
if (units) {
function addSource(update, tags) {
if ( update['$source'] ) {
tags.source = update['$source']
} else if ( update['source'] ) {
tags.source = getSourceId(update['source'])
}
return tags
}
function ensureHasDollarSource(normalizedDelta) {
let dollarSource = normalizedDelta.$source
if (!dollarSource) {
dollarSource = getSourceId(normalizedDelta.source)
normalizedDelta.$source = dollarSource
}
return dollarSource
}
const notAllowed = delta.updates.find(update => {
let source = update.$source
if (!source) {
source = getSourceId(update.source)
}
return update.values.find(valuePath => {
return (
strategy.checkACL(
req.skPrincipal.identifier,
context,
valuePath.path,
source,
'write'
) === false
)
})
})
app.use(require('cors')())
app.use(bodyParser.json({ limit: FILEUPLOADSIZELIMIT }))
this.app = app
app.started = false
_.merge(app, opts)
require('./config/config').load(app)
app.version = '0.0.1'
startSecurity(app, opts ? opts.securityConfig : null)
require('./serverroutes')(app, saveSecurityConfig, getSecurityConfig)
require('./put').start(app)
app.signalk = new FullSignalK(app.selfId, app.selfType, app.config.defaults)
const deltachain = new DeltaChain(app.signalk.addDelta.bind(app.signalk))
app.registerDeltaInputHandler = deltachain.register
app.providerStatus = {}
app.setProviderStatus = function(providerId, statusMessage) {
doSetProviderStatus(providerId, statusMessage, 'status')
}
app.setProviderError = function(providerId, errorMessage) {
doSetProviderStatus(providerId, errorMessage, 'error')
}
function doSetProviderStatus(providerId, statusMessage, type) {
if (!statusMessage) {
DeltaCache.prototype.buildFullFromDeltas = function(
user,
deltas,
includeSources
) {
const signalk = new FullSignalK(
this.app.selfId,
this.app.selfType,
JSON.parse(JSON.stringify(this.defaults))
)
const addDelta = signalk.addDelta.bind(signalk)
if (includeSources) {
_.values(this.sourceDeltas).forEach(addDelta)
}
if (deltas && deltas.length) {
const secFilter = this.app.securityStrategy.shouldFilterDeltas()
? delta => this.app.securityStrategy.filterReadDelta(user, delta)
: delta => true
deltas.filter(secFilter).forEach(addDelta)