Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deployment/Dockerfile.application
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12-alpine3.21 AS startleft-base
FROM python:3.12-alpine3.22 AS startleft-base

WORKDIR /app

Expand All @@ -10,7 +10,7 @@ RUN apk -U upgrade && \
pip install --upgrade pip && pip install .


FROM python:3.12-alpine3.21
FROM python:3.12-alpine3.22

RUN apk -U upgrade && \
apk add --no-cache libmagic py3-pygraphviz py3-re2 py3-shapely && \
Expand Down
8 changes: 8 additions & 0 deletions slp_drawio/resources/schemas/drawio_schema.xsd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mxfile" type="mxfileType"/>
<xs:element name="mxGraphModel" type="mxGraphModelType"/>
<xs:complexType name="mxCellType" mixed="true">
<xs:sequence>
<xs:element type="mxGeometryType" name="mxGeometry" minOccurs="0"/>
Expand Down Expand Up @@ -80,6 +81,7 @@
<xs:element type="mxCellType" name="mxCell"/>
<xs:element type="objectType" name="object"/>
<xs:element type="objectType" name="UserObject"/>
<xs:element name="lx-settings" type="lxSettingsType"/>
</xs:choice>
</xs:complexType>
<xs:complexType name="mxGraphModelType">
Expand Down Expand Up @@ -128,4 +130,10 @@
<xs:attribute type="xs:string" name="pages"/>
<xs:anyAttribute processContents="lax"/>
</xs:complexType>
<xs:complexType name="lxSettingsType">
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
</xs:sequence>
<xs:anyAttribute processContents="lax"/>
</xs:complexType>
</xs:schema>
5 changes: 3 additions & 2 deletions slp_drawio/slp_drawio/load/drawio_dict_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __is_mx_cell_component(mx_cell: dict):


def __get_root_element(source) -> dict:
return source.get("mxfile", {}).get("diagram", {}).get("mxGraphModel", {}).get("root", {})
return source.get("mxfile", {}).get("diagram", {}).get("mxGraphModel",
source.get("mxGraphModel", {})).get("root", {})


def __process_object_elements(root: dict, element_keys: list[str]) -> list[dict]:
Expand Down Expand Up @@ -82,7 +83,7 @@ def get_dataflow_tags(dataflow_id: str, source) -> list[str]:


def get_diagram_size(source) -> Optional[dict]:
model = source.get("mxfile", {}).get("diagram", {}).get("mxGraphModel", {})
model = source.get("mxfile", {}).get("diagram", {}).get("mxGraphModel", source.get("mxGraphModel", {}))
if model:
height = model.get('pageHeight', None)
width = model.get('pageWidth', None)
Expand Down
4 changes: 2 additions & 2 deletions slp_drawio/slp_drawio/load/drawio_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def __is_diagram_encoded(diagram_tags: List) -> bool:
return len(diagram_tags) <= 1


