2023-02-17 06:02:21 +00:00
|
|
|
from core.config import CoreConfig
|
|
|
|
from typing import Dict
|
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
|
|
|
|
class ChuniServerConfig:
|
2023-02-17 06:02:21 +00:00
|
|
|
def __init__(self, parent_config: "ChuniConfig") -> None:
|
|
|
|
self.__config = parent_config
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2023-02-17 06:02:21 +00:00
|
|
|
@property
|
|
|
|
def enable(self) -> bool:
|
2023-03-09 16:38:58 +00:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "chuni", "server", "enable", default=True
|
|
|
|
)
|
|
|
|
|
2023-02-17 06:02:21 +00:00
|
|
|
@property
|
|
|
|
def loglevel(self) -> int:
|
2023-03-09 16:38:58 +00:00
|
|
|
return CoreConfig.str_to_loglevel(
|
|
|
|
CoreConfig.get_config_field(
|
|
|
|
self.__config, "chuni", "server", "loglevel", default="info"
|
|
|
|
)
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
|
2023-03-09 16:38:58 +00:00
|
|
|
|
|
|
|
class ChuniCryptoConfig:
|
2023-02-17 06:02:21 +00:00
|
|
|
def __init__(self, parent_config: "ChuniConfig") -> None:
|
|
|
|
self.__config = parent_config
|
2023-03-09 16:38:58 +00:00
|
|
|
|
2023-02-17 06:02:21 +00:00
|
|
|
@property
|
|
|
|
def keys(self) -> Dict:
|
|
|
|
"""
|
|
|
|
in the form of:
|
2023-03-09 16:38:58 +00:00
|
|
|
internal_version: [key, iv]
|
2023-02-17 06:02:21 +00:00
|
|
|
all values are hex strings
|
|
|
|
"""
|
2023-03-09 16:38:58 +00:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "chuni", "crypto", "keys", default={}
|
|
|
|
)
|
2023-02-17 06:02:21 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def encrypted_only(self) -> bool:
|
2023-03-09 16:38:58 +00:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "chuni", "crypto", "encrypted_only", default=False
|
|
|
|
)
|
|
|
|
|
2023-02-17 06:02:21 +00:00
|
|
|
|
|
|
|
class ChuniConfig(dict):
|
|
|
|
def __init__(self) -> None:
|
|
|
|
self.server = ChuniServerConfig(self)
|
2023-03-09 16:38:58 +00:00
|
|
|
self.crypto = ChuniCryptoConfig(self)
|