Add optional API key support for server authentication in inventoryWebBridge
This commit is contained in:
@@ -22,6 +22,7 @@ local ORDER_CHANNEL = 4201
|
||||
-------------------------------------------------
|
||||
|
||||
local CONFIG_FILE = ".webbridge_config"
|
||||
local API_KEY = nil -- optional API key for server auth
|
||||
|
||||
local function loadConfig()
|
||||
if fs.exists(CONFIG_FILE) then
|
||||
@@ -47,7 +48,6 @@ local latestState = nil -- last broadcast from master
|
||||
local modem = nil
|
||||
local modemName = nil
|
||||
local running = true
|
||||
local API_KEY = nil -- optional API key for server auth
|
||||
|
||||
-------------------------------------------------
|
||||
-- Find modem
|
||||
@@ -75,7 +75,7 @@ local function httpPost(path, body)
|
||||
local headers = { ["Content-Type"] = "application/json" }
|
||||
if API_KEY then headers["Authorization"] = "Bearer " .. API_KEY end
|
||||
|
||||
local ok, err = pcall(function()
|
||||
local ok, result = pcall(function()
|
||||
local response = http.post(url, data, headers)
|
||||
if response then
|
||||
local responseData = response.readAll()
|
||||
@@ -84,10 +84,10 @@ local function httpPost(path, body)
|
||||
end
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
-- Silent fail, will retry
|
||||
return nil
|
||||
if ok then
|
||||
return result
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function httpGet(path)
|
||||
|
||||
Reference in New Issue
Block a user