inwx/source/conf.py

127 lines
2.2 KiB
Python
Raw Normal View History

2024-05-31 11:24:53 +02:00
_conf_data = None
def conf_schema(
):
return {
"type": "object",
"properties": {
"url": {
"type": "object",
"properties": {
},
"additionalProperties": {
"type": "object",
"properties": {
"scheme": {
"type": "string",
},
"host": {
"type": "string",
},
"port": {
"type": "number",
},
"path": {
"type": "string",
},
},
"additionalProperties": False,
"required": [
"host",
]
},
"required": [
]
},
"environment": {
"type": "string",
},
"account": {
"type": "object",
"properties": {
"username": {
"type": "string",
},
"password": {
"type": "string",
},
},
"additionalProperties": False,
"required": [
]
}
},
2024-05-31 11:24:53 +02:00
"additionalProperties": False,
"required": [
],
}
2024-05-31 11:24:53 +02:00
def conf_load(
path : str
):
global _conf_data
2024-06-01 13:26:08 +02:00
conf_data_raw = (
_json.loads(file_read(path))
if _os.path.exists(path) else
{}
)
for pair in conf_data_raw.get("url", {}).items():
if ("host" in pair[1]):
pass
else:
raise ValueError("flawed conf: missing mandatory value 'host' for url entry '%s'" % pair[0])
_conf_data = {
"url": convey(
(
{
"test": {
"scheme": "https",
"host": "api.ote.domrobot.com",
"port": 443,
"path": "jsonrpc/"
},
"production": {
"scheme": "https",
"host": "api.domrobot.com",
"port": 443,
"path": "jsonrpc/"
2024-05-31 11:24:53 +02:00
}
2024-06-01 13:26:08 +02:00
}
|
conf_data_raw.get("url", {})
2024-05-31 11:24:53 +02:00
),
2024-06-01 13:26:08 +02:00
[
lambda x: x.items(),
lambda pairs: map(
lambda pair: (
pair[0],
{
"scheme": pair[1].get("scheme", "https"),
"host": pair[1]["host"],
"port": pair[1].get("port", 443),
"path": pair[1].get("path", "jsonrpc/"),
}
),
pairs
),
dict,
]
),
"environment": conf_data_raw.get("environment", "production"),
"account": {
"username": conf_data_raw.get("account", {}).get("username", None),
"password": conf_data_raw.get("account", {}).get("password", None),
2024-05-31 11:24:53 +02:00
}
2024-06-01 13:26:08 +02:00
}
2024-06-01 13:32:46 +02:00
# print(_json.dumps(_conf_data, indent = "\t"))
def conf_get(
path : str
):
global _conf_data
return path_read(_conf_data, path.split("."))