remove need for kiwi_default.yml
This commit is contained in:
parent
af02c410e5
commit
e42b426f2e
5 changed files with 32 additions and 36 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue