-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add YAML config schema and validation
Signed-off-by: Tobias Wolf <[email protected]>
- Loading branch information
1 parent
f267d13
commit 27aa23a
Showing
6 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,6 @@ rsa==4.9 | |
six==1.16.0 | ||
structlog==24.1.0 | ||
urllib3==2.2.1 | ||
yamale==5.1.0 | ||
websocket-client==1.7.0 | ||
wrapt==1.16.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
general: | ||
module_data_file: str() | ||
|
||
ceph: | ||
conf_file: str() | ||
keyring: str() | ||
|
||
ssh: | ||
private_key: str() | ||
hosts: map(include("ssh_host"), key=str(), min=1) | ||
|
||
kubernetes: | ||
config: str() | ||
|
||
rook: | ||
cluster: | ||
name: str() | ||
namespace: str() | ||
ceph: | ||
image: str() | ||
|
||
migration_modules: list(str()) | ||
--- | ||
ssh_host: | ||
address: ip() | ||
user: str() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import importlib.resources | ||
import importlib.resources.abc | ||
import yamale | ||
import yaml | ||
from pathlib import Path | ||
from typing import Any, Dict | ||
|
||
|
||
def load_yaml(path: str) -> Dict[str, Any]: | ||
_config_schema_file: Path | importlib.resources.abc.Traversable = Path( | ||
"rookify", "config.schema.yaml" | ||
) | ||
for entry in importlib.resources.files("rookify").iterdir(): | ||
if entry.name == "config.schema.yaml": | ||
_config_schema_file = entry | ||
|
||
|
||
def load_config(path: str) -> Dict[str, Any]: | ||
schema = yamale.make_schema(_config_schema_file) | ||
data = yamale.make_data(path) | ||
|
||
yamale.validate(schema, data) | ||
|
||
assert isinstance(data[0][0], dict) | ||
return data[0][0] | ||
|
||
|
||
def load_module_data(path: str) -> Dict[str, Any]: | ||
with open(path, "r") as file: | ||
data = yaml.safe_load(file) | ||
assert isinstance(data, dict) | ||
return data | ||
|
||
|
||
def save_yaml(path: str, data: Dict[str, Any]) -> None: | ||
def save_module_data(path: str, data: Dict[str, Any]) -> None: | ||
with open(path, "w") as file: | ||
yaml.safe_dump(data, file) |