1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-12-24 10:13: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
RESERVED_PROJECT_NAMES = [
'config'
]
#############
# REGEX PARTS

View file

@ -5,7 +5,7 @@ import click
from .cmd import KiwiCommandType, KiwiCommand
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 ..instance import Instance
from ..project import Project
@ -23,6 +23,10 @@ class NewCommand(KiwiCommand):
@classmethod
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:
os.mkdir(project_name)
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 ._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
@ -53,6 +53,16 @@ class ProjectConfig(BaseModel):
result["override_storage"] = self.override_storage.kiwi_dict
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)
@classmethod
def unify_storage(cls, value) -> Dict[str, Any]: