Include hash of template in the maptoken returned from instanciation

Doing so basically removes the need to include the template identifier
in the surrogate keys of the responses for resources fetched via
the instance whenever template is updated. See #105
This commit is contained in:
Sandro Santilli
2014-02-10 15:30:35 +01:00
parent 24709e8341
commit 747f4803ba
4 changed files with 18 additions and 4 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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;