From e42b426f2e3e99a21fb55b67463680c880e80647 Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Tue, 12 Oct 2021 19:17:28 +0200 Subject: [PATCH] remove need for kiwi_default.yml --- example/kiwi.yml | 16 +++++++-------- kiwi_scp/_constants.py | 2 +- kiwi_scp/config.py | 32 ++++++++++++++++++------------ kiwi_scp/data/etc/kiwi_default.yml | 13 ------------ kiwi_scp/scripts/kiwi_next.py | 5 ++++- 5 files changed, 32 insertions(+), 36 deletions(-) delete mode 100644 kiwi_scp/data/etc/kiwi_default.yml diff --git a/example/kiwi.yml b/example/kiwi.yml index 1eb6293..e40d97d 100644 --- a/example/kiwi.yml +++ b/example/kiwi.yml @@ -2,17 +2,17 @@ # kiwi-scp instance configuration # ################################### -version: '0.1.7' +version: '0.2.0' -runtime: - storage: /tmp/kiwi - shells: +shells: - /bin/bash - env: null -markers: - project: .project - disabled: .disabled +projects: + - name: hello-world.project + enabled: true + +storage: + directory: /var/local/kiwi network: name: kiwi_hub diff --git a/kiwi_scp/_constants.py b/kiwi_scp/_constants.py index 62a46f9..54b9607 100644 --- a/kiwi_scp/_constants.py +++ b/kiwi_scp/_constants.py @@ -11,7 +11,7 @@ _RE_NUMBER: str = r"[0-9]|[1-9][0-9]*" RE_SEMVER = rf"^{_RE_NUMBER}(?:\.{_RE_NUMBER}(?:\.{_RE_NUMBER})?)?$" # regex for a lowercase variable name -RE_VARNAME = r"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])$" +RE_VARNAME = r"^[A-Za-z](?:[A-Za-z0-9\._-]*[A-Za-z0-9])$" ############# # ENVIRONMENT diff --git a/kiwi_scp/config.py b/kiwi_scp/config.py index 9efe0e2..792fd4c 100644 --- a/kiwi_scp/config.py +++ b/kiwi_scp/config.py @@ -49,29 +49,35 @@ class _Project(BaseModel): class _Network(BaseModel): """a network subsection""" - name: constr( - to_lower=True, - regex=RE_VARNAME - ) + name: constr(to_lower=True, regex=RE_VARNAME) cidr: IPv4Network class Config(BaseModel): """represents a kiwi.yml""" - version: constr( - regex=RE_SEMVER - ) - shells: Optional[List[str]] - environment: Optional[Dict[str, Optional[str]]] + version: constr(regex=RE_SEMVER) = "0.2.0" + + shells: Optional[List[str]] = [ + "/bin/bash", + ] + + environment: Dict[str, Optional[str]] = {} projects: Optional[List[_Project]] - storage: _Storage - network: _Network + + storage: _Storage = _Storage.parse_obj({ + "directory": "/var/local/kiwi", + }) + + network: _Network = _Network.parse_obj({ + "name": "kiwi_hub", + "cidr": "10.22.46.0/24", + }) @validator("environment", pre=True) @classmethod - def unify_environment(cls, value) -> Optional[Dict[str, Optional[str]]]: + def unify_environment(cls, value) -> Dict[str, Optional[str]]: """parse different environment notations""" def parse_str(var_val: str) -> (str, Optional[str]): @@ -87,7 +93,7 @@ class Config(BaseModel): if value is None: # empty environment - return None + return {} elif isinstance(value, dict): # native dict format diff --git a/kiwi_scp/data/etc/kiwi_default.yml b/kiwi_scp/data/etc/kiwi_default.yml deleted file mode 100644 index bb8335f..0000000 --- a/kiwi_scp/data/etc/kiwi_default.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: 0.2.0 -shells: - - /bin/bash -projects: - - name: admin - enabled: true - - Test: - - test2: false -storage: - directory: /var/local/kiwi -network: - name: kiwi_hub - cidr: 10.22.46.0/24 diff --git a/kiwi_scp/scripts/kiwi_next.py b/kiwi_scp/scripts/kiwi_next.py index 22bb8a2..3650070 100644 --- a/kiwi_scp/scripts/kiwi_next.py +++ b/kiwi_scp/scripts/kiwi_next.py @@ -3,12 +3,15 @@ import yaml def main(): - with open("./kiwi_scp/data/etc/kiwi_default.yml") as kc: + with open("./example/kiwi.yml") as kc: yml = yaml.safe_load(kc) kiwi = Config(**yml) print(repr(kiwi)) + kiwi = Config() + print(repr(kiwi)) + if __name__ == "__main__": main()