reverseproxy: add setUserCertificate

This commit is contained in:
Girish Ramakrishnan
2022-07-14 13:25:41 +05:30
parent d33fd7b886
commit 885d60f7cc
2 changed files with 20 additions and 14 deletions

View File

@@ -1779,12 +1779,12 @@ async function setCertificate(app, data, auditSource) {
if (error) throw error;
}
const certificateJson = cert && key ? JSON.stringify({ cert, key }) : null;
const result = await database.query('UPDATE locations SET certificateJson=? WHERE location=? AND domain=?', [ certificateJson, subdomain, domain ]);
const certificate = cert && key ? { cert, key } : null;
const result = await database.query('UPDATE locations SET certificateJson=? WHERE location=? AND domain=?', [ certificate ? JSON.stringify(certificate) : null, subdomain, domain ]);
if (result.affectedRows === 0) throw new BoxError(BoxError.NOT_FOUND, 'Location not found');
app = await get(app.id); // refresh app object
await reverseProxy.writeAppConfigs(app);
await reverseProxy.setUserCertificate(app, dns.fqdn(subdomain, domainObject), certificate);
await eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: app.id, app, subdomain, domain, cert });
}