Software /
code /
prosody
Annotate
core/configmanager.lua @ 13753:07b6a669f7f1 default tip
Merge 13.0->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 24 Feb 2025 17:49:55 +0000 |
parent | 13745:994ea8d54b72 |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1504
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2862
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2862
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
466
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
466
diff
changeset
|
8 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local _G = _G; |
9876
d812031c8716
configmanager: Pass through warnings from included files
Matthew Wild <mwild1@gmail.com>
parents:
9875
diff
changeset
|
10 local setmetatable, rawget, rawset, io, os, error, dofile, type, pairs, ipairs = |
d812031c8716
configmanager: Pass through warnings from included files
Matthew Wild <mwild1@gmail.com>
parents:
9875
diff
changeset
|
11 setmetatable, rawget, rawset, io, os, error, dofile, type, pairs, ipairs; |
9874
c9f5ccdcdf80
configmanager: Add support for returning warnings
Matthew Wild <mwild1@gmail.com>
parents:
9241
diff
changeset
|
12 local format, math_max, t_insert = string.format, math.max, table.insert; |
2861
1402615b66f8
configmanager: Error when a component and host clash hostnames
Matthew Wild <mwild1@gmail.com>
parents:
1777
diff
changeset
|
13 |
12972
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12531
diff
changeset
|
14 local envload = require"prosody.util.envload".envload; |
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12531
diff
changeset
|
15 local deps = require"prosody.util.dependencies"; |
13390
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
16 local it = require"prosody.util.iterators"; |
12972
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12531
diff
changeset
|
17 local resolve_relative_path = require"prosody.util.paths".resolve_relative_path; |
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12531
diff
changeset
|
18 local glob_to_pattern = require"prosody.util.paths".glob_to_pattern; |
3609
954b1159f2f3
prosody, configmanager, certmanager: Relocate prosody.resolve_relative_path() to configmanager, and update certmanager (the only user of this function)
Matthew Wild <mwild1@gmail.com>
parents:
3573
diff
changeset
|
19 local path_sep = package.config:sub(1,1); |
12972
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12531
diff
changeset
|
20 local get_traceback_table = require "prosody.util.debug".get_traceback_table; |
13671
0c8c1a8338d1
core.configmanager: Delay reporting warnings about Credential until use
Kim Alvefur <zash@zash.se>
parents:
13631
diff
changeset
|
21 local errors = require "prosody.util.error"; |
0c8c1a8338d1
core.configmanager: Delay reporting warnings about Credential until use
Kim Alvefur <zash@zash.se>
parents:
13631
diff
changeset
|
22 local log = require "prosody.util.logger".init("config"); |
3609
954b1159f2f3
prosody, configmanager, certmanager: Relocate prosody.resolve_relative_path() to configmanager, and update certmanager (the only user of this function)
Matthew Wild <mwild1@gmail.com>
parents:
3573
diff
changeset
|
23 |
12972
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12531
diff
changeset
|
24 local encodings = deps.softreq"prosody.util.encodings"; |
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6718
diff
changeset
|
25 local nameprep = encodings and encodings.stringprep.nameprep or function (host) return host:lower(); end |
6323
5926f01e5cd2
configmanager: nameprep VirtualHost and Component names
Matthew Wild <mwild1@gmail.com>
parents:
6166
diff
changeset
|
26 |
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6718
diff
changeset
|
27 local _M = {}; |
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6718
diff
changeset
|
28 local _ENV = nil; |
8555
4f0f5b49bb03
vairious: Add annotation when an empty environment is set [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8158
diff
changeset
|
29 -- luacheck: std none |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
6164
ef4024f6bc40
core.configmanager: Move path utility functions into util.paths
Kim Alvefur <zash@zash.se>
parents:
5814
diff
changeset
|
31 _M.resolve_relative_path = resolve_relative_path; -- COMPAT |
ef4024f6bc40
core.configmanager: Move path utility functions into util.paths
Kim Alvefur <zash@zash.se>
parents:
5814
diff
changeset
|
32 |
8153
c22d5680ca68
configmanager: Remove support for multiple parsers, fixes #852.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7947
diff
changeset
|
33 local parser = nil; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
6715
03a283aa679e
configmanager: Rename unused function argument [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6714
diff
changeset
|
35 local config_mt = { __index = function (t, _) return rawget(t, "*"); end}; |
5357
ac530c44772e
configmanager, hostmanager, prosody: Almost complete removal of section-related code, and the infamous 'core' section. Still backwards-compatible with API users.
Matthew Wild <mwild1@gmail.com>
parents:
5124
diff
changeset
|
36 local config = setmetatable({ ["*"] = { } }, config_mt); |
12440
1ef893715311
configmanager: Add method to report loaded config files (part of #1729 fix)
Matthew Wild <mwild1@gmail.com>
parents:
12083
diff
changeset
|
37 local files = {}; |
13743
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
38 local credentials_directory = nil; |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
39 local credential_fallback_fatal = true; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 -- When host not found, use global |
5380
e119e378b1d9
configmanager: Fix so unset variables are searched for in the global section
Kim Alvefur <zash@zash.se>
parents:
5357
diff
changeset
|
42 local host_mt = { __index = function(_, k) return config["*"][k] end } |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 |
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6718
diff
changeset
|
44 function _M.getconfig() |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
45 return config; |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
46 end |
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
47 |
12531
32bcb899526f
core.configmanager: Remove COMPAT for old config format from 2013
Kim Alvefur <zash@zash.se>
parents:
12448
diff
changeset
|
48 function _M.get(host, key) |
13744
34ac05f6bd10
core.configmanager: Fix reporting delayed warnings from global section
Kim Alvefur <zash@zash.se>
parents:
13743
diff
changeset
|
49 local v = config[host][key]; |
34ac05f6bd10
core.configmanager: Fix reporting delayed warnings from global section
Kim Alvefur <zash@zash.se>
parents:
13743
diff
changeset
|
50 if v and errors.is_error(v) then |
13745
994ea8d54b72
core.configmanager: Pass name and line number in context
Kim Alvefur <zash@zash.se>
parents:
13744
diff
changeset
|
51 log("warn", "%s:%d: %s", v.context.filename, v.context.fileline, v.text); |
13744
34ac05f6bd10
core.configmanager: Fix reporting delayed warnings from global section
Kim Alvefur <zash@zash.se>
parents:
13743
diff
changeset
|
52 return nil; |
13671
0c8c1a8338d1
core.configmanager: Delay reporting warnings about Credential until use
Kim Alvefur <zash@zash.se>
parents:
13631
diff
changeset
|
53 end |
13744
34ac05f6bd10
core.configmanager: Fix reporting delayed warnings from global section
Kim Alvefur <zash@zash.se>
parents:
13743
diff
changeset
|
54 return v; |
5357
ac530c44772e
configmanager, hostmanager, prosody: Almost complete removal of section-related code, and the infamous 'core' section. Still backwards-compatible with API users.
Matthew Wild <mwild1@gmail.com>
parents:
5124
diff
changeset
|
55 end |
12531
32bcb899526f
core.configmanager: Remove COMPAT for old config format from 2013
Kim Alvefur <zash@zash.se>
parents:
12448
diff
changeset
|
56 function _M.rawget(host, key) |
4001
2e8411f6cb14
configmanager: Added rawget().
Waqas Hussain <waqas20@gmail.com>
parents:
3929
diff
changeset
|
57 local hostconfig = rawget(config, host); |
2e8411f6cb14
configmanager: Added rawget().
Waqas Hussain <waqas20@gmail.com>
parents:
3929
diff
changeset
|
58 if hostconfig then |
5357
ac530c44772e
configmanager, hostmanager, prosody: Almost complete removal of section-related code, and the infamous 'core' section. Still backwards-compatible with API users.
Matthew Wild <mwild1@gmail.com>
parents:
5124
diff
changeset
|
59 return rawget(hostconfig, key); |
4001
2e8411f6cb14
configmanager: Added rawget().
Waqas Hussain <waqas20@gmail.com>
parents:
3929
diff
changeset
|
60 end |
2e8411f6cb14
configmanager: Added rawget().
Waqas Hussain <waqas20@gmail.com>
parents:
3929
diff
changeset
|
61 end |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 |
6712
29d5875ae38d
configmanager: Rename variable to avoid name conflict [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6326
diff
changeset
|
63 local function set(config_table, host, key, value) |
5357
ac530c44772e
configmanager, hostmanager, prosody: Almost complete removal of section-related code, and the infamous 'core' section. Still backwards-compatible with API users.
Matthew Wild <mwild1@gmail.com>
parents:
5124
diff
changeset
|
64 if host and key then |
6712
29d5875ae38d
configmanager: Rename variable to avoid name conflict [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6326
diff
changeset
|
65 local hostconfig = rawget(config_table, host); |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 if not hostconfig then |
6712
29d5875ae38d
configmanager: Rename variable to avoid name conflict [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6326
diff
changeset
|
67 hostconfig = rawset(config_table, host, setmetatable({}, host_mt))[host]; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 end |
5357
ac530c44772e
configmanager, hostmanager, prosody: Almost complete removal of section-related code, and the infamous 'core' section. Still backwards-compatible with API users.
Matthew Wild <mwild1@gmail.com>
parents:
5124
diff
changeset
|
69 hostconfig[key] = value; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 return true; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 return false; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 |
13388
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
75 local function rawget_option(config_table, host, key) |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
76 if host and key then |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
77 local hostconfig = rawget(config_table, host); |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
78 if not hostconfig then |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
79 return nil; |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
80 end |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
81 return rawget(hostconfig, key); |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
82 end |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
83 end |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
84 |
12531
32bcb899526f
core.configmanager: Remove COMPAT for old config format from 2013
Kim Alvefur <zash@zash.se>
parents:
12448
diff
changeset
|
85 function _M.set(host, key, value) |
5357
ac530c44772e
configmanager, hostmanager, prosody: Almost complete removal of section-related code, and the infamous 'core' section. Still backwards-compatible with API users.
Matthew Wild <mwild1@gmail.com>
parents:
5124
diff
changeset
|
86 return set(config, host, key, value); |
3573
f31fa6520a4b
configmanager: Atomic reloads, and some other internal changes to achieve this
Matthew Wild <mwild1@gmail.com>
parents:
3515
diff
changeset
|
87 end |
f31fa6520a4b
configmanager: Atomic reloads, and some other internal changes to achieve this
Matthew Wild <mwild1@gmail.com>
parents:
3515
diff
changeset
|
88 |
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6718
diff
changeset
|
89 function _M.load(filename, config_format) |
6713
b628870b1bd6
configmanager: Rename variable to avoid name conflict [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6712
diff
changeset
|
90 config_format = config_format or filename:match("%w+$"); |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
91 |
8153
c22d5680ca68
configmanager: Remove support for multiple parsers, fixes #852.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7947
diff
changeset
|
92 if config_format == "lua" then |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
93 local f, err = io.open(filename); |
2552
8dda55217e83
configmanager: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents:
2427
diff
changeset
|
94 if f then |
5357
ac530c44772e
configmanager, hostmanager, prosody: Almost complete removal of section-related code, and the infamous 'core' section. Still backwards-compatible with API users.
Matthew Wild <mwild1@gmail.com>
parents:
5124
diff
changeset
|
95 local new_config = setmetatable({ ["*"] = { } }, config_mt); |
8153
c22d5680ca68
configmanager: Remove support for multiple parsers, fixes #852.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7947
diff
changeset
|
96 local ok, err = parser.load(f:read("*a"), filename, new_config); |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 f:close(); |
3613
f617718d2221
configmanager: Change parser API again to pass a config table to insert settings to. Fixes Include(). (Thanks Zash/answerman)
Matthew Wild <mwild1@gmail.com>
parents:
3610
diff
changeset
|
98 if ok then |
3573
f31fa6520a4b
configmanager: Atomic reloads, and some other internal changes to achieve this
Matthew Wild <mwild1@gmail.com>
parents:
3515
diff
changeset
|
99 config = new_config; |
1000
a73715a9267f
core.configmanager: Fire event when (re)loading config file
Matthew Wild <mwild1@gmail.com>
parents:
913
diff
changeset
|
100 end |
3780
791aede977da
configmanager: Switch back to returning 'ok' to signal config load success - fixes config errors not being displayed
Matthew Wild <mwild1@gmail.com>
parents:
3613
diff
changeset
|
101 return ok, "parser", err; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 end |
793
55add3b87c01
Report errors in the config file to the user
Matthew Wild <mwild1@gmail.com>
parents:
760
diff
changeset
|
103 return f, "file", err; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 end |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
105 |
6713
b628870b1bd6
configmanager: Rename variable to avoid name conflict [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6712
diff
changeset
|
106 if not config_format then |
793
55add3b87c01
Report errors in the config file to the user
Matthew Wild <mwild1@gmail.com>
parents:
760
diff
changeset
|
107 return nil, "file", "no parser specified"; |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
108 else |
6713
b628870b1bd6
configmanager: Rename variable to avoid name conflict [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6712
diff
changeset
|
109 return nil, "file", "no parser for "..(config_format); |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
110 end |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 |
12440
1ef893715311
configmanager: Add method to report loaded config files (part of #1729 fix)
Matthew Wild <mwild1@gmail.com>
parents:
12083
diff
changeset
|
113 function _M.files() |
1ef893715311
configmanager: Add method to report loaded config files (part of #1729 fix)
Matthew Wild <mwild1@gmail.com>
parents:
12083
diff
changeset
|
114 return files; |
1ef893715311
configmanager: Add method to report loaded config files (part of #1729 fix)
Matthew Wild <mwild1@gmail.com>
parents:
12083
diff
changeset
|
115 end |
1ef893715311
configmanager: Add method to report loaded config files (part of #1729 fix)
Matthew Wild <mwild1@gmail.com>
parents:
12083
diff
changeset
|
116 |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
117 -- Built-in Lua parser |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 do |
6714
429068c24ea0
configmanager: Remove unnecessary function localizations [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6713
diff
changeset
|
119 local pcall = _G.pcall; |
9875
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
120 local function get_line_number(config_file) |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
121 local tb = get_traceback_table(nil, 2); |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
122 for i = 1, #tb do |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
123 if tb[i].info.short_src == config_file then |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
124 return tb[i].info.currentline; |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
125 end |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
126 end |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
127 end |
13390
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
128 |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
129 local config_option_proxy_mt = { |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
130 __index = setmetatable({ |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
131 append = function (self, value) |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
132 local original_option = self:value(); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
133 if original_option == nil then |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
134 original_option = {}; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
135 end |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
136 if type(value) ~= "table" then |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
137 error("'append' operation expects a list of values to append to the existing list", 2); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
138 end |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
139 if value[1] ~= nil then |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
140 for _, v in ipairs(value) do |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
141 t_insert(original_option, v); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
142 end |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
143 else |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
144 for k, v in pairs(value) do |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
145 original_option[k] = v; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
146 end |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
147 end |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
148 set(self.config_table, self.host, self.option_name, original_option); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
149 return self; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
150 end; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
151 value = function (self) |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
152 return rawget_option(self.config_table, self.host, self.option_name); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
153 end; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
154 values = function (self) |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
155 return it.values(self:value()); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
156 end; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
157 }, { |
13391
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
158 __index = function (t, k) --luacheck: ignore 212/t |
13390
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
159 error("Unknown config option operation: '"..k.."'", 2); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
160 end; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
161 }); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
162 |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
163 __call = function (self, v2) |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
164 local v = self:value() or {}; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
165 if type(v) == "table" and type(v2) == "table" then |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
166 return self:append(v2); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
167 end |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
168 |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
169 error("Invalid syntax - missing '=' perhaps?", 2); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
170 end; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
171 }; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
172 |
13626
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
173 -- For reading config values out of files. |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
174 local function filereader(basepath, defaultmode) |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
175 return function(filename, mode) |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
176 local f, err = io.open(resolve_relative_path(basepath, filename)); |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
177 if not f then error(err, 2); end |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
178 local content, err = f:read(mode or defaultmode); |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
179 f:close(); |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
180 if not content then error(err, 2); end |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
181 return content; |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
182 end |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
183 end |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
184 |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
185 -- Collect lines into an array |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
186 local function linereader(basepath) |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
187 return function(filename) |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
188 local ret = {}; |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
189 for line in io.lines(resolve_relative_path(basepath, filename)) do |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
190 t_insert(ret, line); |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
191 end |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
192 return ret; |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
193 end |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
194 end |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
195 |
8153
c22d5680ca68
configmanager: Remove support for multiple parsers, fixes #852.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7947
diff
changeset
|
196 parser = {}; |
c22d5680ca68
configmanager: Remove support for multiple parsers, fixes #852.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7947
diff
changeset
|
197 function parser.load(data, config_file, config_table) |
9875
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
198 local set_options = {}; -- set_options[host.."/"..option_name] = true (when the option has been set already in this file) |
9874
c9f5ccdcdf80
configmanager: Add support for returning warnings
Matthew Wild <mwild1@gmail.com>
parents:
9241
diff
changeset
|
199 local warnings = {}; |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
200 local env; |
13626
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
201 local config_path = config_file:gsub("[^"..path_sep.."]+$", ""); |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
202 |
750
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
203 -- The ' = true' are needed so as not to set off __newindex when we assign the functions below |
2975
c1a2e210f47e
configmanager: Fix very wacky indentation
Matthew Wild <mwild1@gmail.com>
parents:
2974
diff
changeset
|
204 env = setmetatable({ |
3012 | 205 Host = true, host = true, VirtualHost = true, |
206 Component = true, component = true, | |
13626
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
207 FileContents = true, |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
208 FileLine = true, |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
209 FileLines = true, |
13628
4fdd406564ea
core.configmanager: Rename Secret to Credential
Kim Alvefur <zash@zash.se>
parents:
13627
diff
changeset
|
210 Credential = true, |
3610
2084959d4096
configmanager: Update Include and RunScript directives to support paths relative to the (current!) config file
Matthew Wild <mwild1@gmail.com>
parents:
3609
diff
changeset
|
211 Include = true, include = true, RunScript = true }, { |
6717
4fecfc81dac1
configmanager: Rename unused function arguments [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6716
diff
changeset
|
212 __index = function (_, k) |
9241
2d82a926826f
configmanager: Allow referencing environment variables in the config as as ENV_<name>
Matthew Wild <mwild1@gmail.com>
parents:
8692
diff
changeset
|
213 if k:match("^ENV_") then |
2d82a926826f
configmanager: Allow referencing environment variables in the config as as ENV_<name>
Matthew Wild <mwild1@gmail.com>
parents:
8692
diff
changeset
|
214 return os.getenv(k:sub(5)); |
2d82a926826f
configmanager: Allow referencing environment variables in the config as as ENV_<name>
Matthew Wild <mwild1@gmail.com>
parents:
8692
diff
changeset
|
215 end |
13389
47d0d80da208
configmanager: Make _G accessible via `Lua` variable, deprecate direct access
Matthew Wild <mwild1@gmail.com>
parents:
13388
diff
changeset
|
216 if k == "Lua" then |
47d0d80da208
configmanager: Make _G accessible via `Lua` variable, deprecate direct access
Matthew Wild <mwild1@gmail.com>
parents:
13388
diff
changeset
|
217 return _G; |
47d0d80da208
configmanager: Make _G accessible via `Lua` variable, deprecate direct access
Matthew Wild <mwild1@gmail.com>
parents:
13388
diff
changeset
|
218 end |
13388
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
219 local val = rawget_option(config_table, env.__currenthost or "*", k); |
13389
47d0d80da208
configmanager: Make _G accessible via `Lua` variable, deprecate direct access
Matthew Wild <mwild1@gmail.com>
parents:
13388
diff
changeset
|
220 |
13390
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
221 local g_val = rawget(_G, k); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
222 |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
223 if val ~= nil or g_val == nil then |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
224 if type(val) == "table" then |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
225 return setmetatable({ |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
226 config_table = config_table; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
227 host = env.__currenthost or "*"; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
228 option_name = k; |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
229 }, config_option_proxy_mt); |
905a6009f60d
configmanager: Support for appending to existing config options
Matthew Wild <mwild1@gmail.com>
parents:
13389
diff
changeset
|
230 end |
13388
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
231 return val; |
de6c1a170871
configmanager: Allow referencing previously-set options in the config file
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
232 end |
13389
47d0d80da208
configmanager: Make _G accessible via `Lua` variable, deprecate direct access
Matthew Wild <mwild1@gmail.com>
parents:
13388
diff
changeset
|
233 |
47d0d80da208
configmanager: Make _G accessible via `Lua` variable, deprecate direct access
Matthew Wild <mwild1@gmail.com>
parents:
13388
diff
changeset
|
234 if g_val ~= nil then |
13391
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
235 t_insert( |
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
236 warnings, |
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
237 ("%s:%d: direct usage of the Lua API is deprecated - replace `%s` with `Lua.%s`"):format( |
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
238 config_file, |
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
239 get_line_number(config_file), |
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
240 k, |
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
241 k |
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
242 ) |
5c783cf58ae7
configmanager: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13390
diff
changeset
|
243 ); |
13389
47d0d80da208
configmanager: Make _G accessible via `Lua` variable, deprecate direct access
Matthew Wild <mwild1@gmail.com>
parents:
13388
diff
changeset
|
244 end |
47d0d80da208
configmanager: Make _G accessible via `Lua` variable, deprecate direct access
Matthew Wild <mwild1@gmail.com>
parents:
13388
diff
changeset
|
245 |
47d0d80da208
configmanager: Make _G accessible via `Lua` variable, deprecate direct access
Matthew Wild <mwild1@gmail.com>
parents:
13388
diff
changeset
|
246 return g_val; |
2975
c1a2e210f47e
configmanager: Fix very wacky indentation
Matthew Wild <mwild1@gmail.com>
parents:
2974
diff
changeset
|
247 end, |
6717
4fecfc81dac1
configmanager: Rename unused function arguments [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6716
diff
changeset
|
248 __newindex = function (_, k, v) |
9875
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
249 local host = env.__currenthost or "*"; |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
250 local option_path = host.."/"..k; |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
251 if set_options[option_path] then |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
252 t_insert(warnings, ("%s:%d: Duplicate option '%s'"):format(config_file, get_line_number(config_file), k)); |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
253 end |
99291e124449
configmanager: Emit warning for duplicated config options
Matthew Wild <mwild1@gmail.com>
parents:
9874
diff
changeset
|
254 set_options[option_path] = true; |
6717
4fecfc81dac1
configmanager: Rename unused function arguments [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6716
diff
changeset
|
255 set(config_table, env.__currenthost or "*", k, v); |
2975
c1a2e210f47e
configmanager: Fix very wacky indentation
Matthew Wild <mwild1@gmail.com>
parents:
2974
diff
changeset
|
256 end |
c1a2e210f47e
configmanager: Fix very wacky indentation
Matthew Wild <mwild1@gmail.com>
parents:
2974
diff
changeset
|
257 }); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
258 |
1615
0e3eacf135f2
configmanager: Default options appearing before Host "*" to global (fixes potential traceback)
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
259 rawset(env, "__currenthost", "*") -- Default is global |
3011
1189a29cd846
configmanager: Add VirtualHost as an alias for Host (re-applied in trunk due to previous bad merge with 0.7)
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
260 function env.VirtualHost(name) |
10374
a83233559253
core.configmanager: Ensure Hosts are given names
Kim Alvefur <zash@zash.se>
parents:
10206
diff
changeset
|
261 if not name then |
a83233559253
core.configmanager: Ensure Hosts are given names
Kim Alvefur <zash@zash.se>
parents:
10206
diff
changeset
|
262 error("Host must have a name", 2); |
a83233559253
core.configmanager: Ensure Hosts are given names
Kim Alvefur <zash@zash.se>
parents:
10206
diff
changeset
|
263 end |
10375
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
264 local prepped_name = nameprep(name); |
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
265 if not prepped_name then |
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
266 error(format("Name of Host %q contains forbidden characters", name), 0); |
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
267 end |
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
268 name = prepped_name; |
6716
2b78754b0f1c
configmanager: Rename variable to avoid name conflicts [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6715
diff
changeset
|
269 if rawget(config_table, name) and rawget(config_table[name], "component_module") then |
2861
1402615b66f8
configmanager: Error when a component and host clash hostnames
Matthew Wild <mwild1@gmail.com>
parents:
1777
diff
changeset
|
270 error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", |
6716
2b78754b0f1c
configmanager: Rename variable to avoid name conflicts [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6715
diff
changeset
|
271 name, config_table[name].component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); |
2861
1402615b66f8
configmanager: Error when a component and host clash hostnames
Matthew Wild <mwild1@gmail.com>
parents:
1777
diff
changeset
|
272 end |
376
6d87944df37c
New configmanager. Old-style config files still work, but will print a warning
Matthew Wild <mwild1@gmail.com>
parents:
371
diff
changeset
|
273 rawset(env, "__currenthost", name); |
750
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
274 -- Needs at least one setting to logically exist :) |
6716
2b78754b0f1c
configmanager: Rename variable to avoid name conflicts [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6715
diff
changeset
|
275 set(config_table, name or "*", "defined", true); |
3515
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
276 return function (config_options) |
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
277 rawset(env, "__currenthost", "*"); -- Return to global scope |
12448
fb7e76c1ad1c
configmanager: Clearer errors when providing unexpected values after VirtualHost (fixes #1735, thanks arawaks)
Matthew Wild <mwild1@gmail.com>
parents:
12440
diff
changeset
|
278 if type(config_options) == "string" then |
fb7e76c1ad1c
configmanager: Clearer errors when providing unexpected values after VirtualHost (fixes #1735, thanks arawaks)
Matthew Wild <mwild1@gmail.com>
parents:
12440
diff
changeset
|
279 error(format("VirtualHost entries do not accept a module name (module '%s' provided for host '%s')", config_options, name), 2); |
fb7e76c1ad1c
configmanager: Clearer errors when providing unexpected values after VirtualHost (fixes #1735, thanks arawaks)
Matthew Wild <mwild1@gmail.com>
parents:
12440
diff
changeset
|
280 elseif type(config_options) ~= "table" then |
fb7e76c1ad1c
configmanager: Clearer errors when providing unexpected values after VirtualHost (fixes #1735, thanks arawaks)
Matthew Wild <mwild1@gmail.com>
parents:
12440
diff
changeset
|
281 error("Invalid syntax following VirtualHost, expected options but received a "..type(config_options), 2); |
fb7e76c1ad1c
configmanager: Clearer errors when providing unexpected values after VirtualHost (fixes #1735, thanks arawaks)
Matthew Wild <mwild1@gmail.com>
parents:
12440
diff
changeset
|
282 end |
3515
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
283 for option_name, option_value in pairs(config_options) do |
6716
2b78754b0f1c
configmanager: Rename variable to avoid name conflicts [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6715
diff
changeset
|
284 set(config_table, name or "*", option_name, option_value); |
3515
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
285 end |
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
286 end; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
287 end |
3011
1189a29cd846
configmanager: Add VirtualHost as an alias for Host (re-applied in trunk due to previous bad merge with 0.7)
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
288 env.Host, env.host = env.VirtualHost, env.VirtualHost; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
289 |
750
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
290 function env.Component(name) |
10374
a83233559253
core.configmanager: Ensure Hosts are given names
Kim Alvefur <zash@zash.se>
parents:
10206
diff
changeset
|
291 if not name then |
a83233559253
core.configmanager: Ensure Hosts are given names
Kim Alvefur <zash@zash.se>
parents:
10206
diff
changeset
|
292 error("Component must have a name", 2); |
a83233559253
core.configmanager: Ensure Hosts are given names
Kim Alvefur <zash@zash.se>
parents:
10206
diff
changeset
|
293 end |
10375
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
294 local prepped_name = nameprep(name); |
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
295 if not prepped_name then |
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
296 error(format("Name of Component %q contains forbidden characters", name), 0); |
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
297 end |
3d0adbc74c39
core.configmanager: Handle nameprep validation errors
Kim Alvefur <zash@zash.se>
parents:
10374
diff
changeset
|
298 name = prepped_name; |
7947
24170d74b00b
core: Split some very long lines [luacheck]
Kim Alvefur <zash@zash.se>
parents:
6779
diff
changeset
|
299 if rawget(config_table, name) and rawget(config_table[name], "defined") |
24170d74b00b
core: Split some very long lines [luacheck]
Kim Alvefur <zash@zash.se>
parents:
6779
diff
changeset
|
300 and not rawget(config_table[name], "component_module") then |
12083
ec21e379c145
configmanager: Update error message to say 'VirtualHost' instead of 'Host'
Matthew Wild <mwild1@gmail.com>
parents:
10375
diff
changeset
|
301 error(format("Component %q clashes with previously defined VirtualHost %q, for services use a sub-domain like conference.%s", |
2861
1402615b66f8
configmanager: Error when a component and host clash hostnames
Matthew Wild <mwild1@gmail.com>
parents:
1777
diff
changeset
|
302 name, name, name), 0); |
1402615b66f8
configmanager: Error when a component and host clash hostnames
Matthew Wild <mwild1@gmail.com>
parents:
1777
diff
changeset
|
303 end |
6716
2b78754b0f1c
configmanager: Rename variable to avoid name conflicts [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6715
diff
changeset
|
304 set(config_table, name, "component_module", "component"); |
913
3e2dac84017d
core.configmanager: Make components use 'component' module by default if none specified
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
305 -- Don't load the global modules by default |
6716
2b78754b0f1c
configmanager: Rename variable to avoid name conflicts [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6715
diff
changeset
|
306 set(config_table, name, "load_global_modules", false); |
913
3e2dac84017d
core.configmanager: Make components use 'component' module by default if none specified
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
307 rawset(env, "__currenthost", name); |
3515
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
308 local function handle_config_options(config_options) |
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
309 rawset(env, "__currenthost", "*"); -- Return to global scope |
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
310 for option_name, option_value in pairs(config_options) do |
6716
2b78754b0f1c
configmanager: Rename variable to avoid name conflicts [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6715
diff
changeset
|
311 set(config_table, name or "*", option_name, option_value); |
3515
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
312 end |
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
313 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
314 |
750
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
315 return function (module) |
857
49298263f241
core.configmanager: Small fix to check validity of Component definitions
Matthew Wild <mwild1@gmail.com>
parents:
795
diff
changeset
|
316 if type(module) == "string" then |
6716
2b78754b0f1c
configmanager: Rename variable to avoid name conflicts [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6715
diff
changeset
|
317 set(config_table, name, "component_module", module); |
3515
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
318 return handle_config_options; |
857
49298263f241
core.configmanager: Small fix to check validity of Component definitions
Matthew Wild <mwild1@gmail.com>
parents:
795
diff
changeset
|
319 end |
3515
bb494c3aa364
configmanager: Allow VirtualHost/Component definitions to be followed by a table of config options
Matthew Wild <mwild1@gmail.com>
parents:
3384
diff
changeset
|
320 return handle_config_options(module); |
750
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
321 end |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
322 end |
fbfcf8c1c830
configmanager: Add support for defining components
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
323 env.component = env.Component; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
324 |
5413
0bf5e90be086
configmanager: Some cleanup, remove unused variables and imports
Matthew Wild <mwild1@gmail.com>
parents:
5380
diff
changeset
|
325 function env.Include(file) |
6718
be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6717
diff
changeset
|
326 -- Check whether this is a wildcard Include |
3905
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
327 if file:match("[*?]") then |
6166
46cb87d531a7
configmanager: Delay importing LuaFileSystem until needed by an Include line
Kim Alvefur <zash@zash.se>
parents:
5811
diff
changeset
|
328 local lfs = deps.softreq "lfs"; |
46cb87d531a7
configmanager: Delay importing LuaFileSystem until needed by an Include line
Kim Alvefur <zash@zash.se>
parents:
5811
diff
changeset
|
329 if not lfs then |
46cb87d531a7
configmanager: Delay importing LuaFileSystem until needed by an Include line
Kim Alvefur <zash@zash.se>
parents:
5811
diff
changeset
|
330 error(format("Error expanding wildcard pattern in Include %q - LuaFileSystem not available", file)); |
46cb87d531a7
configmanager: Delay importing LuaFileSystem until needed by an Include line
Kim Alvefur <zash@zash.se>
parents:
5811
diff
changeset
|
331 end |
3905
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
332 local path_pos, glob = file:match("()([^"..path_sep.."]+)$"); |
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
333 local path = file:sub(1, math_max(path_pos-2,0)); |
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
334 if #path > 0 then |
3929
7cb03d67101b
configmanager: Filenames without a path are also relative to the config file path, not the current working directory
Matthew Wild <mwild1@gmail.com>
parents:
3905
diff
changeset
|
335 path = resolve_relative_path(config_path, path); |
3905
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
336 else |
3929
7cb03d67101b
configmanager: Filenames without a path are also relative to the config file path, not the current working directory
Matthew Wild <mwild1@gmail.com>
parents:
3905
diff
changeset
|
337 path = config_path; |
3905
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
338 end |
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
339 local patt = glob_to_pattern(glob); |
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
340 for f in lfs.dir(path) do |
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
341 if f:sub(1,1) ~= "." and f:match(patt) then |
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
342 env.Include(path..path_sep..f); |
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
343 end |
9222dad9e1e8
configmanager: Support for wildcards in Include directives
Matthew Wild <mwild1@gmail.com>
parents:
3780
diff
changeset
|
344 end |
6718
be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6717
diff
changeset
|
345 return; |
794
912dc389935a
Add Include command to include extra configuration files from the main one
Matthew Wild <mwild1@gmail.com>
parents:
793
diff
changeset
|
346 end |
6718
be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6717
diff
changeset
|
347 -- Not a wildcard, so resolve (potentially) relative path and run through config parser |
13626
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
348 file = resolve_relative_path(config_path, file); |
6718
be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6717
diff
changeset
|
349 local f, err = io.open(file); |
be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6717
diff
changeset
|
350 if f then |
8153
c22d5680ca68
configmanager: Remove support for multiple parsers, fixes #852.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7947
diff
changeset
|
351 local ret, err = parser.load(f:read("*a"), file, config_table); |
6718
be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6717
diff
changeset
|
352 if not ret then error(err:gsub("%[string.-%]", file), 0); end |
9876
d812031c8716
configmanager: Pass through warnings from included files
Matthew Wild <mwild1@gmail.com>
parents:
9875
diff
changeset
|
353 if err then |
d812031c8716
configmanager: Pass through warnings from included files
Matthew Wild <mwild1@gmail.com>
parents:
9875
diff
changeset
|
354 for _, warning in ipairs(err) do |
d812031c8716
configmanager: Pass through warnings from included files
Matthew Wild <mwild1@gmail.com>
parents:
9875
diff
changeset
|
355 t_insert(warnings, warning); |
d812031c8716
configmanager: Pass through warnings from included files
Matthew Wild <mwild1@gmail.com>
parents:
9875
diff
changeset
|
356 end |
d812031c8716
configmanager: Pass through warnings from included files
Matthew Wild <mwild1@gmail.com>
parents:
9875
diff
changeset
|
357 end |
6718
be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6717
diff
changeset
|
358 end |
be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6717
diff
changeset
|
359 if not f then error("Error loading included "..file..": "..err, 0); end |
be98ebe87eef
configmanager: Refactor function to avoid re-declaring local variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6717
diff
changeset
|
360 return f, err; |
794
912dc389935a
Add Include command to include extra configuration files from the main one
Matthew Wild <mwild1@gmail.com>
parents:
793
diff
changeset
|
361 end |
912dc389935a
Add Include command to include extra configuration files from the main one
Matthew Wild <mwild1@gmail.com>
parents:
793
diff
changeset
|
362 env.include = env.Include; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
363 |
3610
2084959d4096
configmanager: Update Include and RunScript directives to support paths relative to the (current!) config file
Matthew Wild <mwild1@gmail.com>
parents:
3609
diff
changeset
|
364 function env.RunScript(file) |
13626
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
365 return dofile(resolve_relative_path(config_path, file)); |
3610
2084959d4096
configmanager: Update Include and RunScript directives to support paths relative to the (current!) config file
Matthew Wild <mwild1@gmail.com>
parents:
3609
diff
changeset
|
366 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
367 |
13626
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
368 env.FileContents = filereader(config_path, "*a"); |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
369 env.FileLine = filereader(config_path, "*l"); |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
370 env.FileLines = linereader(config_path); |
ac60c21015c7
core.configmanager: Add ways to read config values from files
Kim Alvefur <zash@zash.se>
parents:
13391
diff
changeset
|
371 |
13743
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
372 if credentials_directory then |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
373 env.Credential = filereader(credentials_directory, "*a"); |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
374 elseif credential_fallback_fatal then |
13628
4fdd406564ea
core.configmanager: Rename Secret to Credential
Kim Alvefur <zash@zash.se>
parents:
13627
diff
changeset
|
375 env.Credential = function() error("Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set", 2) end |
13627
2db7b3b65363
core.configmanager: Add function for getting secrets from separate files
Kim Alvefur <zash@zash.se>
parents:
13626
diff
changeset
|
376 else |
13628
4fdd406564ea
core.configmanager: Rename Secret to Credential
Kim Alvefur <zash@zash.se>
parents:
13627
diff
changeset
|
377 env.Credential = function() |
13671
0c8c1a8338d1
core.configmanager: Delay reporting warnings about Credential until use
Kim Alvefur <zash@zash.se>
parents:
13631
diff
changeset
|
378 return errors.new({ |
13745
994ea8d54b72
core.configmanager: Pass name and line number in context
Kim Alvefur <zash@zash.se>
parents:
13744
diff
changeset
|
379 type = "continue"; |
994ea8d54b72
core.configmanager: Pass name and line number in context
Kim Alvefur <zash@zash.se>
parents:
13744
diff
changeset
|
380 text = "Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set"; |
994ea8d54b72
core.configmanager: Pass name and line number in context
Kim Alvefur <zash@zash.se>
parents:
13744
diff
changeset
|
381 }, { filename = config_file; fileline = get_line_number(config_file) }); |
13627
2db7b3b65363
core.configmanager: Add function for getting secrets from separate files
Kim Alvefur <zash@zash.se>
parents:
13626
diff
changeset
|
382 end |
2db7b3b65363
core.configmanager: Add function for getting secrets from separate files
Kim Alvefur <zash@zash.se>
parents:
13626
diff
changeset
|
383 end |
2db7b3b65363
core.configmanager: Add function for getting secrets from separate files
Kim Alvefur <zash@zash.se>
parents:
13626
diff
changeset
|
384 |
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4530
diff
changeset
|
385 local chunk, err = envload(data, "@"..config_file, env); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
386 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
387 if not chunk then |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
388 return nil, err; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
390 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
391 local ok, err = pcall(chunk); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
392 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
393 if not ok then |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
394 return nil, err; |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
395 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
396 |
12440
1ef893715311
configmanager: Add method to report loaded config files (part of #1729 fix)
Matthew Wild <mwild1@gmail.com>
parents:
12083
diff
changeset
|
397 t_insert(files, config_file); |
1ef893715311
configmanager: Add method to report loaded config files (part of #1729 fix)
Matthew Wild <mwild1@gmail.com>
parents:
12083
diff
changeset
|
398 |
9874
c9f5ccdcdf80
configmanager: Add support for returning warnings
Matthew Wild <mwild1@gmail.com>
parents:
9241
diff
changeset
|
399 return true, warnings; |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
400 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5413
diff
changeset
|
401 |
371
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
402 end |
0dc5819660e8
Import initial configmanager, not sure if it works yet, but it does pass the unit tests ;)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
403 |
13743
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
404 function _M.set_credentials_directory(directory) |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
405 credentials_directory = directory; |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
406 end |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
407 |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
408 function _M.set_credential_fallback_mode(mode) |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
409 credential_fallback_fatal = mode == "error"; |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
410 end |
0c7e11c11968
core.configmanager: Remove dependency on 'prosody' global for Credential
Kim Alvefur <zash@zash.se>
parents:
13671
diff
changeset
|
411 |
466
0ecfd89c2cc0
Fix for configmanager when config file can't be found
Matthew Wild <mwild1@gmail.com>
parents:
376
diff
changeset
|
412 return _M; |