diff --git a/NEWS.md b/NEWS.md index 00e340ef..7faa90e2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ New features: Enhancements: * Allow specifying fixed sqlapi host address (#117) + * Include template hash in template instance response, to keep caches + of different instances separated (#105) Bug fixes: diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index c6b19bfe..75e98bf5 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -484,7 +484,8 @@ var CartodbWindshaft = function(serverOptions) { if ( err ) throw err; //console.log("Response from createLayergroup: "); console.dir(response); // Add the signature part to the token! - response.layergroupid = cdbuser + '@' + response.layergroupid; + var tplhash = templateMaps.fingerPrint(template).substring(0,8); + response.layergroupid = cdbuser + '@' + tplhash + '@' + response.layergroupid; return response; }, callback diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index f79551ca..4e7ab128 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -613,9 +613,12 @@ console.log("Checking authorization from signer " + signer + " for resource " + if ( tksplit.length > 1 ) req.params.cache_buster= tksplit[1]; tksplit = req.params.token.split('@'); if ( tksplit.length > 1 ) { - req.params.signer = this.userByReq(req); - if ( tksplit[0] ) req.params.signer = tksplit[0]; - req.params.token = tksplit[1]; + req.params.signer = tksplit.shift(); + if ( ! req.params.signer ) req.params.signer = this.userByReq(req); + if ( tksplit.length > 1 ) { + 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); } } diff --git a/lib/cartodb/template_maps.js b/lib/cartodb/template_maps.js index 172bdbcc..117146ff 100644 --- a/lib/cartodb/template_maps.js +++ b/lib/cartodb/template_maps.js @@ -588,4 +588,12 @@ o.instance = function(template, params) { return layergroup; }; +// Return a fingerPrint of the object +o.fingerPrint = function(template) { + return crypto.createHash('md5') + .update(JSON.stringify(template)) + .digest('hex') + ; +}; + module.exports = TemplateMaps;