Use exclusion lists for keys/columns to be omited from the /v1/apps endpoint

This commit is contained in:
Kostas Lekkas 2016-04-20 19:43:16 +03:00
parent e03e5ed0ae
commit f76b38eb49

View File

@ -10,6 +10,17 @@ config = require './config'
device = require './device'
_ = require 'lodash'
privateAppEnvVars = [
'RESIN_SUPERVISOR_API_KEY'
'RESIN_API_KEY'
]
ignoredAppTableColumns = [
'id'
'name'
'privileged'
]
module.exports = (application) ->
api = express()
api.use(bodyParser())
@ -171,9 +182,9 @@ module.exports = (application) ->
if !app?
throw new Error('App not found')
# Don't return keys on the endpoint
app.env = _.omit(JSON.parse(app.env), [ 'RESIN_SUPERVISOR_API_KEY', 'RESIN_API_KEY' ])
# name and privileged are unused, and id makes no sense to the user here.
res.json(_.omit(app, [ 'id', 'name', 'privileged' ]))
app.env = _.omit(JSON.parse(app.env), privateAppEnvVars)
# Don't return data that will be of no use to the user
res.json(_.omit(app, ignoredAppTableColumns))
.catch (err) ->
res.status(503).send(err?.message or err or 'Unknown error')