Hello everybody, is it possible to trigger for eg ...
# sql
y
Hello everybody, is it possible to trigger for eg an http request on a policy check fail ?
c
What you can probably do is encapsulate your RLS entirely inside a function which returns a boolean. In that function, you can make the HTTP request if you see that you are about to return false
y
That was my guess yes :)
Thanks for the quick response and this hint, will try it in a bit
c
I think there is actually one more way
which would allow you to have your RLS outside of a function (if that's important)
you still need a function, but that function will ONLY make a request and will always return false. Let's call it notify()
Then, in your RLS you can add a call to the function as a last argument of an OR clause. Assuming, PostgreSQL uses short-circuiting when evaluating RLS policies, your function will NEVER be called if the RLS check evaluates to TRUE
Here is an example
Let's say you have an RLS like this:
auth.uid() = some_user_id || notify()
if auth.uid() = some_user_id is TRUE AND RLS checks implement short-circuiting, notify() will NOT be called (since TRUE || FALSE is always TRUE)
if, on the other hand auth.uid() = some_user_id is FALSE, then the RLS check will invoke your notify function, which will send the request and still return false
y
That's actually a smart way of doing it yes
I might consider it depending where I want my rls logic, I think it's better to have pseudo pure functions even in sql so your approach sounds really cool
c
your call