a gazillion things to implement cosmos db healthcheck

This commit is contained in:
Pablo Martin 2024-08-09 12:41:23 +02:00
parent 7af3b12c81
commit 91c79357f8
11 changed files with 421 additions and 15 deletions

40
anaxi/config.py Normal file
View file

@ -0,0 +1,40 @@
import logging
import pathlib
from typing import Dict
from anaxi.file_persistence import read_yaml
logger = logging.getLogger()
class CosmosDBDatabaseConfig:
config_root_key: str = "cosmos-databases"
def __init__(self, host: str, database_id: str, master_key: str) -> None:
self.host = host
self.database_id = database_id
self.master_key = master_key
@classmethod
def from_dict(cls, a_dict) -> "CosmosDBDatabaseConfig":
return CosmosDBDatabaseConfig(**a_dict)
@classmethod
def from_yaml(cls, path: pathlib.Path) -> Dict[str, "CosmosDBDatabaseConfig"]:
yaml_contents = read_yaml(path)
cosmos_db_contents = yaml_contents[CosmosDBDatabaseConfig.config_root_key]
try:
database_configs = {
db_id: CosmosDBDatabaseConfig.from_dict(db_config)
for db_id, db_config in cosmos_db_contents.items()
}
except KeyError as e:
logger.error(
"Error reading Cosmos DB config yaml file. The file seems malformed. Review the example in the repository."
)
raise e
return database_configs