def _decode_diagram(content: str) -> str:
def _decode_diagram(content: str) -> str | None:
tree = ElementTree.XML(content)
tree_tag = tree.find('diagram')
tree_tag = tree if tree.tag == 'mxGraphModel' else tree.find('diagram')
if __is_diagram_encoded(list(tree_tag.iter())):
data = base64.b64decode(tree_tag.text, validate=True)
xml = zlib.decompress(data, wbits=-15).decode()
Expand Down
23 changes: 23 additions & 0 deletions slp_drawio/tests/resources/drawio/lean_ix.drawio.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<mxGraphModel dx="1421" dy="904" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<lx-settings id="0">
<lx-fact-sheet-type-labels fact-sheet-type="BusinessCapability">
<lx-label value="fullName" />
</lx-fact-sheet-type-labels>
</lx-settings>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="5i7VU8sxTlh_DojUgWXD-1" value="AWS Cloud" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_aws_cloud_alt;strokeColor=#232F3E;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#232F3E;dashed=0;" parent="1" vertex="1">
<mxGeometry x="210" y="230" width="130" height="130" as="geometry" />
</mxCell>
<mxCell id="xUHJV5QXkyTOu5aMK-rF-2" value="" style="image;html=1;image=img/lib/clip_art/computers/Database_128x128.png" parent="5i7VU8sxTlh_DojUgWXD-1" vertex="1">
<mxGeometry x="25" y="40" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="5i7VU8sxTlh_DojUgWXD-2" value="Region" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_region;strokeColor=#147EBA;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#147EBA;dashed=1;" parent="1" vertex="1">
<mxGeometry x="440" y="230" width="130" height="130" as="geometry" />
</mxCell>
<mxCell id="xUHJV5QXkyTOu5aMK-rF-3" value="" style="outlineConnect=0;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;shape=mxgraph.aws3.ec2;fillColor=#F58534;gradientColor=none;" parent="5i7VU8sxTlh_DojUgWXD-2" vertex="1">
<mxGeometry x="26.75" y="27" width="76.5" height="93" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
1 change: 1 addition & 0 deletions slp_drawio/tests/resources/test_resource_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
wrong_mxgraphmodel_drawio = f'{drawio}/wrong_mxgraphmodel.drawio'
wrong_root_drawio = f'{drawio}/wrong_root.drawio'
not_xml = f'{drawio}/not_xml.drawio'
lean_ix_drawio = f'{drawio}/lean_ix.drawio.xml'
4 changes: 4 additions & 0 deletions slp_drawio/tests/unit/load/test_drawio_dict_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def test_is_multiple_pages(source, expected):
pytest.param({'mxfile': {'diagram': {'mxGraphModel': {'pageHeight': 123, 'pageWidth': 456}}}},
{'height': 123, 'width': 456},
id='exists size'),
pytest.param({'mxGraphModel': {'pageHeight': 123, 'pageWidth': 456}},
{'height': 123, 'width': 456},
id='exists size only mxGraphModel'),
pytest.param({'mxfile': {'diagram': {'mxGraphModel': {}}}}, None, id='not dimensions'),
pytest.param({'mxGraphModel': {}}, None, id='not dimensions only mxGraphModel'),
pytest.param({}, None, id='not model')
])
def test_get_diagram_size(source, expected):
Expand Down
13 changes: 7 additions & 6 deletions slp_drawio/tests/validate/test_drawio_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from slp_base import DiagramFileNotValidError, CommonError
from slp_drawio.slp_drawio.validate.drawio_validator import DrawioValidator
from slp_drawio.tests.resources.test_resource_paths import wrong_mxgraphmodel_drawio, wrong_mxfile_drawio, \
wrong_mxcell_drawio, wrong_root_drawio, aws_minimal_drawio, aws_minimal_xml, not_xml
wrong_mxcell_drawio, wrong_root_drawio, aws_minimal_drawio, aws_minimal_xml, not_xml, lean_ix_drawio

filename_pattern = re.compile('^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}\\.[drawio|xml]')

Expand Down Expand Up @@ -79,12 +79,13 @@ def test_invalid_schema(self, filepath: str):
assert error_info.typename == 'DiagramFileNotValidError'
assert error_info.value.message == 'Provided diag_file is not valid. It does not comply with schema'

