domain: split the config and wellknown routes

we want to add more stuff to the UI like the jitsi URL
This commit is contained in:
Girish Ramakrishnan
2021-12-03 13:46:54 -08:00
parent 5592dc8a42
commit 39807e6ba4
8 changed files with 107 additions and 41 deletions
+21 -13
View File
@@ -4,7 +4,8 @@ exports = module.exports = {
add,
get,
list,
update,
setConfig,
setWellKnown,
del,
checkDnsRecords,
@@ -76,7 +77,7 @@ async function list(req, res, next) {
next(new HttpSuccess(200, { domains: results }));
}
async function update(req, res, next) {
async function setConfig(req, res, next) {
assert.strictEqual(typeof req.params.domain, 'string');
assert.strictEqual(typeof req.body, 'object');
@@ -98,26 +99,33 @@ async function update(req, res, next) {
if (!req.body.tlsConfig.provider || typeof req.body.tlsConfig.provider !== 'string') return next(new HttpError(400, 'tlsConfig.provider must be a string'));
}
if ('wellKnown' in req.body) {
if (typeof req.body.wellKnown !== 'object') return next(new HttpError(400, 'wellKnown must be an object'));
if (req.body.wellKnown) {
if (Object.keys(req.body.wellKnown).some(k => typeof req.body.wellKnown[k] !== 'string')) return next(new HttpError(400, 'wellKnown is a map of strings'));
}
}
// some DNS providers like DigitalOcean take a really long time to verify credentials (https://github.com/expressjs/timeout/issues/26)
req.clearTimeout();
let data = {
const data = {
zoneName: req.body.zoneName || '',
provider: req.body.provider,
config: req.body.config,
fallbackCertificate: req.body.fallbackCertificate || null,
tlsConfig: req.body.tlsConfig || { provider: 'letsencrypt-prod' },
wellKnown: req.body.wellKnown || null
tlsConfig: req.body.tlsConfig || { provider: 'letsencrypt-prod' }
};
const [error] = await safe(domains.update(req.params.domain, data, AuditSource.fromRequest(req)));
const [error] = await safe(domains.setConfig(req.params.domain, data, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204, {}));
}
async function setWellKnown(req, res, next) {
assert.strictEqual(typeof req.params.domain, 'string');
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.wellKnown !== 'object') return next(new HttpError(400, 'wellKnown must be an object'));
if (req.body.wellKnown) {
if (Object.keys(req.body.wellKnown).some(k => typeof req.body.wellKnown[k] !== 'string')) return next(new HttpError(400, 'wellKnown is a map of strings'));
}
const [error] = await safe(domains.setWellKnown(req.params.domain, req.body.wellKnown || null, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204, {}));