Merge pull request #270 from CartoDB/jshint

Enable jshint
This commit is contained in:
Raul Ochoa
2015-03-16 00:48:15 +01:00
12 changed files with 227 additions and 124 deletions
+92
View File
@@ -0,0 +1,92 @@
{
// // JSHint Default Configuration File (as on JSHint website)
// // See http://jshint.com/docs/ for more details
//
// "maxerr" : 50, // {int} Maximum error before stopping
//
// // Enforcing
// "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
// "camelcase" : false, // true: Identifiers must be in camelCase
// "curly" : true, // true: Require {} for every new block or scope
// "eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
"immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
// "indent" : 4, // {int} Number of spaces to use for indentation
// "latedef" : false, // true: Require variables/functions to be defined before being used
"newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
// "noempty" : true, // true: Prohibit use of empty blocks
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
"nonew" : true, // true: Prohibit use of constructors for side-effects (without assignment)
// "plusplus" : false, // true: Prohibit use of `++` & `--`
// "quotmark" : false, // Quotation mark consistency:
// // false : do nothing (default)
// // true : ensure whatever is used is consistent
// // "single" : require single quotes
// // "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // true: Require all defined variables be used
// "strict" : true, // true: Requires all functions run in ES5 Strict Mode
// "maxparams" : false, // {int} Max number of formal params allowed per function
// "maxdepth" : false, // {int} Max depth of nested blocks (within functions)
// "maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : 8, // {int} Max cyclomatic complexity per function
"maxlen" : 120, // {int} Max number of characters per line
//
// // Relaxing
// "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
// "boss" : false, // true: Tolerate assignments where comparisons would be expected
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
// "eqnull" : false, // true: Tolerate use of `== null`
// "es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
// "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
// "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
// // (ex: `for each`, multiple try/catch, function expression…)
// "evil" : false, // true: Tolerate use of `eval` and `new Function()`
// "expr" : false, // true: Tolerate `ExpressionStatement` as Programs
// "funcscope" : false, // true: Tolerate defining variables inside control statements
// "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
// "iterator" : false, // true: Tolerate using the `__iterator__` property
// "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
// "laxbreak" : false, // true: Tolerate possibly unsafe line breakings
// "laxcomma" : false, // true: Tolerate comma-first style coding
// "loopfunc" : false, // true: Tolerate functions being defined in loops
// "multistr" : false, // true: Tolerate multi-line strings
// "noyield" : false, // true: Tolerate generator functions with no yield statement in them.
// "notypeof" : false, // true: Tolerate invalid typeof operator values
// "proto" : false, // true: Tolerate using the `__proto__` property
// "scripturl" : false, // true: Tolerate script-targeted URLs
// "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
// "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
// "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
// "validthis" : false, // true: Tolerate using this in a non-constructor function
//
// // Environments
// "browser" : true, // Web Browser (window, document, etc)
// "browserify" : false, // Browserify (node.js code in the browser)
// "couch" : false, // CouchDB
// "devel" : true, // Development/debugging (alert, confirm, etc)
// "dojo" : false, // Dojo Toolkit
// "jasmine" : false, // Jasmine
// "jquery" : false, // jQuery
// "mocha" : true, // Mocha
// "mootools" : false, // MooTools
"node" : true, // Node.js
// "nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
// "prototypejs" : false, // Prototype and Scriptaculous
// "qunit" : false, // QUnit
// "rhino" : false, // Rhino
// "shelljs" : false, // ShellJS
// "worker" : false, // Web Workers
// "wsh" : false, // Windows Scripting Host
// "yui" : false, // Yahoo User Interface
// Custom Globals
"globals" : { // additional predefined global variables
"suite": true,
"suiteSetup": true,
"test": true,
"suiteTeardown": true
}
}
+6
View File
@@ -27,6 +27,12 @@ test: config/environments/test.js
test/acceptance/*.js \
test/acceptance/cache/*.js
jshint:
@echo "***jshint***"
@./node_modules/.bin/jshint lib/
test-all: jshint test
check: test
.PHONY: pre-install test
+6 -6
View File
@@ -1,6 +1,6 @@
var sqlApi = require('../sql/sql_api');
var PSQL = require('cartodb-psql');
var Step = require('step');
var step = require('step');
function QueryTablesApi(pgConnection, metadataBackend) {
this.pgConnection = pgConnection;
@@ -78,7 +78,7 @@ QueryTablesApi.prototype.runQuery = function(username, query, queryHandler, call
var params = {};
Step(
step(
function setAuth() {
self.pgConnection.setDBAuth(username, params, this);
},
@@ -109,7 +109,7 @@ QueryTablesApi.prototype.runQuery = function(username, query, queryHandler, call
} else {
Step(
step(
function getApiKey() {
self.metadataBackend.getUserMapKey(username, this);
},
@@ -138,7 +138,7 @@ function prepareSql(sql) {
function shouldQueryPostgresDirectly() {
return global.environment
&& global.environment.enabledFeatures
&& global.environment.enabledFeatures.cdbQueryTablesFromPostgres;
return global.environment &&
global.environment.enabledFeatures &&
global.environment.enabledFeatures.cdbQueryTablesFromPostgres;
}
+5 -5
View File
@@ -1,4 +1,4 @@
var Step = require('step');
var step = require('step');
var _ = require('underscore');
function PgConnection(metadataBackend) {
@@ -24,13 +24,13 @@ PgConnection.prototype.setDBAuth = function(username, params, callback) {
var user_params = {};
var auth_user = global.environment.postgres_auth_user;
var auth_pass = global.environment.postgres_auth_pass;
Step(
step(
function getId() {
self.metadataBackend.getUserId(username, this);
},
function(err, user_id) {
if (err) throw err;
user_params['user_id'] = user_id;
user_params.user_id = user_id;
var dbuser = _.template(auth_user, user_params);
_.extend(params, {dbuser:dbuser});
@@ -42,7 +42,7 @@ PgConnection.prototype.setDBAuth = function(username, params, callback) {
},
function(err, user_password) {
if (err) throw err;
user_params['user_password'] = user_password;
user_params.user_password = user_password;
if ( auth_pass ) {
var dbpass = _.template(auth_pass, user_params);
_.extend(params, {dbpassword:dbpass});
@@ -76,7 +76,7 @@ PgConnection.prototype.setDBConn = function(dbowner, params, callback) {
dbhost: global.environment.postgres.host,
dbport: global.environment.postgres.port
});
Step(
step(
function getConnectionParams() {
self.metadataBackend.getUserDBConnectionParams(dbowner, this);
},
+3 -4
View File
@@ -1,6 +1,5 @@
var _ = require('underscore'),
Varnish = require('node-varnish'),
varnish_queue = null;
var Varnish = require('node-varnish');
var varnish_queue = null;
function init(host, port, secret) {
varnish_queue = new Varnish.VarnishQueue(host, port, secret);
@@ -23,4 +22,4 @@ function invalidate_db(dbname, table) {
module.exports = {
init: init,
invalidate_db: invalidate_db
}
};
+26 -21
View File
@@ -1,12 +1,12 @@
var _ = require('underscore');
var Step = require('step');
var step = require('step');
var Windshaft = require('windshaft');
var Cache = require('./cache_validator');
var os = require('os');
var HealthCheck = require('./monitoring/health_check');
if ( ! process.env['PGAPPNAME'] )
process.env['PGAPPNAME']='cartodb_tiler';
if ( ! process.env.PGAPPNAME )
process.env.PGAPPNAME='cartodb_tiler';
var CartodbWindshaft = function(serverOptions) {
// Perform keyword substitution in statsd
@@ -18,20 +18,21 @@ var CartodbWindshaft = function(serverOptions) {
}
}
var redisPool = serverOptions.redis.pool
|| require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:cartodb'}));
var redisPool = serverOptions.redis.pool ||
require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:cartodb'}));
var cartoData = require('cartodb-redis')({pool: redisPool});
var templateMaps = serverOptions.templateMaps;
if(serverOptions.cache_enabled) {
console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ', serverOptions.varnish_port);
console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ',
serverOptions.varnish_port);
Cache.init(serverOptions.varnish_host, serverOptions.varnish_port, serverOptions.varnish_secret);
serverOptions.afterStateChange = function(req, data, callback) {
Cache.invalidate_db(req.params.dbname, req.params.table);
callback(null, data);
}
};
}
serverOptions.beforeStateChange = function(req, callback) {
@@ -51,18 +52,21 @@ var CartodbWindshaft = function(serverOptions) {
var SurrogateKeysCache = require('./cache/surrogate_keys_cache'),
NamedMapsCacheEntry = require('./cache/model/named_maps_entry'),
VarnishHttpCacheBackend = require('./cache/backend/varnish_http'),
varnishHttpCacheBackend = new VarnishHttpCacheBackend(serverOptions.varnish_host, serverOptions.varnish_http_port),
varnishHttpCacheBackend = new VarnishHttpCacheBackend(
serverOptions.varnish_host,
serverOptions.varnish_http_port
),
surrogateKeysCache = new SurrogateKeysCache(varnishHttpCacheBackend);
if (serverOptions.varnish_purge_enabled) {
function invalidateNamedMap(owner, templateName) {
surrogateKeysCache.invalidate(new NamedMapsCacheEntry(owner, templateName), function(err) {
if (err) {
console.warn('Cache: surrogate key invalidation failed');
}
});
}
function invalidateNamedMap (owner, templateName) {
surrogateKeysCache.invalidate(new NamedMapsCacheEntry(owner, templateName), function(err) {
if (err) {
console.warn('Cache: surrogate key invalidation failed');
}
});
}
if (serverOptions.varnish_purge_enabled) {
['update', 'delete'].forEach(function(eventType) {
templateMaps.on(eventType, invalidateNamedMap);
});
@@ -102,7 +106,7 @@ var CartodbWindshaft = function(serverOptions) {
}
}
var req = res.req;
Step (
step (
function addCacheChannel() {
if ( ! req ) {
// having no associated request can happen when
@@ -124,10 +128,11 @@ var CartodbWindshaft = function(serverOptions) {
//console.log("Skipping cache channel in route:\n" + req.route.path);
return false;
}
//console.log("Adding cache channel to route\n" + req.route.path + " not matching any in:\n" + mapCreateRoutes.join("\n"));
//console.log("Adding cache channel to route\n" + req.route.path + " not matching any in:\n" +
// mapCreateRoutes.join("\n"));
serverOptions.addCacheChannel(that, req, this);
},
function sendResponse(err, added) {
function sendResponse(err/*, added*/) {
if ( err ) console.log(err + err.stack);
ws_sendResponse.apply(that, thatArgs);
return null;
@@ -172,7 +177,7 @@ var CartodbWindshaft = function(serverOptions) {
*/
ws.get(serverOptions.base_url + '/infowindow', function(req, res){
ws.doCORS(res);
Step(
step(
function(){
serverOptions.getInfowindow(req, this);
},
@@ -193,7 +198,7 @@ var CartodbWindshaft = function(serverOptions) {
*/
ws.get(serverOptions.base_url + '/map_metadata', function(req, res){
ws.doCORS(res);
Step(
step(
function(){
serverOptions.getMapMetadata(req, this);
},
+23 -27
View File
@@ -1,4 +1,4 @@
var Step = require('step');
var step = require('step');
var _ = require('underscore');
function TemplateMapsController(app, serverOptions, templateMaps, metadataBackend, templateBaseUrl, surrogateKeysCache,
@@ -35,7 +35,7 @@ TemplateMapsController.prototype.create = function(req, res) {
var cdbuser = self.serverOptions.userByReq(req);
Step(
step(
function checkPerms(){
self.serverOptions.authorizedByAPIKey(req, this);
},
@@ -83,7 +83,7 @@ TemplateMapsController.prototype.update = function(req, res) {
var cdbuser = this.serverOptions.userByReq(req);
var template;
var tpl_id;
Step(
step(
function checkPerms(){
self.serverOptions.authorizedByAPIKey(req, this);
},
@@ -100,8 +100,7 @@ TemplateMapsController.prototype.update = function(req, res) {
tpl_id = req.params.template_id.split('@');
if ( tpl_id.length > 1 ) {
if ( tpl_id[0] != cdbuser ) {
err = new Error("Invalid template id '"
+ req.params.template_id + "' for user '" + cdbuser + "'");
err = new Error("Invalid template id '" + req.params.template_id + "' for user '" + cdbuser + "'");
err.http_status = 404;
throw err;
}
@@ -142,9 +141,8 @@ TemplateMapsController.prototype.retrieve = function(req, res) {
this.app.doCORS(res);
var cdbuser = this.serverOptions.userByReq(req);
var template;
var tpl_id;
Step(
step(
function checkPerms(){
self.serverOptions.authorizedByAPIKey(req, this);
},
@@ -158,10 +156,10 @@ TemplateMapsController.prototype.retrieve = function(req, res) {
tpl_id = req.params.template_id.split('@');
if ( tpl_id.length > 1 ) {
if ( tpl_id[0] != cdbuser ) {
var err = new Error("Cannot get template id '"
+ req.params.template_id + "' for user '" + cdbuser + "'");
err.http_status = 404;
throw err;
var templateNotFoundErr = new Error("Cannot get template id '" + req.params.template_id +
"' for user '" + cdbuser + "'");
templateNotFoundErr.http_status = 404;
throw templateNotFoundErr;
}
tpl_id = tpl_id[1];
}
@@ -204,9 +202,8 @@ TemplateMapsController.prototype.destroy = function(req, res) {
this.app.doCORS(res);
var cdbuser = this.serverOptions.userByReq(req);
var template;
var tpl_id;
Step(
step(
function checkPerms(){
self.serverOptions.authorizedByAPIKey(req, this);
},
@@ -220,16 +217,16 @@ TemplateMapsController.prototype.destroy = function(req, res) {
tpl_id = req.params.template_id.split('@');
if ( tpl_id.length > 1 ) {
if ( tpl_id[0] != cdbuser ) {
var err = new Error("Cannot find template id '"
+ req.params.template_id + "' for user '" + cdbuser + "'");
err.http_status = 404;
throw err;
var templateNotFoundErr = new Error("Cannot find template id '" + req.params.template_id +
"' for user '" + cdbuser + "'");
templateNotFoundErr.http_status = 404;
throw templateNotFoundErr;
}
tpl_id = tpl_id[1];
}
self.templateMaps.delTemplate(cdbuser, tpl_id, this);
},
function prepareResponse(err, tpl_val){
function prepareResponse(err/*, tpl_val*/){
if ( err ) throw err;
return { status: 'ok' };
},
@@ -259,7 +256,7 @@ TemplateMapsController.prototype.list = function(req, res) {
var cdbuser = this.serverOptions.userByReq(req);
Step(
step(
function checkPerms(){
self.serverOptions.authorizedByAPIKey(req, this);
},
@@ -299,7 +296,7 @@ TemplateMapsController.prototype.instantiate = function(req, res) {
if ( req.profiler && req.profiler.statsd_client) {
req.profiler.start('windshaft-cartodb.instance_template_post');
}
Step(
step(
function() {
if ( ! req.headers['content-type'] || req.headers['content-type'].split(';')[0] != 'application/json') {
throw new Error('template POST data must be of type application/json, it is instead ');
@@ -311,7 +308,7 @@ TemplateMapsController.prototype.instantiate = function(req, res) {
);
};
TemplateMapsController.prototype.options = function(req, res) {
TemplateMapsController.prototype.options = function(req, res, next) {
this.app.doCORS(res, "Content-Type");
return next();
};
@@ -326,7 +323,7 @@ TemplateMapsController.prototype.jsonp = function(req, res) {
if ( req.profiler && req.profiler.statsd_client) {
req.profiler.start('windshaft-cartodb.instance_template_get');
}
Step(
step(
function() {
if ( req.query.callback === undefined || req.query.callback.length === 0) {
throw new Error('callback parameter should be present and be a function name');
@@ -361,9 +358,8 @@ TemplateMapsController.prototype.instantiateTemplate = function(req, res, templa
var tpl_id = req.params.template_id.split('@');
if ( tpl_id.length > 1 ) {
if ( tpl_id[0] && tpl_id[0] != cdbuser ) {
var err = new Error('Cannot instanciate map of user "'
+ tpl_id[0] + '" on database of user "'
+ cdbuser + '"');
var err = new Error('Cannot instanciate map of user "' + tpl_id[0] + '" on database of user "' + cdbuser +
'"');
err.http_status = 403;
callback(err);
return;
@@ -371,7 +367,7 @@ TemplateMapsController.prototype.instantiateTemplate = function(req, res, templa
tpl_id = tpl_id[1];
}
var auth_token = req.query.auth_token;
Step(
step(
function getTemplate(){
self.templateMaps.getTemplate(cdbuser, tpl_id, this);
},
@@ -464,7 +460,7 @@ TemplateMapsController.prototype.finish_instantiation = function(err, response,
TemplateMapsController.prototype.setDBParams = function(cdbuser, params, callback) {
var self = this;
Step(
step(
function setAuth() {
self.pgConnection.setDBAuth(cdbuser, params, this);
},
+6 -7
View File
@@ -1,8 +1,7 @@
var _ = require('underscore'),
dot = require('dot'),
fs = require('fs'),
path = require('path'),
Step = require('step');
var dot = require('dot');
var fs = require('fs');
var path = require('path');
var step = require('step');
function HealthCheck(metadataBackend, tilelive) {
this.metadataBackend = metadataBackend;
@@ -40,9 +39,9 @@ HealthCheck.prototype.check = function(config, callback) {
ok: false
}
};
mapnikXmlParams = config;
var mapnikXmlParams = config;
Step(
step(
function getDBParams() {
startTime = Date.now();
self.metadataBackend.getAllUserDBParams(config.username, this);
+39 -32
View File
@@ -1,5 +1,5 @@
var _ = require('underscore');
var Step = require('step');
var step = require('step');
var QueryTablesApi = require('./api/query_tables_api');
var PgConnection = require('./backends/pg_connection');
var crypto = require('crypto');
@@ -35,8 +35,8 @@ var REQUEST_QUERY_PARAMS_WHITELIST = [
];
module.exports = function(redisPool) {
redisPool = redisPool
|| require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:server_options'}));
redisPool = redisPool ||
require('redis-mpool')(_.extend(global.environment.redis, {name: 'windshaft:server_options'}));
var cartoData = require('cartodb-redis')({ pool: redisPool }),
lzmaWorker = new LZMA(),
@@ -147,7 +147,7 @@ module.exports = function(redisPool) {
var that = this;
Step (
step (
function checkCached() {
if ( me.channelCache.hasOwnProperty(cacheKey) ) {
callback(null, me.channelCache[cacheKey]);
@@ -167,7 +167,7 @@ module.exports = function(redisPool) {
}
var next = this;
var mapStore = app.mapStore;
Step(
step(
function loadFromStore() {
mapStore.load(req.params.token, this);
},
@@ -196,7 +196,7 @@ module.exports = function(redisPool) {
// strip out windshaft/mapnik inserted sql if present
var sql = req.params.sql.match(/^\((.*)\)\sas\scdbq$/);
sql = (sql != null) ? sql[1] : req.params.sql;
sql = (sql !== null) ? sql[1] : req.params.sql;
return sql;
},
@@ -281,14 +281,16 @@ module.exports = function(redisPool) {
};
me.beforeLayergroupCreate = function(req, requestMapConfig, callback) {
mapConfigNamedLayersAdapter.getLayers(this.userByReq(req), requestMapConfig.layers, pgConnection, function(err, layers, datasource) {
if (err) {
return callback(err);
}
mapConfigNamedLayersAdapter.getLayers(this.userByReq(req), requestMapConfig.layers, pgConnection,
function(err, layers, datasource) {
if (err) {
return callback(err);
}
requestMapConfig.layers = layers;
return callback(null, requestMapConfig, datasource)
});
requestMapConfig.layers = layers;
return callback(null, requestMapConfig, datasource);
}
);
};
me.afterLayergroupCreate = function(req, mapconfig, response, callback) {
@@ -333,7 +335,7 @@ module.exports = function(redisPool) {
var dbName = req.params.dbname;
var cacheKey = dbName + ':' + token;
Step(
step(
function getAffectedTablesAndLastUpdatedTime() {
queryTablesApi.getAffectedTablesAndLastUpdatedTime(username, sql, this);
},
@@ -377,14 +379,13 @@ module.exports = function(redisPool) {
var host = req.headers.host;
var mat = host.match(this.re_userFromHost);
if ( ! mat ) {
console.error("ERROR: user pattern '" + this.re_userFromHost
+ "' does not match hostname '" + host + "'");
console.error("ERROR: user pattern '" + this.re_userFromHost + "' does not match hostname '" + host + "'");
return;
}
// console.log("Matches: "); console.dir(mat);
if ( ! mat.length === 2 ) {
console.error("ERROR: pattern '" + this.re_userFromHost
+ "' gave unexpected matches against '" + host + "': " + mat);
if ( mat.length !== 2 ) {
console.error("ERROR: pattern '" + this.re_userFromHost + "' gave unexpected matches against '" + host + "': " +
mat);
return;
}
return mat[1];
@@ -409,7 +410,8 @@ module.exports = function(redisPool) {
var layergroup_id = req.params.token;
var auth_token = req.params.auth_token;
//console.log("Checking authorization from signer " + signer + " for resource " + layergroup_id + " with auth_token " + auth_token);
//console.log("Checking authorization from signer " + signer + " for resource " + layergroup_id +
// " with auth_token " + auth_token);
var mapStore = req.app.mapStore;
if (!mapStore) {
throw new Error('Unable to retrieve map configuration token');
@@ -445,7 +447,7 @@ module.exports = function(redisPool) {
}
//console.log("given ApiKey: " + givenKey);
var user = me.userByReq(req);
Step(
step(
function (){
cartoData.getUserMapKey(user, this);
},
@@ -469,7 +471,7 @@ module.exports = function(redisPool) {
var that = this;
var user = me.userByReq(req);
Step(
step(
function (){
that.authorizedByAPIKey(req, this);
},
@@ -545,6 +547,7 @@ module.exports = function(redisPool) {
);
};
// jshint maxcomplexity:10
/**
* Whitelist input and get database name & default geometry type from
* subdomain/user metadata held in CartoDB Redis
@@ -559,7 +562,12 @@ module.exports = function(redisPool) {
//console.log("type of req.query.lzma is " + typeof(req.query.lzma));
// Decode (from base64)
var lzma = (new Buffer(req.query.lzma, 'base64').toString('binary')).split('').map(function(c) { return c.charCodeAt(0) - 128 });
var lzma = new Buffer(req.query.lzma, 'base64')
.toString('binary')
.split('')
.map(function(c) {
return c.charCodeAt(0) - 128;
});
// Decompress
lzmaWorker.decompress(
@@ -574,7 +582,7 @@ module.exports = function(redisPool) {
callback(new Error('Error parsing lzma as JSON: ' + err));
}
},
function(percent) { // progress
function(/*percent*/) { // progress
//console.log("LZMA decompression " + percent + "%");
}
);
@@ -597,14 +605,15 @@ module.exports = function(redisPool) {
if ( tksplit.length > 1 ) {
req.params.signer = tksplit.shift();
if ( ! req.params.signer ) req.params.signer = user;
else if ( req.params.signer != user ) {
var err = new Error('Cannot use map signature of user "' + req.params.signer + '" on database of user "' + user + '"');
else if ( req.params.signer !== user ) {
var err = new Error('Cannot use map signature of user "' + req.params.signer + '" on database of user "' +
user + '"');
err.http_status = 403;
callback(err);
return;
}
if ( tksplit.length > 1 ) {
var template_hash = tksplit.shift(); // unused
/*var template_hash = */tksplit.shift(); // unused
}
req.params.token = tksplit.shift();
//console.log("Request for token " + req.params.token + " with signature from " + req.params.signer);
@@ -617,11 +626,9 @@ module.exports = function(redisPool) {
// for cartodb, ensure interactivity is cartodb_id or user specified
req.params.interactivity = req.params.interactivity || 'cartodb_id';
var that = this;
if (req.profiler) req.profiler.done('req2params.setup');
Step(
step(
function getPrivacy(){
me.authorize(req, this);
},
@@ -674,7 +681,7 @@ module.exports = function(redisPool) {
var that = this;
var user = me.userByReq(req);
Step(
step(
function(){
// TODO: if this step really needed ?
that.req2params(req, this);
@@ -702,7 +709,7 @@ module.exports = function(redisPool) {
var that = this;
var user = me.userByReq(req);
Step(
step(
function(){
// TODO: if this step really needed ?
that.req2params(req, this);
+4 -4
View File
@@ -16,7 +16,7 @@ module.exports.query = function (username, api_key, sql, callback) {
var qs = { q: sql };
// add api_key if given
if (_.isString(api_key) && api_key != '') { qs.api_key = api_key; }
if (_.isString(api_key) && api_key !== '') { qs.api_key = api_key; }
// call sql api
//
@@ -36,11 +36,11 @@ module.exports.query = function (username, api_key, sql, callback) {
var reqSpec = {
url:sqlapi,
json:true,
headers:{host: sqlapihostname}
headers:{host: sqlapihostname},
// http://nodejs.org/api/http.html#http_agent_maxsockets
,pool:{maxSockets:maxSockets}
pool:{maxSockets:maxSockets},
// timeout in milliseconds
,timeout:maxSQLTime
timeout:maxSQLTime
};
if ( sql.length > maxGetLen ) {
reqSpec.method = 'POST';
+15 -17
View File
@@ -1,7 +1,7 @@
var crypto = require('crypto'),
Step = require('step'),
_ = require('underscore'),
dot = require('dot');
var crypto = require('crypto');
var step = require('step');
var _ = require('underscore');
var dot = require('dot');
var EventEmitter = require('events').EventEmitter;
@@ -56,7 +56,7 @@ var o = TemplateMaps.prototype;
//--------------- PRIVATE METHODS --------------------------------
o._userTemplateLimit = function() {
return this.opts['max_user_templates'] || 0;
return this.opts.max_user_templates || 0;
};
/**
@@ -71,7 +71,7 @@ o._redisCmd = function(redisFunc, redisArgs, callback) {
var that = this;
var db = that.db_signatures;
Step(
step(
function getRedisClient() {
that.redis_pool.acquire(db, this);
},
@@ -89,6 +89,7 @@ o._redisCmd = function(redisFunc, redisArgs, callback) {
};
var _reValidIdentifier = /^[a-zA-Z][0-9a-zA-Z_]*$/;
// jshint maxcomplexity:15
o._checkInvalidTemplate = function(template) {
if ( template.version != '0.0.1' ) {
return new Error("Unsupported template version " + template.version);
@@ -136,7 +137,6 @@ o._checkInvalidTemplate = function(template) {
break;
default:
return new Error("Unsupported authentication method: " + auth.method);
break;
}
return false;
@@ -205,7 +205,7 @@ o.addTemplate = function(owner, template, callback) {
var userTemplatesKey = this.key_usr_tpl({ owner:owner });
var limit = this._userTemplateLimit();
Step(
step(
function checkLimit() {
if ( ! limit ) {
return 0;
@@ -253,7 +253,7 @@ o.addTemplate = function(owner, template, callback) {
//
o.delTemplate = function(owner, tpl_id, callback) {
var self = this;
Step(
step(
function deleteTemplate() {
self._redisCmd('HDEL', [ self.key_usr_tpl({ owner:owner }), tpl_id ], this);
},
@@ -311,7 +311,7 @@ o.updTemplate = function(owner, tpl_id, template, callback) {
var userTemplatesKey = this.key_usr_tpl({ owner:owner });
Step(
step(
function getExistingTemplate() {
self._redisCmd('HGET', [ userTemplatesKey, tpl_id ], this);
},
@@ -366,7 +366,7 @@ o.listTemplates = function(owner, callback) {
//
o.getTemplate = function(owner, tpl_id, callback) {
var self = this;
Step(
step(
function getTemplate() {
self._redisCmd('HGET', [ self.key_usr_tpl({owner:owner}), tpl_id ], this);
},
@@ -424,14 +424,14 @@ var _reNumber = /^([-+]?[\d\.]?\d+([eE][+-]?\d+)?)$/,
_reCSSColorName = /^[a-zA-Z]+$/,
_reCSSColorVal = /^#[0-9a-fA-F]{3,6}$/;
_replaceVars = function(str, params) {
function _replaceVars (str, params) {
//return _.template(str, params); // lazy way, possibly dangerous
// Construct regular expressions for each param
Object.keys(params).forEach(function(k) {
str = str.replace(new RegExp("<%=\\s*" + k + "\\s*%>", "g"), params[k]);
});
return str;
};
}
o.instance = function(template, params) {
var all_params = {};
var phold = template.placeholders || {};
@@ -450,16 +450,14 @@ o.instance = function(template, params) {
else if ( type === 'number' ) {
// check it's a number
if ( typeof(val) !== 'number' && ! val.match(_reNumber) ) {
throw new Error("Invalid number value for template parameter '"
+ k + "': " + val);
throw new Error("Invalid number value for template parameter '" + k + "': " + val);
}
}
else if ( type === 'css_color' ) {
// check it only contains letters or
// starts with # and only contains hexdigits
if ( ! val.match(_reCSSColorName) && ! val.match(_reCSSColorVal) ) {
throw new Error("Invalid css_color value for template parameter '"
+ k + "': " + val);
throw new Error("Invalid css_color value for template parameter '" + k + "': " + val);
}
}
else {
+2 -1
View File
@@ -38,13 +38,14 @@
},
"devDependencies": {
"mocha": "~1.21.4",
"jshint": "~2.6.0",
"redis": "~0.8.6",
"strftime": "~0.8.2",
"semver": "~1.1.4"
},
"scripts": {
"preinstall": "make pre-install",
"test": "make test"
"test": "make test-all"
},
"engines": {
"node": ">=0.8 <0.11",