Adding a request filter
Request filters are filters that are invoked when a request is received from the database client. Normally, the request will simply be forwarded to the server, but you can create one or more filter to interfere with that:
you can change the request, for instance rewrite a SQL query
you can notify an other system about the query, perhaps for security reasons, or for logging purposes
you can reject the request, with error codes and error messages of your choice
you can even respond to the request yourself -- that's more advanced, but very powerful
Creating a request filter
In the Gallium Data admin app, open your project and click the New Request Filter button. Select the type of filter. In this example, let's just select Query filter - Postgres:
This type of filter takes no parameters. It is invoked automatically for all query packets (specifically Query and Parse packets).
Now in the Code section, you can enter JavaScript code that can do whatever you have in mind. Let's say, for this example, we want to reject certain queries. We could just write code to that effect:
if (context.packet.getQuery().includes("evil")) {
context.result.success = false;
context.result.errorMessage = "No evil queries";
}
Now if you execute a query that contains the word evil in your database client, you will get an error:
Of course, you can much more than this trivial example. You have full access to JavaScript, and to the underlying Java platform, so the sky is the limit.