This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
2020-07-28 09:19:03 +00:00
|
|
|
rewrite_by_lua_block {
|
2020-07-08 12:09:54 +00:00
|
|
|
local b64 = require("ngx.base64")
|
|
|
|
-- open apipassword file for reading (b flag is required for some reason)
|
|
|
|
-- (file /etc/.sia/apipassword has to be mounted from the host system)
|
|
|
|
local apipassword_file = io.open("/data/sia/apipassword", "rb")
|
|
|
|
-- read apipassword file contents and trim newline (important)
|
|
|
|
local apipassword = apipassword_file:read("*all"):gsub("%s+", "")
|
|
|
|
-- make sure to close file after reading the password
|
|
|
|
apipassword_file.close()
|
2020-07-28 09:19:03 +00:00
|
|
|
-- encode the user:password authorization string
|
|
|
|
-- (in our case user is empty so it is just :password)
|
2020-07-08 12:09:54 +00:00
|
|
|
local content = b64.encode_base64url(":" .. apipassword)
|
2020-07-28 09:19:03 +00:00
|
|
|
-- set authorization header with proper base64 encoded string
|
2020-07-08 12:09:54 +00:00
|
|
|
ngx.req.set_header("Authorization", "Basic " .. content)
|
2020-07-28 09:19:03 +00:00
|
|
|
}
|