1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-22 04:43:00 +00:00

RESERVED_PROJECT_NAMES

This commit is contained in:
Jörn-Michael Miehe 2022-01-24 16:53:19 +01:00
parent eb50abcf7d
commit 29bc413f8e
3 changed files with 20 additions and 2 deletions

View file

@ -1,5 +1,9 @@
import os import os
RESERVED_PROJECT_NAMES = [
'config'
]
############# #############
# REGEX PARTS # REGEX PARTS

View file

@ -5,7 +5,7 @@ import click
from .cmd import KiwiCommandType, KiwiCommand from .cmd import KiwiCommandType, KiwiCommand
from .decorators import kiwi_command from .decorators import kiwi_command
from .._constants import DEFAULT_DOCKER_COMPOSE_NAME, COMPOSE_FILE_NAME from .._constants import DEFAULT_DOCKER_COMPOSE_NAME, COMPOSE_FILE_NAME, RESERVED_PROJECT_NAMES
from ..config import ProjectConfig from ..config import ProjectConfig
from ..instance import Instance from ..instance import Instance
from ..project import Project from ..project import Project
@ -23,6 +23,10 @@ class NewCommand(KiwiCommand):
@classmethod @classmethod
def run_for_new_project(cls, instance: Instance, project_name: str, **kwargs) -> None: def run_for_new_project(cls, instance: Instance, project_name: str, **kwargs) -> None:
if project_name in RESERVED_PROJECT_NAMES:
KiwiCommand.print_error(f"Project name '{project_name}' is reserved!")
return
try: try:
os.mkdir(project_name) os.mkdir(project_name)
instance.config.projects.append(ProjectConfig( instance.config.projects.append(ProjectConfig(

View file

@ -5,7 +5,7 @@ from typing import Optional, Dict, List, Any, TextIO, Tuple
from pydantic import BaseModel, constr, root_validator, validator from pydantic import BaseModel, constr, root_validator, validator
from ._constants import RE_SEMVER, RE_VARNAME, KIWI_CONF_NAME from ._constants import RE_SEMVER, RE_VARNAME, KIWI_CONF_NAME, RESERVED_PROJECT_NAMES
from .yaml import YAML from .yaml import YAML
@ -53,6 +53,16 @@ class ProjectConfig(BaseModel):
result["override_storage"] = self.override_storage.kiwi_dict result["override_storage"] = self.override_storage.kiwi_dict
return result return result
@validator("name")
@classmethod
def check_project(cls, value: str) -> str:
"""check if project name is allowed"""
if value in RESERVED_PROJECT_NAMES:
raise ValueError(f"Project name '{value}' is reserved!")
return value
@validator("override_storage", pre=True) @validator("override_storage", pre=True)
@classmethod @classmethod
def unify_storage(cls, value) -> Dict[str, Any]: def unify_storage(cls, value) -> Dict[str, Any]: