From 4bb5af4b5afba42aaacae9d1ace7b9d4f4adc1ac Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Fri, 28 Oct 2022 22:01:07 +0200 Subject: [PATCH] nginx: Add check_role function to worker init --- hosts/architect/nginx.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hosts/architect/nginx.nix b/hosts/architect/nginx.nix index 8afc238..16a3542 100644 --- a/hosts/architect/nginx.nix +++ b/hosts/architect/nginx.nix @@ -47,6 +47,22 @@ # https://github.com/openresty/lua-resty-redis/issues/159 resolver local=on ipv6=off; + + init_worker_by_lua_block { + function check_role (res, role) + if res.user.roles == nil then + return false + end + + for _,v in pairs(res.user.roles) do + if string.lower(v) == role then + return true + end + end + + return false + end + } ''; appendConfig = ''