Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint Lua with luacheck #232

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ else
logger:debug("Denied unauthenticated access to "..ngx.var.uri.." (corresponding perm: "..permission["id"]..")")
has_access = false
else
logger:debug("User "..authUser.." tries to access "..ngx.var.uri.." (corresponding perm: "..permission["id"]..")")
logger:debug(
"User "..authUser.." tries to access "..ngx.var.uri.." (corresponding perm: "..permission["id"]..")")

-- The user has permission to access the content if s.he is in the list of allowed users
if element_is_in_table(authUser, permission["users"]) then
Expand Down Expand Up @@ -275,11 +276,12 @@ end
-- 6. EFFECTIVELY PASS OR DENY ACCESS
--
-- If the user has access (either because app is public OR logged in + authorized)
-- -> pass + possibly inject the Basic Auth header on the fly such that the app can know which user is logged in
-- -> pass + possibly inject the Basic Auth header on the fly such that the app can know which user is logged in
--
-- Otherwise, the user can't access
-- -> either because not logged in at all, in that case, redirect to the portal WITH a callback url to redirect to after logging in
-- -> or because user is logged in, but has no access .. in that case just redirect to the portal
-- -> either because not logged in at all, in that case, redirect to the portal WITH a callback url to redirect to
-- after logging in
-- -> or because user is logged in, but has no access .. in that case just redirect to the portal
-- ###########################################################################

function set_basic_auth_header()
Expand Down
17 changes: 11 additions & 6 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function get_cookie_secret()
local cookie_secret_path = conf_["cookie_secret_file"] or "/etc/yunohost/.ssowat_cookie_secret"

if file_can_be_opened_for_reading(cookie_secret_path) == false then
ngx.log(ngx.STDERR, "Cookie secret file doesn't exist (yet?) or can't be opened for reading. Authentication will be disabled for now.")
ngx.log(ngx.STDERR, "Cookie secret file doesn't exist (yet?) or can't be opened for reading. " ..
"Authentication will be disabled for now.")
return nil
end

Expand All @@ -40,18 +41,21 @@ function get_cookie_secret()
cookie_secret_file:close()
return cookie_secret
else
ngx.log(ngx.STDERR, "Cookie secret file doesn't exist (yet?) or can't be opened for reading. Authentication will be disabled for now.")
ngx.log(ngx.STDERR, "Cookie secret file doesn't exist (yet?) or can't be opened for reading. " ..
"Authentication will be disabled for now.")
return nil
end
end

function compare_attributes(file_attributes1, file_attributes2)
if file_attributes1 == nil and file_attributes2 == nil then
return true
elseif file_attributes1 == nil and file_attributes2 ~= nil or file_attributes1 ~= nil and file_attributes2 == nil then
elseif file_attributes1 == nil and file_attributes2 ~= nil or
file_attributes1 ~= nil and file_attributes2 == nil then
return false
end
return file_attributes1["modification"] == file_attributes2["modification"] and file_attributes1["size"] == file_attributes2["size"]
return file_attributes1["modification"] == file_attributes2["modification"] and
file_attributes1["size"] == file_attributes2["size"]
end

function get_config()
Expand All @@ -60,7 +64,8 @@ function get_config()
local new_config_attributes = lfs.attributes(conf_path, {"modification", "size"})
local new_config_persistent_attributes = lfs.attributes(conf_path..".persistent", {"modification", "size"})

if compare_attributes(new_config_attributes, config_attributes) and compare_attributes(new_config_persistent_attributes, config_persistent_attributes) then
if compare_attributes(new_config_attributes, config_attributes) and
compare_attributes(new_config_persistent_attributes, config_persistent_attributes) then
return conf
-- If the file is being written, its size may be 0 and reloading fails, return the last valid config
elseif new_config_attributes == nil or new_config_attributes["size"] == 0 then
Expand All @@ -70,7 +75,7 @@ function get_config()
-- If the timestamp of the modification or the size is different, reload the configuration.
config_attributes = new_config_attributes
config_persistent_attributes = new_config_persistent_attributes

local conf_file = assert(io.open(conf_path, "r"), "Configuration file is missing")
conf = json.decode(conf_file:read("*all"))
conf_file:close()
Expand Down
Loading