-
Notifications
You must be signed in to change notification settings - Fork 2
/
httpext.lua
45 lines (36 loc) · 985 Bytes
/
httpext.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
-- Package management module
-- HTTP Extensions
-- Copyright (c) 2017 Blizzard Entertainment
---
if http == nil then
return
end
function http.getVersion()
return _PREMAKE_VERSION .. " (" .. _PREMAKE_COMMIT .. ")"
end
function http.getUser()
return telemetry.getusername() or os.getenv('USERNAME') or os.getenv('LOGNAME') or '<unknown>'
end
function http.getComputer()
return telemetry.gethostname() or os.getenv('COMPUTERNAME') or os.getenv('HOSTNAME') or '<unknown>'
end
function http.getHttpHeader()
return {
'X-Premake-Version: ' .. http.getVersion(),
'X-Premake-User: ' .. http.getUser(),
"X-Premake-Machine: " .. http.getComputer(),
}
end
function http.getJson(servers, link)
for _, hostname in ipairs(servers) do
local content, result_str, result_code = http.get(hostname .. link, { headers = http.getHttpHeader() })
if content then
local tbl = json.decode(content)
if tbl ~= nil then
return tbl
end
end
end
return nil
end