Fix config option to disable built-in templates.

This commit is contained in:
grossmj 2022-06-21 17:17:44 +02:00
parent d8b928f1c1
commit 410f062721
3 changed files with 18 additions and 2 deletions

View File

@ -138,6 +138,7 @@ class ServerSettings(BaseModel):
allowed_interfaces: List[str] = Field(default_factory=list)
default_nat_interface: str = None
allow_remote_console: bool = False
enable_builtin_templates: bool = True
@validator("additional_images_paths", pre=True)
def split_additional_images_paths(cls, v):

View File

@ -23,6 +23,7 @@ from fastapi.encoders import jsonable_encoder
from typing import List
from gns3server import schemas
from gns3server.config import Config
import gns3server.db.models as models
from gns3server.db.repositories.templates import TemplatesRepository
from gns3server.controller.controller_error import (
@ -174,8 +175,9 @@ class TemplatesService:
db_templates = await self._templates_repo.get_templates()
for db_template in db_templates:
templates.append(db_template.asjson())
for builtin_template in BUILTIN_TEMPLATES:
templates.append(jsonable_encoder(builtin_template))
if Config.instance().settings.Server.enable_builtin_templates:
for builtin_template in BUILTIN_TEMPLATES:
templates.append(jsonable_encoder(builtin_template))
return templates
async def _find_image(self, image_path: str):

View File

@ -28,6 +28,7 @@ from tests.utils import asyncio_patch
from gns3server.db.repositories.images import ImagesRepository
from gns3server.db.repositories.templates import TemplatesRepository
from gns3server.controller import Controller
from gns3server.controller import Config
from gns3server.services.templates import BUILTIN_TEMPLATES
pytestmark = pytest.mark.asyncio
@ -257,6 +258,18 @@ class TestBuiltinTemplates:
response = await client.delete(app.url_path_for("delete_template", template_id=template_id))
assert response.status_code == status.HTTP_403_FORBIDDEN
async def test_list_builtin_templates_not_enabled(
self,
app: FastAPI,
client: AsyncClient,
controller: Controller
) -> None:
config = Config.instance()
config.settings.Server.enable_builtin_templates = False
response = await client.get(app.url_path_for("get_templates"))
assert not response.json()
class TestDynamipsTemplate: