Add 'user_from_host' directive to generalize username extraction
Closes #100 Default extractor is backward compatible
This commit is contained in:
parent
e9db535dd8
commit
1f693c6c78
1
NEWS.md
1
NEWS.md
@ -2,6 +2,7 @@
|
|||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
* Update cartodb-redis dependency to "~0.2.0"
|
* Update cartodb-redis dependency to "~0.2.0"
|
||||||
|
* Add 'user_from_host' directive to generalize username extraction (#100)
|
||||||
|
|
||||||
1.5.2 -- 2013-12-05
|
1.5.2 -- 2013-12-05
|
||||||
-------------------
|
-------------------
|
||||||
|
@ -2,6 +2,9 @@ var config = {
|
|||||||
environment: 'development'
|
environment: 'development'
|
||||||
,port: 8181
|
,port: 8181
|
||||||
,host: '127.0.0.1'
|
,host: '127.0.0.1'
|
||||||
|
// Regular expression pattern to extract username
|
||||||
|
// from hostname. Must have a single grabbing block.
|
||||||
|
,user_from_host: '^(.*)\\.localhost'
|
||||||
// Maximum number of connections for one process
|
// Maximum number of connections for one process
|
||||||
// 128 is a good value with a limit of 1024 open file descriptors
|
// 128 is a good value with a limit of 1024 open file descriptors
|
||||||
,maxConnections:128
|
,maxConnections:128
|
||||||
|
@ -2,6 +2,9 @@ var config = {
|
|||||||
environment: 'production'
|
environment: 'production'
|
||||||
,port: 8181
|
,port: 8181
|
||||||
,host: '127.0.0.1'
|
,host: '127.0.0.1'
|
||||||
|
// Regular expression pattern to extract username
|
||||||
|
// from hostname. Must have a single grabbing block.
|
||||||
|
,user_from_host: '^(.*)\\.cartodb\\.com$'
|
||||||
// Maximum number of connections for one process
|
// Maximum number of connections for one process
|
||||||
// 128 is a good value with a limit of 1024 open file descriptors
|
// 128 is a good value with a limit of 1024 open file descriptors
|
||||||
,maxConnections:128
|
,maxConnections:128
|
||||||
|
@ -2,6 +2,9 @@ var config = {
|
|||||||
environment: 'production'
|
environment: 'production'
|
||||||
,port: 8181
|
,port: 8181
|
||||||
,host: '127.0.0.1'
|
,host: '127.0.0.1'
|
||||||
|
// Regular expression pattern to extract username
|
||||||
|
// from hostname. Must have a single grabbing block.
|
||||||
|
,user_from_host: '^(.*)\\.cartodb\\.com$'
|
||||||
// Maximum number of connections for one process
|
// Maximum number of connections for one process
|
||||||
// 128 is a good value with a limit of 1024 open file descriptors
|
// 128 is a good value with a limit of 1024 open file descriptors
|
||||||
,maxConnections:128
|
,maxConnections:128
|
||||||
|
@ -2,6 +2,9 @@ var config = {
|
|||||||
environment: 'test'
|
environment: 'test'
|
||||||
,port: 8888
|
,port: 8888
|
||||||
,host: '127.0.0.1'
|
,host: '127.0.0.1'
|
||||||
|
// Regular expression pattern to extract username
|
||||||
|
// from hostname. Must have a single grabbing block.
|
||||||
|
,user_from_host: '(.*)'
|
||||||
// Maximum number of connections for one process
|
// Maximum number of connections for one process
|
||||||
// 128 is a good value with a limit of 1024 open file descriptors
|
// 128 is a good value with a limit of 1024 open file descriptors
|
||||||
,maxConnections:128
|
,maxConnections:128
|
||||||
|
@ -305,8 +305,26 @@ module.exports = function(){
|
|||||||
|
|
||||||
/* X-Cache-Channel generation } */
|
/* X-Cache-Channel generation } */
|
||||||
|
|
||||||
|
me.re_userFromHost = new RegExp(
|
||||||
|
global.environment.user_from_host ||
|
||||||
|
'^([^\\.]+)\\.' // would extract "strk" from "strk.cartodb.com"
|
||||||
|
);
|
||||||
|
|
||||||
me.userByReq = function(req) {
|
me.userByReq = function(req) {
|
||||||
return cartoData.userFromHostname(req.headers.host);
|
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 + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// console.log("Matches: "); console.dir(mat);
|
||||||
|
if ( ! mat.length === 2 ) {
|
||||||
|
console.error("ERROR: pattern '" + this.re_userFromHost
|
||||||
|
+ "' gave unexpected matches against '" + host + "': " + mat);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return mat[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set db authentication parameters to those of the given username
|
// Set db authentication parameters to those of the given username
|
||||||
|
Loading…
Reference in New Issue
Block a user