rename location to subdomain
the primary subdomain was previously called 'location'. but the alias/secondary/redirect
subdomain is called 'subdomain'. this makes it all consistent.
location terminology is now used for { subdomain, domain } pair
This commit is contained in:
+33
-33
@@ -519,7 +519,7 @@ function getDataDir(app, dataDir) {
|
||||
function removeInternalFields(app) {
|
||||
return _.pick(app,
|
||||
'id', 'appStoreId', 'installationState', 'error', 'runState', 'health', 'taskId',
|
||||
'location', 'domain', 'fqdn', 'crontab',
|
||||
'subdomain', 'domain', 'fqdn', 'crontab',
|
||||
'accessRestriction', 'manifest', 'portBindings', 'iconUrl', 'memoryLimit', 'cpuShares', 'operators',
|
||||
'sso', 'debugMode', 'reverseProxyConfig', 'enableBackup', 'creationTime', 'updateTime', 'ts', 'tags',
|
||||
'label', 'secondaryDomains', 'redirectDomains', 'aliasDomains', 'env', 'enableAutomaticUpdate', 'dataDir', 'mounts',
|
||||
@@ -530,7 +530,7 @@ function removeInternalFields(app) {
|
||||
function removeRestrictedFields(app) {
|
||||
return _.pick(app,
|
||||
'id', 'appStoreId', 'installationState', 'error', 'runState', 'health', 'taskId', 'accessRestriction', 'secondaryDomains', 'redirectDomains', 'aliasDomains', 'sso',
|
||||
'location', 'domain', 'fqdn', 'manifest', 'portBindings', 'iconUrl', 'creationTime', 'ts', 'tags', 'label', 'enableBackup');
|
||||
'subdomain', 'domain', 'fqdn', 'manifest', 'portBindings', 'iconUrl', 'creationTime', 'ts', 'tags', 'label', 'enableBackup');
|
||||
}
|
||||
|
||||
async function getIcon(app, options) {
|
||||
@@ -640,7 +640,7 @@ function postProcess(result) {
|
||||
result.aliasDomains = [];
|
||||
for (let i = 0; i < subdomainTypes.length; i++) {
|
||||
if (subdomainTypes[i] === exports.SUBDOMAIN_TYPE_PRIMARY) {
|
||||
result.location = subdomains[i];
|
||||
result.subdomain = subdomains[i];
|
||||
result.domain = domains[i];
|
||||
} else if (subdomainTypes[i] === exports.SUBDOMAIN_TYPE_SECONDARY) {
|
||||
result.secondaryDomains.push({ domain: domains[i], subdomain: subdomains[i], environmentVariable: subdomainEnvironmentVariables[i] });
|
||||
@@ -682,7 +682,7 @@ function attachProperties(app, domainObjectMap) {
|
||||
}
|
||||
app.portBindings = result;
|
||||
app.iconUrl = app.hasIcon || app.hasAppStoreIcon ? `/api/v1/apps/${app.id}/icon` : null;
|
||||
app.fqdn = dns.fqdn(app.location, domainObjectMap[app.domain]);
|
||||
app.fqdn = dns.fqdn(app.subdomain, domainObjectMap[app.domain]);
|
||||
app.secondaryDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
app.redirectDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
app.aliasDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
@@ -726,12 +726,12 @@ function accessLevel(app, user) {
|
||||
return canAccess(app, user) ? 'user' : null;
|
||||
}
|
||||
|
||||
async function add(id, appStoreId, manifest, location, domain, portBindings, data) {
|
||||
async function add(id, appStoreId, manifest, subdomain, domain, portBindings, data) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof appStoreId, 'string');
|
||||
assert(manifest && typeof manifest === 'object');
|
||||
assert.strictEqual(typeof manifest.version, 'string');
|
||||
assert.strictEqual(typeof location, 'string');
|
||||
assert.strictEqual(typeof subdomain, 'string');
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
assert.strictEqual(typeof portBindings, 'object');
|
||||
assert(data && typeof data === 'object');
|
||||
@@ -770,7 +770,7 @@ async function add(id, appStoreId, manifest, location, domain, portBindings, dat
|
||||
|
||||
queries.push({
|
||||
query: 'INSERT INTO subdomains (appId, domain, subdomain, type) VALUES (?, ?, ?, ?)',
|
||||
args: [ id, domain, location, exports.SUBDOMAIN_TYPE_PRIMARY ]
|
||||
args: [ id, domain, subdomain, exports.SUBDOMAIN_TYPE_PRIMARY ]
|
||||
});
|
||||
|
||||
Object.keys(portBindings).forEach(function (env) {
|
||||
@@ -863,9 +863,9 @@ async function updateWithConstraints(id, app, constraints) {
|
||||
});
|
||||
}
|
||||
|
||||
if ('location' in app && 'domain' in app) { // must be updated together as they are unique together
|
||||
if ('subdomain' in app && 'domain' in app) { // must be updated together as they are unique together
|
||||
queries.push({ query: 'DELETE FROM subdomains WHERE appId = ?', args: [ id ]}); // all locations of an app must be updated together
|
||||
queries.push({ query: 'INSERT INTO subdomains (appId, domain, subdomain, type) VALUES (?, ?, ?, ?)', args: [ id, app.domain, app.location, exports.SUBDOMAIN_TYPE_PRIMARY ]});
|
||||
queries.push({ query: 'INSERT INTO subdomains (appId, domain, subdomain, type) VALUES (?, ?, ?, ?)', args: [ id, app.domain, app.subdomain, exports.SUBDOMAIN_TYPE_PRIMARY ]});
|
||||
|
||||
if ('secondaryDomains' in app) {
|
||||
app.secondaryDomains.forEach(function (d) {
|
||||
@@ -898,7 +898,7 @@ async function updateWithConstraints(id, app, constraints) {
|
||||
if (p === 'manifest' || p === 'tags' || p === 'accessRestriction' || p === 'debugMode' || p === 'error' || p === 'reverseProxyConfig' || p === 'servicesConfig' || p === 'operators') {
|
||||
fields.push(`${p}Json = ?`);
|
||||
values.push(JSON.stringify(app[p]));
|
||||
} else if (p !== 'portBindings' && p !== 'location' && p !== 'domain' && p !== 'secondaryDomains' && p !== 'redirectDomains' && p !== 'aliasDomains' && p !== 'env' && p !== 'mounts') {
|
||||
} else if (p !== 'portBindings' && p !== 'subdomain' && p !== 'domain' && p !== 'secondaryDomains' && p !== 'redirectDomains' && p !== 'aliasDomains' && p !== 'env' && p !== 'mounts') {
|
||||
fields.push(p + ' = ?');
|
||||
values.push(app[p]);
|
||||
}
|
||||
@@ -1077,8 +1077,8 @@ async function downloadManifest(appStoreId, manifest) {
|
||||
return { appStoreId: parts[0], manifest: response.body.manifest };
|
||||
}
|
||||
|
||||
function mailboxNameForLocation(location, manifest) {
|
||||
if (location) return `${location}.app`;
|
||||
function mailboxNameForSubdomain(subdomain, manifest) {
|
||||
if (subdomain) return `${subdomain}.app`;
|
||||
if (manifest.title) return manifest.title.toLowerCase().replace(/[^a-zA-Z0-9]/g, '') + '.app';
|
||||
return 'noreply.app';
|
||||
}
|
||||
@@ -1228,7 +1228,7 @@ async function install(data, auditSource) {
|
||||
|
||||
assert.strictEqual(typeof data.manifest, 'object'); // manifest is already downloaded
|
||||
|
||||
const location = data.location.toLowerCase(),
|
||||
const subdomain = data.subdomain.toLowerCase(),
|
||||
domain = data.domain.toLowerCase(),
|
||||
portBindings = data.portBindings || null,
|
||||
accessRestriction = data.accessRestriction || null,
|
||||
@@ -1290,7 +1290,7 @@ async function install(data, auditSource) {
|
||||
|
||||
// sendmail is enabled by default
|
||||
const enableMailbox = 'enableMailbox' in data ? data.enableMailbox : true;
|
||||
const mailboxName = manifest.addons?.sendmail ? mailboxNameForLocation(location, manifest) : null;
|
||||
const mailboxName = manifest.addons?.sendmail ? mailboxNameForSubdomain(subdomain, manifest) : null;
|
||||
const mailboxDomain = manifest.addons?.sendmail ? domain : null;
|
||||
|
||||
let icon = data.icon || null;
|
||||
@@ -1299,7 +1299,7 @@ async function install(data, auditSource) {
|
||||
icon = Buffer.from(icon, 'base64');
|
||||
}
|
||||
|
||||
const locations = [{ subdomain: location, domain, type: exports.SUBDOMAIN_TYPE_PRIMARY }]
|
||||
const locations = [{ subdomain: subdomain, domain, type: exports.SUBDOMAIN_TYPE_PRIMARY }]
|
||||
.concat(secondaryDomains.map(ad => _.extend(ad, { type: exports.SUBDOMAIN_TYPE_SECONDARY })))
|
||||
.concat(redirectDomains.map(ad => _.extend(ad, { type: exports.SUBDOMAIN_TYPE_REDIRECT })))
|
||||
.concat(aliasDomains.map(ad => _.extend(ad, { type: exports.SUBDOMAIN_TYPE_ALIAS })));
|
||||
@@ -1332,7 +1332,7 @@ async function install(data, auditSource) {
|
||||
installationState: exports.ISTATE_PENDING_INSTALL
|
||||
};
|
||||
|
||||
const [addError] = await safe(add(appId, appStoreId, manifest, location, domain, translatePortBindings(portBindings, manifest), app));
|
||||
const [addError] = await safe(add(appId, appStoreId, manifest, subdomain, domain, translatePortBindings(portBindings, manifest), app));
|
||||
if (addError && addError.reason === BoxError.ALREADY_EXISTS) throw getDuplicateErrorDetails(addError.message, locations, domainObjectMap, portBindings);
|
||||
if (addError) throw addError;
|
||||
|
||||
@@ -1346,8 +1346,8 @@ async function install(data, auditSource) {
|
||||
|
||||
const taskId = await addTask(appId, app.installationState, task, auditSource);
|
||||
|
||||
const newApp = _.extend({}, _.omit(app, 'icon'), { appStoreId, manifest, location, domain, portBindings });
|
||||
newApp.fqdn = dns.fqdn(newApp.location, domainObjectMap[newApp.domain]);
|
||||
const newApp = _.extend({}, _.omit(app, 'icon'), { appStoreId, manifest, location: subdomain, domain, portBindings });
|
||||
newApp.fqdn = dns.fqdn(newApp.subdomain, domainObjectMap[newApp.domain]);
|
||||
newApp.secondaryDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
newApp.redirectDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
newApp.aliasDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
@@ -1578,7 +1578,7 @@ async function setMailbox(app, data, auditSource) {
|
||||
error = mail.validateName(mailboxName);
|
||||
if (error) throw new BoxError(BoxError.BAD_FIELD, error.message, { field: 'mailboxName' });
|
||||
} else {
|
||||
mailboxName = mailboxNameForLocation(app.location, app.domain, app.manifest);
|
||||
mailboxName = mailboxNameForSubdomain(app.subdomain, app.domain, app.manifest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1698,7 +1698,7 @@ async function setLocation(app, data, auditSource) {
|
||||
if (error) throw error;
|
||||
|
||||
let values = {
|
||||
location: data.location.toLowerCase(),
|
||||
location: data.subdomain.toLowerCase(),
|
||||
domain: data.domain.toLowerCase(),
|
||||
// these are intentionally reset, if not set
|
||||
portBindings: null,
|
||||
@@ -1716,7 +1716,7 @@ async function setLocation(app, data, auditSource) {
|
||||
|
||||
// rename the auto-created mailbox to match the new location
|
||||
if (app.manifest.addons?.sendmail && app.mailboxName?.endsWith('.app')) {
|
||||
values.mailboxName = mailboxNameForLocation(values.location, app.manifest);
|
||||
values.mailboxName = mailboxNameForSubdomain(values.subdomain, app.manifest);
|
||||
values.mailboxDomain = values.domain;
|
||||
}
|
||||
|
||||
@@ -1735,7 +1735,7 @@ async function setLocation(app, data, auditSource) {
|
||||
values.aliasDomains = data.aliasDomains;
|
||||
}
|
||||
|
||||
const locations = [{ subdomain: values.location, domain: values.domain, type: exports.SUBDOMAIN_TYPE_PRIMARY }]
|
||||
const locations = [{ subdomain: values.subdomain, domain: values.domain, type: exports.SUBDOMAIN_TYPE_PRIMARY }]
|
||||
.concat(values.secondaryDomains.map(ad => _.extend(ad, { type: exports.SUBDOMAIN_TYPE_SECONDARY })))
|
||||
.concat(values.redirectDomains.map(ad => _.extend(ad, { type: exports.SUBDOMAIN_TYPE_REDIRECT })))
|
||||
.concat(values.aliasDomains.map(ad => _.extend(ad, { type: exports.SUBDOMAIN_TYPE_ALIAS })));
|
||||
@@ -1754,7 +1754,7 @@ async function setLocation(app, data, auditSource) {
|
||||
if (taskError && taskError.reason === BoxError.ALREADY_EXISTS) taskError = getDuplicateErrorDetails(taskError.message, locations, domainObjectMap, data.portBindings);
|
||||
if (taskError) throw taskError;
|
||||
|
||||
values.fqdn = dns.fqdn(values.location, domainObjectMap[values.domain]);
|
||||
values.fqdn = dns.fqdn(values.subdomain, domainObjectMap[values.domain]);
|
||||
values.secondaryDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
values.redirectDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
values.aliasDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
@@ -1846,7 +1846,7 @@ async function updateApp(app, data, auditSource) {
|
||||
if (!manifest.addons?.sendmail) { // clear if the update removed addon
|
||||
values.mailboxName = values.mailboxDomain = null;
|
||||
} else if (!app.mailboxName || app.mailboxName.endsWith('.app')) { // allocate since update added the addon
|
||||
values.mailboxName = mailboxNameForLocation(app.location, manifest);
|
||||
values.mailboxName = mailboxNameForSubdomain(app.subdomain, manifest);
|
||||
values.mailboxDomain = app.domain;
|
||||
}
|
||||
|
||||
@@ -1975,7 +1975,7 @@ async function repair(app, data, auditSource) {
|
||||
if (!data.manifest.addons?.sendmail) { // clear if repair removed addon
|
||||
task.values.mailboxName = task.values.mailboxDomain = null;
|
||||
} else if (!app.mailboxName || app.mailboxName.endsWith('.app')) { // allocate since repair added the addon
|
||||
task.values.mailboxName = mailboxNameForLocation(app.location, data.manifest);
|
||||
task.values.mailboxName = mailboxNameForSubdomain(app.subdomain, data.manifest);
|
||||
task.values.mailboxDomain = app.domain;
|
||||
}
|
||||
|
||||
@@ -2021,7 +2021,7 @@ async function restore(app, backupId, auditSource) {
|
||||
if (!backupInfo.manifest.addons?.sendmail) { // clear if restore removed addon
|
||||
values.mailboxName = values.mailboxDomain = null;
|
||||
} else if (!app.mailboxName || app.mailboxName.endsWith('.app')) { // allocate since restore added the addon
|
||||
values.mailboxName = mailboxNameForLocation(app.location, backupInfo.manifest);
|
||||
values.mailboxName = mailboxNameForSubdomain(app.subdomain, backupInfo.manifest);
|
||||
values.mailboxDomain = app.domain;
|
||||
}
|
||||
|
||||
@@ -2146,7 +2146,7 @@ async function clone(app, data, user, auditSource) {
|
||||
assert(user && typeof user === 'object');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
const location = data.location.toLowerCase(),
|
||||
const subdomain = data.subdomain.toLowerCase(),
|
||||
domain = data.domain.toLowerCase(),
|
||||
portBindings = data.portBindings || null,
|
||||
backupId = data.backupId,
|
||||
@@ -2155,11 +2155,11 @@ async function clone(app, data, user, auditSource) {
|
||||
appId = app.id;
|
||||
|
||||
assert.strictEqual(typeof backupId, 'string');
|
||||
assert.strictEqual(typeof location, 'string');
|
||||
assert.strictEqual(typeof subdomain, 'string');
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
assert.strictEqual(typeof portBindings, 'object');
|
||||
|
||||
const locations = [{ subdomain: location, domain, type: 'primary' }];
|
||||
const locations = [{ subdomain: subdomain, domain, type: 'primary' }];
|
||||
const domainObjectMap = await validateLocations(locations);
|
||||
const backupInfo = await backups.get(backupId);
|
||||
|
||||
@@ -2176,7 +2176,7 @@ async function clone(app, data, user, auditSource) {
|
||||
if (error) throw error;
|
||||
|
||||
// should we copy the original app's mailbox settings instead?
|
||||
const mailboxName = manifest.addons?.sendmail ? mailboxNameForLocation(location, manifest) : null;
|
||||
const mailboxName = manifest.addons?.sendmail ? mailboxNameForSubdomain(subdomain, manifest) : null;
|
||||
const mailboxDomain = manifest.addons?.sendmail ? domain : null;
|
||||
|
||||
const newAppId = uuid.v4();
|
||||
@@ -2206,7 +2206,7 @@ async function clone(app, data, user, auditSource) {
|
||||
enableMailbox: app.enableMailbox
|
||||
};
|
||||
|
||||
const [addError] = await safe(add(newAppId, appStoreId, manifest, location, domain, translatePortBindings(portBindings, manifest), obj));
|
||||
const [addError] = await safe(add(newAppId, appStoreId, manifest, subdomain, domain, translatePortBindings(portBindings, manifest), obj));
|
||||
if (addError && addError.reason === BoxError.ALREADY_EXISTS) throw getDuplicateErrorDetails(addError.message, locations, domainObjectMap, portBindings);
|
||||
if (addError) throw addError;
|
||||
|
||||
@@ -2220,8 +2220,8 @@ async function clone(app, data, user, auditSource) {
|
||||
};
|
||||
const taskId = await addTask(newAppId, exports.ISTATE_PENDING_CLONE, task, auditSource);
|
||||
|
||||
const newApp = _.extend({}, _.omit(obj, 'icon'), { appStoreId, manifest, location, domain, portBindings });
|
||||
newApp.fqdn = dns.fqdn(newApp.location, domainObjectMap[newApp.domain]);
|
||||
const newApp = _.extend({}, _.omit(obj, 'icon'), { appStoreId, manifest, location: subdomain, domain, portBindings });
|
||||
newApp.fqdn = dns.fqdn(newApp.subdomain, domainObjectMap[newApp.domain]);
|
||||
newApp.secondaryDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
newApp.redirectDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
newApp.aliasDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
|
||||
Reference in New Issue
Block a user