Utilities
The nauthilus_util module provides several helper functions for Lua scripts in Nauthilus.
local nauthilus_util = require("nauthilus_util")
Functions
nauthilus_util.getenv
Returns the value of an environment variable, cached via nauthilus_cache.
Syntax
local val = nauthilus_util.getenv(name, default)
Parameters
name(string) - The name of the environment variable.default(string) - A default value if the environment variable is not set.
Returns
val(string) - The value of the environment variable or the default value.
Example
local api_url = nauthilus_util.getenv("API_URL", "http://localhost:8080")
nauthilus_util.exists_in_table
Iterates over a flat Lua table (list) and checks if a string was found in the values.
Syntax
local found = nauthilus_util.exists_in_table(tbl, element)
Parameters
tbl(table) - The table to search in.element(string) - The string to search for.
Returns
found(boolean) -trueif found,falseotherwise.
Example
local roles = {"admin", "user", "guest"}
if nauthilus_util.exists_in_table(roles, "admin") then
-- User is an admin
end
nauthilus_util.get_current_timestamp
Creates a timestamp string valid for logging purposes. It respects the TZ environment variable.
Syntax
local ts = nauthilus_util.get_current_timestamp()
Returns
ts(string) - A formatted timestamp string (e.g., "2006-01-02T15:04:05 -07:00").