Read user's database_host from redis, when available (#88)

Still lacks a testcase
This commit is contained in:
Sandro Santilli 2013-11-11 17:23:10 +01:00
parent d7c82e7a51
commit 07cb36ebc7
2 changed files with 23 additions and 4 deletions

View File

@ -112,10 +112,14 @@ module.exports = function() {
this.retrieve(this.user_metadata_db, redisKey, 'database_host', function(err, dbname) { this.retrieve(this.user_metadata_db, redisKey, 'database_host', function(err, dbname) {
if ( err ) callback(err, null); if ( err ) callback(err, null);
else if ( dbname === null ) { else {
callback(new Error("missing " + username + "'s database_host in redis (try CARTODB/script/restore_redis)"), null); if ( dbname === null ) {
/* database_host was introduced in cartodb-2.5.0,
* for older versions we'll just use configured host */
//console.log("WARNING: missing " + username + "'s database_host in redis (try CARTODB/script/restore_redis)");
}
callback(err, dbname);
} }
else callback(err, dbname);
}); });
}; };

View File

@ -359,14 +359,22 @@ module.exports = function(){
req.params.interactivity = req.params.interactivity || 'cartodb_id'; req.params.interactivity = req.params.interactivity || 'cartodb_id';
req.params.processXML = function(req, xml, callback) { req.params.processXML = function(req, xml, callback) {
// Replace dbuser
var dbuser = req.params.dbuser || global.settings.postgres.user; var dbuser = req.params.dbuser || global.settings.postgres.user;
if ( ! me.rx_dbuser ) me.rx_dbuser = /(<Parameter name="user"><!\[CDATA\[)[^\]]*(]]><\/Parameter>)/g; if ( ! me.rx_dbuser ) me.rx_dbuser = /(<Parameter name="user"><!\[CDATA\[)[^\]]*(]]><\/Parameter>)/g;
xml = xml.replace(me.rx_dbuser, "$1" + dbuser + "$2"); xml = xml.replace(me.rx_dbuser, "$1" + dbuser + "$2");
// Replace dbpass
var dbpass = req.params.dbpassword || global.settings.postgres.password; var dbpass = req.params.dbpassword || global.settings.postgres.password;
if ( ! me.rx_dbpass ) me.rx_dbpass = /(<Parameter name="password"><!\[CDATA\[)[^\]]*(]]><\/Parameter>)/g; if ( ! me.rx_dbpass ) me.rx_dbpass = /(<Parameter name="password"><!\[CDATA\[)[^\]]*(]]><\/Parameter>)/g;
xml = xml.replace(me.rx_dbpass, "$1" + dbpass + "$2"); xml = xml.replace(me.rx_dbpass, "$1" + dbpass + "$2");
// Replace or set dbhost
var dbhost = req.params.dbhost || global.settings.postgres.host;
if ( ! me.rx_dbhost ) me.rx_dbhost = /(<Parameter name="host"><!\[CDATA\[)[^\]]*(]]><\/Parameter>)/g;
xml = xml.replace(me.rx_dbhost, "$1" + dbhost + "$2");
callback(null, xml); callback(null, xml);
} }
@ -384,9 +392,16 @@ module.exports = function(){
if(data === "0") throw new Error("Sorry, you are unauthorized (permission denied)"); if(data === "0") throw new Error("Sorry, you are unauthorized (permission denied)");
return data; return data;
}, },
function getDatabase(err, data){ function getDatabaseHost(err, data){
if(err) throw err; if(err) throw err;
cartoData.getDatabaseHost(req, this);
},
function getDatabase(err, data){
if (req.profiler) req.profiler.done('cartoData.getDatabaseHost');
if(err) throw err;
if ( data ) _.extend(req.params, {dbhost:data});
cartoData.getDatabase(req, this); cartoData.getDatabase(req, this);
}, },
function getGeometryType(err, data){ function getGeometryType(err, data){