better naming of the dashboard functions

This commit is contained in:
Girish Ramakrishnan
2023-08-13 10:29:24 +05:30
parent e723c3c19b
commit a7be30a816
7 changed files with 55 additions and 60 deletions
+26 -45
View File
@@ -3,12 +3,12 @@
exports = module.exports = {
getLocation,
setLocation,
clearLocation,
setupDnsAndCert,
prepareDomain,
setDashboardDomain,
switchDomain,
prepareLocation,
changeLocation,
getConfig,
};
@@ -24,24 +24,14 @@ const apps = require('./apps.js'),
dns = require('./dns.js'),
mailServer = require('./mailserver.js'),
network = require('./network.js'),
oidc = require('./oidc.js'),
platform = require('./platform.js'),
reverseProxy = require('./reverseproxy.js'),
safe = require('safetydance'),
services = require('./services.js'),
settings = require('./settings.js'),
system = require('./system.js'),
tasks = require('./tasks.js'),
users = require('./users.js');
async function setLocation(domain, fqdn) {
assert.strictEqual(typeof domain, 'string');
assert.strictEqual(typeof fqdn, 'string');
// should probably be just one key. or make this a transaction
await settings.set(settings.DASHBOARD_DOMAIN_KEY, domain);
await settings.set(settings.DASHBOARD_FQDN_KEY, fqdn);
}
async function getLocation() {
const domain = await settings.get(settings.DASHBOARD_DOMAIN_KEY) || '';
const fqdn = await settings.get(settings.DASHBOARD_FQDN_KEY) || '';
@@ -49,6 +39,20 @@ async function getLocation() {
return { domain, fqdn, subdomain: constants.DASHBOARD_SUBDOMAIN };
}
async function setLocation(domain) {
assert.strictEqual(typeof domain, 'string');
const fqdn = dns.fqdn(constants.DASHBOARD_SUBDOMAIN, domain);
await settings.set(settings.DASHBOARD_DOMAIN_KEY, domain);
await settings.set(settings.DASHBOARD_FQDN_KEY, fqdn);
debug(`setLocation: ${domain}`);
}
async function clearLocation() {
await setLocation('');
}
async function getConfig() {
const ubuntuVersion = await system.getUbuntuVersion();
const profileConfig = await users.getProfileConfig();
@@ -73,62 +77,39 @@ async function getConfig() {
};
}
async function prepareDomain(domain, auditSource) {
async function prepareLocation(domain, auditSource) {
assert.strictEqual(typeof domain, 'string');
assert.strictEqual(typeof auditSource, 'object');
debug(`prepareDomain: ${domain}`);
debug(`prepareLocation: ${domain}`);
if (constants.DEMO) throw new BoxError(BoxError.CONFLICT, 'Not allowed in demo mode');
const fqdn = dns.fqdn(constants.DASHBOARD_SUBDOMAIN, domain);
const result = await apps.list();
if (result.some(app => app.fqdn === fqdn)) throw new BoxError(BoxError.BAD_STATE, 'Dashboard location conflicts with an existing app');
const taskId = await tasks.add(tasks.TASK_SETUP_DNS_AND_CERT, [ constants.DASHBOARD_SUBDOMAIN, domain, auditSource ]);
tasks.startTask(taskId, {});
return taskId;
}
// call this only pre activation since it won't start mail server
async function setDashboardDomain(domain, auditSource) {
async function changeLocation(domain, auditSource) {
assert.strictEqual(typeof domain, 'string');
assert.strictEqual(typeof auditSource, 'object');
debug(`setDashboardDomain: ${domain}`);
debug(`changeLocation: ${domain}`);
if (constants.DEMO) throw new BoxError(BoxError.CONFLICT, 'Not allowed in demo mode');
await reverseProxy.writeDashboardConfig(domain);
const fqdn = dns.fqdn(constants.DASHBOARD_SUBDOMAIN, domain);
await setLocation(domain, fqdn);
await setLocation(domain);
await safe(appstore.updateCloudron({ domain }), { debug });
await eventlog.add(eventlog.ACTION_DASHBOARD_DOMAIN_UPDATE, auditSource, { domain, fqdn });
}
// call this only post activation because it will restart mail server
async function switchDomain(domain, auditSource) {
assert.strictEqual(typeof domain, 'string');
assert.strictEqual(typeof auditSource, 'object');
debug(`switchDomain: ${domain}`);
if (constants.DEMO) throw new BoxError(BoxError.CONFLICT, 'Not allowed in demo mode');
await setDashboardDomain(domain, auditSource);
// mark apps using oidc addon to be reconfigured
const [, installedApps] = await safe(apps.list());
await safe(apps.configureInstalledApps(installedApps.filter((a) => !!a.manifest.addons.oidc), auditSource));
await safe(services.rebuildService('turn', auditSource), { debug }); // to update the realm variable
await oidc.stop();
await oidc.start();
await platform.onDashboardLocationChanged(auditSource);
}
async function setupDnsAndCert(subdomain, domain, auditSource, progressCallback) {