Software /
code /
prosody
Comparison
core/configmanager.lua @ 9241:2d82a926826f
configmanager: Allow referencing environment variables in the config as as ENV_<name>
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 03 Sep 2018 17:45:30 +0100 |
parent | 8692:a55574754e5f |
child | 9874:c9f5ccdcdf80 |
comparison
equal
deleted
inserted
replaced
9240:f9a83aca4421 | 9241:2d82a926826f |
---|---|
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 local _G = _G; | 9 local _G = _G; |
10 local setmetatable, rawget, rawset, io, error, dofile, type, pairs = | 10 local setmetatable, rawget, rawset, io, os, error, dofile, type, pairs = |
11 setmetatable, rawget, rawset, io, error, dofile, type, pairs; | 11 setmetatable, rawget, rawset, io, os, error, dofile, type, pairs; |
12 local format, math_max = string.format, math.max; | 12 local format, math_max = string.format, math.max; |
13 | 13 |
14 local envload = require"util.envload".envload; | 14 local envload = require"util.envload".envload; |
15 local deps = require"util.dependencies"; | 15 local deps = require"util.dependencies"; |
16 local resolve_relative_path = require"util.paths".resolve_relative_path; | 16 local resolve_relative_path = require"util.paths".resolve_relative_path; |
107 env = setmetatable({ | 107 env = setmetatable({ |
108 Host = true, host = true, VirtualHost = true, | 108 Host = true, host = true, VirtualHost = true, |
109 Component = true, component = true, | 109 Component = true, component = true, |
110 Include = true, include = true, RunScript = true }, { | 110 Include = true, include = true, RunScript = true }, { |
111 __index = function (_, k) | 111 __index = function (_, k) |
112 if k:match("^ENV_") then | |
113 return os.getenv(k:sub(5)); | |
114 end | |
112 return rawget(_G, k); | 115 return rawget(_G, k); |
113 end, | 116 end, |
114 __newindex = function (_, k, v) | 117 __newindex = function (_, k, v) |
115 set(config_table, env.__currenthost or "*", k, v); | 118 set(config_table, env.__currenthost or "*", k, v); |
116 end | 119 end |