Multi-tenanancy
I've been working lately on adding some multi-tenancy to cube and would love to get feedback on the approach. I've modified the server config to take two additional parameters authentication and namespace, which let you authenticate incoming requests and namespace event types per requests. You can see an example of authentication in test/authenticated-collector-test.js. I haven't added a test for the namespacing yet, because it involves checking mongo to verify that the type was namespaced. Unfortunately, I don't really know how to test that with node/vows. Any help there would be appreciated.
So... what do you think of this approach? Prefer something else? Think this is interesting?
So... everything seems to work now, but the code is quite a mess. @mbostock, you have time to talk about this sometime? I'm happy to come up to SF.
I really like these namespace changes. Thanks for writing this, @trotter
I have a style nit, though. The authentication checking pattern
} catch (e) {
if (e.toString() == "AuthenticationError: Invalid Credentials") {
response.writeHead(401, headers);
response.end(JSON.stringify({error: e.toString()}));
} else {
response.writeHead(400, headers);
response.end(JSON.stringify({error: e.toString()}));
}
return;
}
and the namespace application pattern
// Namespace the type if necessary.
if (namespaceFun) {
namespaceFun(typeWithoutNamespace, request, namespaceFunCallback);
} else {
namespaceFunCallback(typeWithoutNamespace);
}
function namespaceFunCallback(type) {
are repeated several times and seem like they could be factored out.
Is there a reason that the authentication doesn't just wrap endpoint? Maybe add an authenticated parameter to endpoint that does this authentication checking in one place.
Thanks, @sbuss. I'll see about factoring those out. I hadn't actually considered just wrapping it within the server code itself.