diff --git a/src/domains.js b/src/domains.js index 5c7bc6ba2..acd6a4673 100644 --- a/src/domains.js +++ b/src/domains.js @@ -16,6 +16,8 @@ module.exports = exports = { waitForDnsRecord: waitForDnsRecord, + removePrivateFields: removePrivateFields, + DomainError: DomainError }; @@ -32,7 +34,8 @@ var assert = require('assert'), shell = require('./shell.js'), sysinfo = require('./sysinfo.js'), tld = require('tldjs'), - util = require('util'); + util = require('util'), + _ = require('underscore'); var RESTART_CMD = path.join(__dirname, 'scripts/restart.sh'); var NOOP_CALLBACK = function (error) { if (error) debug(error); }; @@ -357,3 +360,8 @@ function fqdn(location, domain, provider) { return location + (location ? (provider !== 'caas' ? '.' : '-') : '') + domain; } +function removePrivateFields(domain) { + var result = _.pick(domain, 'domain', 'zoneName', 'provider', 'config', 'tlsConfig', 'fallbackCertificate'); + if (result.fallbackCertificate) delete result.fallbackCertificate.key; // do not return the 'key'. in caas, this is private + return result; +} \ No newline at end of file diff --git a/src/routes/domains.js b/src/routes/domains.js index c69f3f261..1243ebe24 100644 --- a/src/routes/domains.js +++ b/src/routes/domains.js @@ -47,9 +47,7 @@ function get(req, res, next) { if (error && error.reason === DomainError.NOT_FOUND) return next(new HttpError(404, error.message)); if (error) return next(new HttpError(500, error)); - delete result.fallbackCertificate.key; // do not return the 'key'. in caas, this is private - - next(new HttpSuccess(200, result)); + next(new HttpSuccess(200, domains.removePrivateFields(result))); }); } @@ -57,6 +55,8 @@ function getAll(req, res, next) { domains.getAll(function (error, result) { if (error) return next(new HttpError(500, error)); + result = result.map(domains.removePrivateFields); + next(new HttpSuccess(200, { domains: result })); }); }