1
0
Fork 0

Export cluster auth on dispatchers (non-cluster) to JS.

This commit is contained in:
Max Neunhoeffer 2014-05-06 13:01:54 +02:00
parent 2390008f00
commit 02b68533e1
1 changed files with 21 additions and 0 deletions

View File

@ -1251,6 +1251,26 @@ static v8::Handle<v8::Value> JS_StatusServerState (v8::Arguments const& argv) {
return scope.Close(v8::String::New(state.c_str(), (int) state.size()));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the server state
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_GetClusterAuthentication (v8::Arguments const& argv) {
v8::HandleScope scope;
if (argv.Length() != 0) {
TRI_V8_EXCEPTION_USAGE(scope, "getClusterAuthentication()");
}
std::string auth;
if (ServerState::instance()->getRole() == ServerState::ROLE_UNDEFINED) {
// Only on dispatchers, otherwise this would be a security risk!
auth = ServerState::instance()->getAuthentication();
}
return scope.Close(v8::String::New(auth.c_str(), (int) auth.size()));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief prepare to send a request
///
@ -1832,6 +1852,7 @@ void TRI_InitV8Cluster (v8::Handle<v8::Context> context) {
TRI_AddMethodVocbase(rt, "setId", JS_SetIdServerState, true);
TRI_AddMethodVocbase(rt, "setRole", JS_SetRoleServerState, true);
TRI_AddMethodVocbase(rt, "status", JS_StatusServerState);
TRI_AddMethodVocbase(rt, "getClusterAuthentication", JS_GetClusterAuthentication);
v8g->ServerStateTempl = v8::Persistent<v8::ObjectTemplate>::New(isolate, rt);
TRI_AddGlobalFunctionVocbase(context, "ArangoServerStateCtor", ft->GetFunction(), true);