Hi All,
I am working on my first project trying to access an Azure Cosmo DB Gremlin Graph from nodejs. I am using the official driver as this will be supported going forward. I am trying to implement authorisation as my Cosmbo DB has this implemented. Currently there is no support for authentication with the official driver, it does however seem to support response handlers on the DriverRemoteConnection object. I have therefore tried to implement authentication using this functionality.
The issue I currently have, having written but not tested my code, is that I cannot access the requestId for my response. In the DriverRemoteConnection implementation the _handleMessage function calls handlers with a status code >= 400 with an error and does not pass the message response to the callback. My understanding is that a sasl challenge returns a 407 status code.
if (response.status.code >= 400) {
// callback in error
return handler.callback(
new Error(util.format('Server error: %s (%d)', response.status.message, response.status.code)));
}
I could traverse the _responseHandlers array but this doesn't strike me as the correct way to get the requestId and could easily be prone to problems, more than 1 response for instance.
My question is, is there a reference implementation for Sasl Authentication with gremlin-javascript 3.2.9. If not, can we work on one here :)
My current code looks like this, it is untested so might not work at all right now, but I need to know how best to get the requestId:
const Gremlin = require('gremlin')
const connection = new Gremlin.driver.DriverRemoteConnection(`ws://${process.env.DOCDB_SERVER}:443/gremlin`)
const graph = new Gremlin.structure.Graph()
connection._responseHandlers[407] = {
callback: function () {
const saslresponse = new Buffer(`\0/dbs/${process.env.DOCDB_DATABASE}/colls/${process.env.DOCDB_GRAPH}\0${process.env.DOCDB_PASSWORD}`).toString('base64')
const response = {
'requestId': { '@type': 'g:UUID', '@value': needRequestIdHere },
'op': 'bytecode',
'processor': 'traversal',
'args': {
'aliases': { 'g': this.traversalSource },
'sasl': saslresponse
}
}
const message = new Buffer(this._header + JSON.stringify(response), 'utf8')
this._ws.send(message)
},
result: []
}
const g = graph.traversal().withRemote(connection)
Any help is really greatly appreciated.
Thanks,
Matt