|
22 | 22 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
23 | 23 |
|
24 | 24 | import errno
|
25 |
| -import json |
| 25 | +import tomllib |
26 | 26 | import logging
|
27 | 27 | import os
|
28 | 28 | import sys
|
@@ -81,7 +81,7 @@ class AsyncConfig:
|
81 | 81 | class Config:
|
82 | 82 | """This class will contain the configuration for CMS. This needs
|
83 | 83 | to be populated at the initilization stage. This is loaded by
|
84 |
| - default with some sane data. See cms.conf.sample in the config |
| 84 | + default with some sane data. See cms.sample.toml in the config |
85 | 85 | directory for information on the meaning of the fields.
|
86 | 86 |
|
87 | 87 | """
|
@@ -166,13 +166,21 @@ def __init__(self):
|
166 | 166 | self.max_jobs_per_user = 10
|
167 | 167 | self.pdf_printing_allowed = False
|
168 | 168 |
|
| 169 | + # PrometheusExporter |
| 170 | + self.prometheus_listen_address = "127.0.0.1" |
| 171 | + self.prometheus_listen_port = 8811 |
| 172 | + |
| 173 | + # TelegramBot |
| 174 | + self.telegram_bot_token = None |
| 175 | + self.telegram_bot_chat_id = None |
| 176 | + |
169 | 177 | self.log_dir = os.path.join("/", "var", "local", "log", "cms")
|
170 | 178 | self.cache_dir = os.path.join("/", "var", "local", "cache", "cms")
|
171 | 179 | self.data_dir = os.path.join("/", "var", "local", "lib", "cms")
|
172 | 180 | self.run_dir = os.path.join("/", "var", "local", "run", "cms")
|
173 | 181 | paths = [
|
174 |
| - os.path.join("/", "usr", "local", "etc", "cms.conf"), |
175 |
| - os.path.join("/", "etc", "cms.conf"), |
| 182 | + os.path.join("/", "usr", "local", "etc", "cms.toml"), |
| 183 | + os.path.join("/", "etc", "cms.toml"), |
176 | 184 | ]
|
177 | 185 |
|
178 | 186 | # Allow user to override config file path using environment
|
@@ -202,23 +210,21 @@ def _load(self, paths: list[str]):
|
202 | 210 |
|
203 | 211 | def _load_unique(self, path: str):
|
204 | 212 | """Populate the Config class with everything that sits inside
|
205 |
| - the JSON file path (usually something like /etc/cms.conf). The |
| 213 | + the TOML file path (usually something like /etc/cms.toml). The |
206 | 214 | only pieces of data treated differently are the elements of
|
207 | 215 | core_services and other_services that are sent to async
|
208 | 216 | config.
|
209 | 217 |
|
210 |
| - Services whose name begins with an underscore are ignored, so |
211 |
| - they can be commented out in the configuration file. |
212 |
| -
|
213 |
| - path: the path of the JSON config file. |
| 218 | + path: the path of the TOML config file. |
214 | 219 |
|
215 | 220 | """
|
216 | 221 | # Load config file.
|
217 | 222 | try:
|
218 |
| - with open(path, 'rt', encoding='utf-8') as f: |
219 |
| - data = json.load(f) |
| 223 | + with open(path, 'rb') as f: |
| 224 | + data = tomllib.load(f) |
220 | 225 | except FileNotFoundError:
|
221 |
| - logger.debug("Couldn't find config file %s.", path) |
| 226 | + logger.debug("Couldn't find config file %s (maybe you need to " |
| 227 | + "convert it from cms.conf to cms.toml?).", path) |
222 | 228 | return False
|
223 | 229 | except OSError as error:
|
224 | 230 | logger.warning("I/O error while opening file %s: [%s] %s",
|
@@ -257,6 +263,8 @@ def _load_unique(self, path: str):
|
257 | 263 |
|
258 | 264 | # Put everything else in self.
|
259 | 265 | for key, value in data.items():
|
| 266 | + if not hasattr(self, key): |
| 267 | + logger.warning("Unrecognized key %s in config!", key) |
260 | 268 | setattr(self, key, value)
|
261 | 269 |
|
262 | 270 | return True
|
|
0 commit comments