Update to cartodb-redis 0.1.0

This commit is contained in:
Sandro Santilli
2013-11-15 19:14:00 +01:00
parent d61c373fad
commit 4c16087ea8
3 changed files with 77 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
var _ = require('underscore')
, Step = require('step')
, cartoData = require('cartodb-redis')
, cartoData = require('cartodb-redis')(global.environment.redis)
, Cache = require('./cache_validator')
, mapnik = require('mapnik')
, crypto = require('crypto')
@@ -304,6 +304,73 @@ module.exports = function(){
/* X-Cache-Channel generation } */
/**
* Get privacy for cartodb table
*
* @param req - standard req object. Importantly contains table and host information
* @param callback - is the table private or not?
*/
me.authorize= function(req, callback) {
var that = this;
Step(
function(){
cartoData.checkMapKey(req, this);
},
function checkIfInternal(err, check_result){
if (err) throw err;
// if unauthorized continue to check table privacy
if (check_result !== 1) return true;
// authorized by key, login as db owner
var user_params = {};
var auth_user = global.environment.postgres_auth_user;
var auth_pass = global.environment.postgres_auth_pass;
Step(
function getId() {
cartoData.getId(req, this);
},
function(err, user_id) {
if (err) throw err;
user_params['user_id'] = user_id;
var dbuser = _.template(auth_user, user_params);
_.extend(req.params, {dbuser:dbuser});
// skip looking up user_password if postgres_auth_pass
// doesn't contain the "user_password" label
if ( ! auth_pass.match(/\buser_password\b/) ) return null;
cartoData.getDatabasePassword(req, this);
},
function(err, user_password) {
if (err) throw err;
user_params['user_password'] = user_password;
if ( auth_pass ) {
var dbpass = _.template(auth_pass, user_params);
_.extend(req.params, {dbpassword:dbpass});
}
return true;
},
function finish(err) {
callback(err, true); // authorized (or error)
}
);
}
,function getDatabase(err, data){
if (err) throw err;
cartoData.getDatabase(req, this);
},
function getPrivacy(err, data){
if (err) throw err;
cartoData.getTablePrivacy(data, req.params.table, this);
},
function(err, data){
callback(err, data);
}
);
};
/**
* Whitelist input and get database name & default geometry type from
* subdomain/user metadata held in CartoDB Redis
@@ -363,17 +430,17 @@ module.exports = function(){
req.params.processXML = function(req, xml, callback) {
// Replace dbuser
var dbuser = req.params.dbuser || global.settings.postgres.user;
var dbuser = req.params.dbuser || global.environment.postgres.user;
if ( ! me.rx_dbuser ) me.rx_dbuser = /(<Parameter name="user"><!\[CDATA\[)[^\]]*(]]><\/Parameter>)/g;
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.environment.postgres.password;
if ( ! me.rx_dbpass ) me.rx_dbpass = /(<Parameter name="password"><!\[CDATA\[)[^\]]*(]]><\/Parameter>)/g;
xml = xml.replace(me.rx_dbpass, "$1" + dbpass + "$2");
// Replace or set dbhost
var dbhost = req.params.dbhost || global.settings.postgres.host;
var dbhost = req.params.dbhost || global.environment.postgres.host;
if ( ! me.rx_dbhost ) me.rx_dbhost = /(<Parameter name="host"><!\[CDATA\[)[^\]]*(]]><\/Parameter>)/g;
xml = xml.replace(me.rx_dbhost, "$1" + dbhost + "$2");
@@ -386,7 +453,7 @@ module.exports = function(){
Step(
function getPrivacy(){
cartoData.authorize(req, this);
me.authorize(req, this);
},
function gatekeep(err, data){
if (req.profiler) req.profiler.done('cartoData.authorize');

8
npm-shrinkwrap.json generated
View File

@@ -273,7 +273,7 @@
"version": "2.9.202"
},
"cartodb-redis": {
"version": "0.0.1",
"version": "0.1.0",
"dependencies": {
"generic-pool": {
"version": "2.0.4"
@@ -286,12 +286,12 @@
"lzma": {
"version": "1.2.3"
},
"semver": {
"version": "1.1.4"
},
"strftime": {
"version": "0.6.2"
},
"semver": {
"version": "1.1.4"
},
"redis": {
"version": "0.8.6"
},

View File

@@ -24,7 +24,7 @@
"windshaft" : "~0.14.3",
"step": "0.0.x",
"request": "2.9.202",
"cartodb-redis": "~0.0.1",
"cartodb-redis": "~0.1.0",
"mapnik": "~0.7.22",
"lzma": "~1.2.3"
},