grim/prosody_mod_auth_jetbrains_hub

Parents 04429328022c
Children 7a9ad183f1f1
lua is top down like C.. so get_group_query needs to be defined before calling it
--- a/mod_auth_jetbrains_hub.lua Thu Oct 24 04:55:25 2019 -0500
+++ b/mod_auth_jetbrains_hub.lua Thu Oct 24 05:11:15 2019 -0500
@@ -17,7 +17,7 @@
local host = module.host;
-- Options
-local hub_url = module:get_option_string("jetbrains_hub_url", ""):gsub("$host", host);
+local hub_url = module:get_option_string("jetbrains_hub_url", ""):gsub("$host", host);
if hub_url == "" then error("jetbrains_hub_url required") end
local hub_scopes = module:get_option_string("jetbrains_hub_scopes", "");
@@ -33,6 +33,31 @@
-- we only need to update the group part of the query once on load so do it
-- right away
+local function get_group_query()
+ -- if there's no groups, just return an empty string
+ if #hub_groups == 0 then
+ return ""
+ end
+
+ -- we have at least one group, so output the start of our query
+ local query = " and ("
+
+ for i, v in ipairs(hub_groups) do
+ -- add the group making sure to quote it as spaces are allowed and will
+ -- fail if they're not quoted.
+ query = query .. "in:\"" .. v .. "\""
+
+ -- if we have additional groups add our "or" separator between the
+ -- groups.
+ if i < #hub_groups then
+ query = query .. " or "
+ end
+ end
+
+ -- finally add our closing paren and return the query
+ return query .. ")"
+end
+
local group_query = get_group_query()
local provider = {};
@@ -103,31 +128,6 @@
end
end
-local function get_group_query()
- -- if there's no groups, just return an empty string
- if #hub_groups == 0 then
- return ""
- end
-
- -- we have at least one group, so output the start of our query
- local query = " and ("
-
- for i, v in ipairs(hub_groups) do
- -- add the group making sure to quote it as spaces are allowed and will
- -- fail if they're not quoted.
- query = query .. "in:\"" .. v .. "\""
-
- -- if we have additional groups add our "or" separator between the
- -- groups.
- if i < #hub_groups then
- query = query .. " or "
- end
- end
-
- -- finally add our closing paren and return the query
- return query .. ")"
-end
-
local function check_group(username, token)
local headers = { Authorization = "Bearer "..token; };
local body = {