keep mongodb database names short
This commit is contained in:
@@ -2069,4 +2069,5 @@
|
|||||||
* Remove IP nginx configuration that redirects to dashboard after activation
|
* Remove IP nginx configuration that redirects to dashboard after activation
|
||||||
* dashboard: looks for search string in app title as well
|
* dashboard: looks for search string in app title as well
|
||||||
* Add vaapi caps for transcoding
|
* Add vaapi caps for transcoding
|
||||||
|
* Fix issue where the long mongodb database names where causing app indices of rocket.chat to overflow (> 127)
|
||||||
|
|
||||||
|
|||||||
+24
-9
@@ -1666,8 +1666,10 @@ function setupMongoDb(app, options, callback) {
|
|||||||
appdb.getAddonConfigByName(app.id, 'mongodb', '%MONGODB_PASSWORD', function (error, existingPassword) {
|
appdb.getAddonConfigByName(app.id, 'mongodb', '%MONGODB_PASSWORD', function (error, existingPassword) {
|
||||||
if (error && error.reason !== BoxError.NOT_FOUND) return callback(error);
|
if (error && error.reason !== BoxError.NOT_FOUND) return callback(error);
|
||||||
|
|
||||||
|
const database = hat(8 * 8); // 16 bytes. keep this short, so as to not overflow the 127 byte index length in MongoDB < 4.4
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
database: app.id,
|
database: database,
|
||||||
username: app.id,
|
username: app.id,
|
||||||
password: error ? hat(4 * 128) : existingPassword,
|
password: error ? hat(4 * 128) : existingPassword,
|
||||||
oplog: !!options.oplog
|
oplog: !!options.oplog
|
||||||
@@ -1707,18 +1709,20 @@ function clearMongodb(app, options, callback) {
|
|||||||
assert.strictEqual(typeof options, 'object');
|
assert.strictEqual(typeof options, 'object');
|
||||||
assert.strictEqual(typeof callback, 'function');
|
assert.strictEqual(typeof callback, 'function');
|
||||||
|
|
||||||
debugApp(app, 'Clearing mongodb');
|
|
||||||
|
|
||||||
getContainerDetails('mongodb', 'CLOUDRON_MONGODB_TOKEN', function (error, result) {
|
getContainerDetails('mongodb', 'CLOUDRON_MONGODB_TOKEN', function (error, result) {
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
request.post(`https://${result.ip}:3000/databases/${app.id}/clear?access_token=${result.token}`, { json: true, rejectUnauthorized: false }, function (error, response) {
|
appdb.getAddonConfigByName(app.id, 'mongodb', '%MONGODB_DATABASE', function (error, database) {
|
||||||
|
if (error) return callback(error);
|
||||||
|
|
||||||
|
request.post(`https://${result.ip}:3000/databases/${database}/clear?access_token=${result.token}`, { json: true, rejectUnauthorized: false }, function (error, response) {
|
||||||
if (error) return callback(new BoxError(BoxError.ADDONS_ERROR, `Network error clearing mongodb: ${error.message}`));
|
if (error) return callback(new BoxError(BoxError.ADDONS_ERROR, `Network error clearing mongodb: ${error.message}`));
|
||||||
if (response.statusCode !== 200) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error clearing mongodb. Status code: ${response.statusCode} message: ${response.body.message}`));
|
if (response.statusCode !== 200) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error clearing mongodb. Status code: ${response.statusCode} message: ${response.body.message}`));
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function teardownMongoDb(app, options, callback) {
|
function teardownMongoDb(app, options, callback) {
|
||||||
@@ -1726,18 +1730,21 @@ function teardownMongoDb(app, options, callback) {
|
|||||||
assert.strictEqual(typeof options, 'object');
|
assert.strictEqual(typeof options, 'object');
|
||||||
assert.strictEqual(typeof callback, 'function');
|
assert.strictEqual(typeof callback, 'function');
|
||||||
|
|
||||||
debugApp(app, 'Tearing down mongodb');
|
|
||||||
|
|
||||||
getContainerDetails('mongodb', 'CLOUDRON_MONGODB_TOKEN', function (error, result) {
|
getContainerDetails('mongodb', 'CLOUDRON_MONGODB_TOKEN', function (error, result) {
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
request.delete(`https://${result.ip}:3000/databases/${app.id}?access_token=${result.token}`, { json: true, rejectUnauthorized: false }, function (error, response) {
|
appdb.getAddonConfigByName(app.id, 'mongodb', '%MONGODB_DATABASE', function (error, database) {
|
||||||
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null);
|
||||||
|
if (error) return callback(error);
|
||||||
|
|
||||||
|
request.delete(`https://${result.ip}:3000/databases/${database}?access_token=${result.token}`, { json: true, rejectUnauthorized: false }, function (error, response) {
|
||||||
if (error) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error tearing down mongodb: ${error.message}`));
|
if (error) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error tearing down mongodb: ${error.message}`));
|
||||||
if (response.statusCode !== 200) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error tearing down mongodb. Status code: ${response.statusCode} message: ${response.body.message}`));
|
if (response.statusCode !== 200) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error tearing down mongodb. Status code: ${response.statusCode} message: ${response.body.message}`));
|
||||||
|
|
||||||
appdb.unsetAddonConfig(app.id, 'mongodb', callback);
|
appdb.unsetAddonConfig(app.id, 'mongodb', callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function backupMongoDb(app, options, callback) {
|
function backupMongoDb(app, options, callback) {
|
||||||
@@ -1750,9 +1757,13 @@ function backupMongoDb(app, options, callback) {
|
|||||||
getContainerDetails('mongodb', 'CLOUDRON_MONGODB_TOKEN', function (error, result) {
|
getContainerDetails('mongodb', 'CLOUDRON_MONGODB_TOKEN', function (error, result) {
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
const url = `https://${result.ip}:3000/databases/${app.id}/backup?access_token=${result.token}`;
|
appdb.getAddonConfigByName(app.id, 'mongodb', '%MONGODB_DATABASE', function (error, database) {
|
||||||
|
if (error) return callback(error);
|
||||||
|
|
||||||
|
const url = `https://${result.ip}:3000/databases/${database}/backup?access_token=${result.token}`;
|
||||||
pipeRequestToFile(url, dumpPath('mongodb', app.id), callback);
|
pipeRequestToFile(url, dumpPath('mongodb', app.id), callback);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreMongoDb(app, options, callback) {
|
function restoreMongoDb(app, options, callback) {
|
||||||
@@ -1767,10 +1778,13 @@ function restoreMongoDb(app, options, callback) {
|
|||||||
getContainerDetails('mongodb', 'CLOUDRON_MONGODB_TOKEN', function (error, result) {
|
getContainerDetails('mongodb', 'CLOUDRON_MONGODB_TOKEN', function (error, result) {
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
|
appdb.getAddonConfigByName(app.id, 'mongodb', '%MONGODB_DATABASE', function (error, database) {
|
||||||
|
if (error) return callback(error);
|
||||||
|
|
||||||
const readStream = fs.createReadStream(dumpPath('mongodb', app.id));
|
const readStream = fs.createReadStream(dumpPath('mongodb', app.id));
|
||||||
readStream.on('error', (error) => callback(new BoxError(BoxError.FS_ERROR, `Error reading input stream when restoring mongodb: ${error.message}`)));
|
readStream.on('error', (error) => callback(new BoxError(BoxError.FS_ERROR, `Error reading input stream when restoring mongodb: ${error.message}`)));
|
||||||
|
|
||||||
const restoreReq = request.post(`https://${result.ip}:3000/databases/${app.id}/restore?access_token=${result.token}`, { json: true, rejectUnauthorized: false }, function (error, response) {
|
const restoreReq = request.post(`https://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}`, { json: true, rejectUnauthorized: false }, function (error, response) {
|
||||||
if (error) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error restoring mongodb: ${error.message}`));
|
if (error) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error restoring mongodb: ${error.message}`));
|
||||||
if (response.statusCode !== 200) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error restoring mongodb. Status code: ${response.statusCode} message: ${response.body.message}`));
|
if (response.statusCode !== 200) return callback(new BoxError(BoxError.ADDONS_ERROR, `Error restoring mongodb. Status code: ${response.statusCode} message: ${response.body.message}`));
|
||||||
|
|
||||||
@@ -1779,6 +1793,7 @@ function restoreMongoDb(app, options, callback) {
|
|||||||
|
|
||||||
readStream.pipe(restoreReq);
|
readStream.pipe(restoreReq);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function startRedis(existingInfra, callback) {
|
function startRedis(existingInfra, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user