Adding a connection filter

A connection filter gets called whenever a database client opens a connection to Gallium Data. You can use one of the built-in filters, or you can use the JavaScript connection filter and do whatever you want. Let's do that as an example.

In the admin app, go to Repository and select a project, then click New Connection Filter. You will be prompted for the type, select JavaScript connection filter.

Give this new filter a name:

We can now edit the code and make this filter actually do something. We're just going to check the IP address.

const clientAddress = context.socket.getRemoteSocketAddress().getAddress().toString();
const lastDotIdx = clientAddress.lastIndexOf(".");
if (lastDotIdx > 0) {
const finalNumStr = clientAddress.substring(lastDotIdx + 1);
const finalNum = parseInt(finalNumStr);
if (finalNum > 200) {
context.result.success = false;
context.result.errorMessage = "No IPs ending over 200, like " + clientAddress;
}
}

At that point, you just need to publish, and the connection filter will be in place.

If you now try to connect using your database client, the connection will be submitted to the filter, which will decide its fate.

If you're not sure whether this filter is in fact working properly, you have two main ways to check: logging and debugging.