@pytest.mark.parametrize('mime, size, filepath', [
pytest.param('application/octet-stream', 10, aws_minimal_drawio, id='encoded-tiny-binary'),
pytest.param('application/xml', 10 * 1024 * 1024, aws_minimal_xml, id='xml-big-xml'),
pytest.param('text/plain', 10 * 1024 * 1024, aws_minimal_drawio, id='encoded-big-text')
@pytest.mark.parametrize('mime, filepath', [
pytest.param('application/octet-stream', aws_minimal_drawio, id='encoded-tiny-binary'),
pytest.param('application/xml', aws_minimal_xml, id='xml-big-xml'),
pytest.param('text/plain', aws_minimal_drawio, id='encoded-big-text'),
pytest.param('application/xml', lean_ix_drawio, id='lean-ix-drawio-xml')
])
def test_valid_file(self, mime: str, size: int, filepath: str):
def test_valid_file(self, mime: str, filepath: str):
# GIVEN the valid file
file = get_byte_data(filepath)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json

import pytest
import responses
from fastapi.testclient import TestClient
from tests.resources import test_resource_paths

from sl_util.sl_util.file_utils import get_byte_data
from startleft.startleft.api import fastapi_server
from startleft.startleft.api.controllers.diagram import diag_create_otm_controller
from tests.resources import test_resource_paths

webapp = fastapi_server.webapp

Expand Down Expand Up @@ -47,4 +48,33 @@ def test_create_otm_multi_page_error(self):
assert body_response['title'] == 'Diagram file is not valid'
assert body_response['detail'] == 'DrawIO processor does not accept diagrams with multiple pages'
assert len(body_response['errors']) == 1
assert body_response['errors'][0]['errorMessage'] == 'Diagram File is not compatible'
assert body_response['errors'][0]['errorMessage'] == 'Diagram File is not compatible'

@pytest.mark.parametrize('diagram_file_path', [
test_resource_paths.drawio_minimal,
test_resource_paths.lean_ix_drawio
])
@responses.activate
def test_create_otm_ok(self, diagram_file_path):
# Given a project_id
project_id: str = 'test_ok'
project_name: str = 'test_ok_name'

# And the source file
diag_file = get_byte_data(diagram_file_path)

# And the mapping file
mapping_file = get_byte_data(test_resource_paths.default_drawio_mapping)

# When I do post on diagram endpoint
files = {'diag_file': (diagram_file_path, diag_file),
'default_mapping_file': ('default_mapping_file.yaml', mapping_file)}
body = {'diag_type': 'DRAWIO', 'id': project_id, 'name': project_name}
response = client.post(get_url(), files=files, data=body)

# Then
assert response.status_code == 201
assert response.headers.get('content-type') == json_mime
otm = json.loads(response.text)
assert len(otm['trustZones']) > 0
assert len(otm['components']) > 0
23 changes: 23 additions & 0 deletions tests/resources/drawio/aws_minimal.drawio.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<mxfile host="Electron" modified="2023-10-10T12:38:11.657Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/19.0.3 Chrome/102.0.5005.63 Electron/19.0.3 Safari/537.36" etag="IaZ6VWqQhPlsWStpV9DA" version="19.0.3" type="device">
<diagram id="pOeIjdqQ_qid1hbLa7JX" name="Page-1">
<mxGraphModel dx="1421" dy="904" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="5i7VU8sxTlh_DojUgWXD-1" value="AWS Cloud" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_aws_cloud_alt;strokeColor=#232F3E;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#232F3E;dashed=0;" parent="1" vertex="1">
<mxGeometry x="210" y="230" width="130" height="130" as="geometry" />
</mxCell>
<mxCell id="xUHJV5QXkyTOu5aMK-rF-2" value="" style="image;html=1;image=img/lib/clip_art/computers/Database_128x128.png" parent="5i7VU8sxTlh_DojUgWXD-1" vertex="1">
<mxGeometry x="25" y="40" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="5i7VU8sxTlh_DojUgWXD-2" value="Region" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_region;strokeColor=#147EBA;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#147EBA;dashed=1;" parent="1" vertex="1">
<mxGeometry x="440" y="230" width="130" height="130" as="geometry" />
</mxCell>
<mxCell id="xUHJV5QXkyTOu5aMK-rF-3" value="" style="outlineConnect=0;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;shape=mxgraph.aws3.ec2;fillColor=#F58534;gradientColor=none;" parent="5i7VU8sxTlh_DojUgWXD-2" vertex="1">
<mxGeometry x="26.75" y="27" width="76.5" height="93" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
23 changes: 23 additions & 0 deletions tests/resources/drawio/lean_ix.drawio.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<mxGraphModel dx="1421" dy="904" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<lx-settings id="0">
<lx-fact-sheet-type-labels fact-sheet-type="BusinessCapability">
<lx-label value="fullName" />
</lx-fact-sheet-type-labels>
</lx-settings>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="5i7VU8sxTlh_DojUgWXD-1" value="AWS Cloud" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_aws_cloud_alt;strokeColor=#232F3E;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#232F3E;dashed=0;" parent="1" vertex="1">
<mxGeometry x="210" y="230" width="130" height="130" as="geometry" />
</mxCell>
<mxCell id="xUHJV5QXkyTOu5aMK-rF-2" value="" style="image;html=1;image=img/lib/clip_art/computers/Database_128x128.png" parent="5i7VU8sxTlh_DojUgWXD-1" vertex="1">
<mxGeometry x="25" y="40" width="80" height="80" as="geometry" />
</mxCell>
<mxCell id="5i7VU8sxTlh_DojUgWXD-2" value="Region" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_region;strokeColor=#147EBA;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#147EBA;dashed=1;" parent="1" vertex="1">
<mxGeometry x="440" y="230" width="130" height="130" as="geometry" />
</mxCell>
<mxCell id="xUHJV5QXkyTOu5aMK-rF-3" value="" style="outlineConnect=0;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;shape=mxgraph.aws3.ec2;fillColor=#F58534;gradientColor=none;" parent="5i7VU8sxTlh_DojUgWXD-2" vertex="1">
<mxGeometry x="26.75" y="27" width="76.5" height="93" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
2 changes: 2 additions & 0 deletions tests/resources/test_resource_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@
# DRAWIO
drawio_multi_page = f'{path}/drawio/drawio-multi-page.drawio'
default_drawio_mapping = f'{path}/drawio/drawio_mapping.yaml'
drawio_minimal = f'{path}/drawio/aws_minimal.drawio.xml'
lean_ix_drawio = f'{path}/drawio/lean_ix.drawio.xml'