diff --git a/src/apps.js b/src/apps.js index 46827523f..043725e25 100644 --- a/src/apps.js +++ b/src/apps.js @@ -4,6 +4,7 @@ exports = module.exports = { AppsError: AppsError, hasAccessTo: hasAccessTo, + removeInternalAppFields: removeInternalAppFields, get: get, getByIpAddress: getByIpAddress, @@ -83,7 +84,8 @@ var addons = require('./addons.js'), url = require('url'), util = require('util'), uuid = require('uuid'), - validator = require('validator'); + validator = require('validator'), + _ = require('underscore'); // http://dustinsenos.com/articles/customErrorsInNode // http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi @@ -322,6 +324,13 @@ function getAppConfig(app) { }; } +function removeInternalAppFields(app) { + return _.pick(app, 'id', 'appStoreId', 'installationState', 'installationProgress', 'runState', 'health', + 'location', 'domain', 'fqdn', + 'accessRestriction', 'manifest', 'portBindings', 'iconUrl', 'memoryLimit', 'xFrameOptions', + 'sso', 'debugMode', 'robotsTxt', 'enableBackup', 'creationTime', 'updateTime'); +} + function getIconUrlSync(app) { var iconPath = paths.APP_ICONS_DIR + '/' + app.id + '.png'; return fs.existsSync(iconPath) ? '/api/v1/apps/' + app.id + '/icon' : null; diff --git a/src/routes/apps.js b/src/routes/apps.js index a51dd1ab9..a1f7b8c57 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -43,32 +43,6 @@ function auditSource(req) { return { ip: ip, username: req.user ? req.user.username : null, userId: req.user ? req.user.id : null }; } -function removeInternalAppFields(app) { - return { - id: app.id, - appStoreId: app.appStoreId, - installationState: app.installationState, - installationProgress: app.installationProgress, - runState: app.runState, - health: app.health, - location: app.location, - domain: app.domain, - accessRestriction: app.accessRestriction, - manifest: app.manifest, - portBindings: app.portBindings, - iconUrl: app.iconUrl, - fqdn: app.fqdn, - memoryLimit: app.memoryLimit, - xFrameOptions: app.xFrameOptions, - sso: app.sso, - debugMode: app.debugMode, - robotsTxt: app.robotsTxt, - enableBackup: app.enableBackup, - creationTime: app.creationTime.toISOString(), - updateTime: app.updateTime.toISOString() - }; -} - function getApp(req, res, next) { assert.strictEqual(typeof req.params.id, 'string'); @@ -76,7 +50,7 @@ function getApp(req, res, next) { if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(404, 'No such app')); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(200, removeInternalAppFields(app))); + next(new HttpSuccess(200, apps.removeInternalAppFields(app))); }); } @@ -86,7 +60,7 @@ function getApps(req, res, next) { apps.getAll(function (error, allApps) { if (error) return next(new HttpError(500, error)); - allApps = allApps.map(removeInternalAppFields); + allApps = allApps.map(apps.removeInternalAppFields); next(new HttpSuccess(200, { apps: allApps })); }); @@ -98,7 +72,7 @@ function getAllByUser(req, res, next) { apps.getAllByUser(req.user, function (error, allApps) { if (error) return next(new HttpError(500, error)); - allApps = allApps.map(removeInternalAppFields); + allApps = allApps.map(apps.removeInternalAppFields); next(new HttpSuccess(200, { apps: allApps })); });