translate port bindings after validation
This commit is contained in:
+9
-12
@@ -240,13 +240,13 @@ function validatePortBindings(portBindings, manifest) {
|
||||
|
||||
if (!portBindings) return null;
|
||||
|
||||
const tcpPorts = manifest.tcpPorts || { };
|
||||
const udpPorts = manifest.udpPorts || { };
|
||||
const tcpPorts = manifest.tcpPorts || {};
|
||||
const udpPorts = manifest.udpPorts || {};
|
||||
|
||||
for (const portName in portBindings) {
|
||||
if (!/^[A-Z0-9_]+$/.test(portName)) return new BoxError(BoxError.BAD_FIELD, `${portName} is not a valid environment variable in portBindings`);
|
||||
|
||||
const hostPort = portBindings[portName].hostPort;
|
||||
const hostPort = portBindings[portName];
|
||||
if (!Number.isInteger(hostPort)) return new BoxError(BoxError.BAD_FIELD, `${hostPort} is not an integer in ${portName} portBindings`);
|
||||
if (RESERVED_PORTS.indexOf(hostPort) !== -1) return new BoxError(BoxError.BAD_FIELD, `Port ${hostPort} for ${portName} is reserved in portBindings`);
|
||||
if (RESERVED_PORT_RANGES.find(range => (hostPort >= range[0] && hostPort <= range[1]))) return new BoxError(BoxError.BAD_FIELD, `Port ${hostPort} for ${portName} is reserved in portBindings`);
|
||||
@@ -1287,7 +1287,6 @@ async function install(data, auditSource) {
|
||||
|
||||
const subdomain = data.subdomain.toLowerCase(),
|
||||
domain = data.domain.toLowerCase(),
|
||||
portBindings = translatePortBindings(data.portBindings || null, data.manifest),
|
||||
accessRestriction = data.accessRestriction || null,
|
||||
memoryLimit = data.memoryLimit || 0,
|
||||
debugMode = data.debugMode || null,
|
||||
@@ -1312,8 +1311,9 @@ async function install(data, auditSource) {
|
||||
error = checkManifestConstraints(manifest);
|
||||
if (error) throw error;
|
||||
|
||||
error = validatePortBindings(portBindings, manifest);
|
||||
error = validatePortBindings(data.portBindings || null, manifest);
|
||||
if (error) throw error;
|
||||
const portBindings = translatePortBindings(data.portBindings || null, manifest);
|
||||
|
||||
error = validateAccessRestriction(accessRestriction);
|
||||
if (error) throw error;
|
||||
@@ -1851,10 +1851,9 @@ async function setLocation(app, data, auditSource) {
|
||||
};
|
||||
|
||||
if ('portBindings' in data) {
|
||||
values.portBindings = translatePortBindings(data.portBindings || null, app.manifest);
|
||||
|
||||
error = validatePortBindings(values.portBindings, app.manifest);
|
||||
error = validatePortBindings(data.portBindings || null, app.manifest);
|
||||
if (error) throw error;
|
||||
values.portBindings = translatePortBindings(data.portBindings || null, app.manifest);
|
||||
}
|
||||
|
||||
// rename the auto-created mailbox to match the new location
|
||||
@@ -2258,7 +2257,6 @@ async function clone(app, data, user, auditSource) {
|
||||
|
||||
const subdomain = data.subdomain.toLowerCase(),
|
||||
domain = data.domain.toLowerCase(),
|
||||
portBindings = data.portBindings || null,
|
||||
backupId = data.backupId,
|
||||
overwriteDns = 'overwriteDns' in data ? data.overwriteDns : false,
|
||||
skipDnsSetup = 'skipDnsSetup' in data ? data.skipDnsSetup : false;
|
||||
@@ -2276,8 +2274,6 @@ async function clone(app, data, user, auditSource) {
|
||||
|
||||
const manifest = backupInfo.manifest, appStoreId = app.appStoreId;
|
||||
|
||||
const newPortBindings = translatePortBindings(data.portBindings, manifest);
|
||||
|
||||
let error = validateSecondaryDomains(data.secondaryDomains || {}, manifest);
|
||||
if (error) throw error;
|
||||
const secondaryDomains = translateSecondaryDomains(data.secondaryDomains || {});
|
||||
@@ -2292,8 +2288,9 @@ async function clone(app, data, user, auditSource) {
|
||||
error = checkManifestConstraints(manifest);
|
||||
if (error) throw error;
|
||||
|
||||
error = validatePortBindings(newPortBindings, manifest);
|
||||
error = validatePortBindings(data.portBindings || null, manifest);
|
||||
if (error) throw error;
|
||||
const newPortBindings = translatePortBindings(data.portBindings || null, manifest);
|
||||
|
||||
// should we copy the original app's mailbox settings instead?
|
||||
const mailboxName = manifest.addons?.sendmail ? mailboxNameForSubdomain(subdomain, manifest) : null;
|
||||
|
||||
Reference in New Issue
Block a user