From 0b759af5b31a37f160470588001575c8248923ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20B=C3=BCchse?= Date: Fri, 6 Sep 2024 15:13:01 +0200 Subject: [PATCH] Reduce inter-template redundancy (#739) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Reduce inter-template redundancy * fix wrong br tag * Add some styling, as well as AOV --------- Signed-off-by: Matthias Büchse --- compliance-monitor/monitor.py | 6 ++- compliance-monitor/templates/details.html.j2 | 34 -------------- compliance-monitor/templates/details.md.j2 | 23 ++++++---- compliance-monitor/templates/overview.html.j2 | 6 +++ compliance-monitor/templates/overview.md.j2 | 25 +++++----- .../templates/overview_fragment.html.j2 | 46 ------------------- 6 files changed, 37 insertions(+), 103 deletions(-) delete mode 100644 compliance-monitor/templates/details.html.j2 delete mode 100644 compliance-monitor/templates/overview_fragment.html.j2 diff --git a/compliance-monitor/monitor.py b/compliance-monitor/monitor.py index 503299a42..e18acc97f 100755 --- a/compliance-monitor/monitor.py +++ b/compliance-monitor/monitor.py @@ -88,12 +88,12 @@ class ViewType(Enum): VIEW_DETAIL = { ViewType.markdown: 'details.md', - ViewType.fragment: 'details.html', + ViewType.fragment: 'details.md', ViewType.page: 'overview.html', } VIEW_TABLE = { ViewType.markdown: 'overview.md', - ViewType.fragment: 'overview_fragment.html', + ViewType.fragment: 'overview.md', ViewType.page: 'overview.html', } REQUIRED_TEMPLATES = tuple(set(fn for view in (VIEW_DETAIL, VIEW_TABLE) for fn in view.values())) @@ -548,6 +548,8 @@ def render_view(view, view_type, results, base_url='/', title=None): def detail_url(subject, scope): return f"{base_url}page/detail/{subject}/{scope}" # noqa: E306,E704 def report_url(report): return f"{base_url}reports/{report}" # noqa: E306,E704 fragment = templates_map[stage1].render(results=results, detail_url=detail_url, report_url=report_url) + if view_type != ViewType.markdown and stage1.endswith('.md'): + fragment = markdown(fragment, extensions=['extra']) if stage1 != stage2: fragment = templates_map[stage2].render(fragment=fragment, title=title) return Response(content=fragment, media_type=media_type) diff --git a/compliance-monitor/templates/details.html.j2 b/compliance-monitor/templates/details.html.j2 deleted file mode 100644 index f4b7f6290..000000000 --- a/compliance-monitor/templates/details.html.j2 +++ /dev/null @@ -1,34 +0,0 @@ - -{% for subject, subject_result in results.items() -%} -

{{ subject }}

- -{% for scopeuuid, scope_result in subject_result.items() -%} - -{% if not scope_result.relevant -%} -

{{ scope_result.name }}

-

No recent test results available.

-{% endif -%} -{% for version in scope_result.relevant -%} -{% set version_result = scope_result.versions[version] -%} -

{{ scope_result.name }} {{ version }} ({{ version_result.validity }}): {{ version_result.result | verdict }}

- -{% for target, target_result in version_result.targets.items() -%} -

Target {{ target }}: {{ target_result.result | verdict }}

- - - -{% for testcase_id in target_result.testcases -%} -{% set testcase = version_result.testcases[testcase_id] -%} -{% set res = version_result.results[testcase_id] if testcase_id in version_result.results else dict(result=0) -%} - -{% endfor -%} -
testcase idresultdescription
{% if res.result != 1 %}⚠️ {% endif %}{{ testcase.id }}{% if res.report %}{% endif -%} -{{ res.result | verdict_check }} -{%- if res.report %}{% endif -%} -{{ testcase.description | trim | markdown }}
-{% endfor -%} -{% endfor -%} -{% endfor -%} -{% endfor -%} diff --git a/compliance-monitor/templates/details.md.j2 b/compliance-monitor/templates/details.md.j2 index f2e88cebf..d84ebc012 100644 --- a/compliance-monitor/templates/details.md.j2 +++ b/compliance-monitor/templates/details.md.j2 @@ -1,29 +1,32 @@ {% for subject, subject_result in results.items() -%} # {{ subject }} - {% for scopeuuid, scope_result in subject_result.items() -%} - {% if not scope_result.relevant -%} ## {{ scope_result.name }} + No recent test results available. + {% endif -%} {% for version in scope_result.relevant -%} -{% set version_result = scope_result.versions[version] -%} +{%- set version_result = scope_result.versions[version] -%} ## {{ scope_result.name }} {{ version }} ({{ version_result.validity }}): {{ version_result.result | verdict }} - {% for target, target_result in version_result.targets.items() -%} ### Target {{ target }}: {{ target_result.result | verdict }} -|---|---|---| | testcase id | result | description | |---|---|---| {% for testcase_id in target_result.testcases -%} {% set testcase = version_result.testcases[testcase_id] -%} -{% set result = version_result.results[testcase_id].result if testcase_id in version_result.results else 0 -%} -| {{ testcase.id }} | {{ result | verdict }} | {{ testcase.description | trim }} | -{% endfor -%} -|---|---|---| - +{% set res = version_result.results[testcase_id] if testcase_id in version_result.results else dict(result=0) -%} +| {% if res.result != 1 %}⚠️ {% endif %}{{ testcase.id }} | +{#- #} {% if res.report -%} +[{{ res.result | verdict_check }}]({{ report_url(res.report) }}) +{%- else -%} +{{ res.result | verdict_check }} +{%- endif -%} +{% if res.report %} { title="{{ res.report }} ({{ res.checked_at }})" }{% endif %} {# -#} +| {{ testcase.description | trim }} | +{% endfor %} {% endfor -%} {% endfor -%} {% endfor -%} diff --git a/compliance-monitor/templates/overview.html.j2 b/compliance-monitor/templates/overview.html.j2 index b47b643a7..7562ce368 100644 --- a/compliance-monitor/templates/overview.html.j2 +++ b/compliance-monitor/templates/overview.html.j2 @@ -1,5 +1,11 @@ + {{ title or 'SCS compliance overview' }} diff --git a/compliance-monitor/templates/overview.md.j2 b/compliance-monitor/templates/overview.md.j2 index 9e5c57351..8da599af1 100644 --- a/compliance-monitor/templates/overview.md.j2 +++ b/compliance-monitor/templates/overview.md.j2 @@ -4,22 +4,25 @@ for the time being to have the highest degree of control -#} {% set iaas = '50393e6f-2ae1-4c5c-a62c-3b75f2abef3f' -%} | Name | Description | Operator | SCS-compatible IaaS | HealthMon | -| ----- | ------------ | --------- | :------------------: | :--------: | +|-------|--------------|-----------|----------------------|:----------:| | [gx-scs](https://github.com/SovereignCloudStack/docs/blob/main/community/cloud-resources/plusserver-gx-scs.md) | Dev environment provided for SCS & GAIA-X context | plusserver GmbH | {#- #} [{{ results | passed('gx-scs', iaas) or '–' }}]({{ detail_url('gx-scs', iaas) }}) {# -#} | [HM](https://health.gx-scs.sovereignit.cloud:3000/) | +| [aov.cloud](https://www.aov.de/) | Community cloud for customers | aov IT.Services GmbH | +{#- #} [{{ results | passed('aov', iaas) or '–' }}]({{ detail_url('aov', iaas) }}) {# -#} +| [HM](https://health.aov.cloud/) | | [CNDS](https://cnds.io/) | Public cloud for customers | artcodix GmbH | {#- #} [{{ results | passed('artcodix', iaas) or '–' }}]({{ detail_url('artcodix', iaas) }}) {# -#} | [HM](https://ohm.muc.cloud.cnds.io/) | -| [pluscloud open](https://www.plusserver.com/en/products/pluscloud-open)
- prod1
- prod2
- prod3
- prod4 | Public cloud for customers (4 regions) | plusserver GmbH |  
|  
-{#- #}[{{ results | passed('pco-prod1', iaas) or '–' }}]({{ detail_url('pco-prod1', iaas) }}){# -#} +| [pluscloud open](https://www.plusserver.com/en/products/pluscloud-open)
(4 regions) | Public cloud for customers | plusserver GmbH | {# #} +{#- #}prod1: [{{ results | passed('pco-prod1', iaas) or '–' }}]({{ detail_url('pco-prod1', iaas) }}){# -#}
-{#- #}[{{ results | passed('pco-prod2', iaas) or '–' }}]({{ detail_url('pco-prod2', iaas) }}){# -#} +{#- #}prod2: [{{ results | passed('pco-prod2', iaas) or '–' }}]({{ detail_url('pco-prod2', iaas) }}){# -#}
-{#- #}[{{ results | passed('pco-prod3', iaas) or '–' }}]({{ detail_url('pco-prod3', iaas) }}){# -#} +{#- #}prod3: [{{ results | passed('pco-prod3', iaas) or '–' }}]({{ detail_url('pco-prod3', iaas) }}){# -#}
-{#- #}[{{ results | passed('pco-prod4', iaas) or '–' }}]({{ detail_url('pco-prod4', iaas) }}) {# -#} -|  
[HM1](https://health.prod1.plusserver.sovereignit.cloud:3000/d/9ltTEmlnk/openstack-health-monitor2?orgId=1&var-mycloud=plus-pco)
[HM2](https://health.prod1.plusserver.sovereignit.cloud:3000/d/9ltTEmlnk/openstack-health-monitor2?orgId=1&var-mycloud=plus-prod2)
[HM3](https://health.prod1.plusserver.sovereignit.cloud:3000/d/9ltTEmlnk/openstack-health-monitor2?orgId=1&var-mycloud=plus-prod3)
[HM4](https://health.prod1.plusserver.sovereignit.cloud:3000/d/9ltTEmlnk/openstack-health-monitor2?orgId=1&var-mycloud=plus-prod4) | +{#- #}prod4: [{{ results | passed('pco-prod4', iaas) or '–' }}]({{ detail_url('pco-prod4', iaas) }}) {# -#} +| [HM1](https://health.prod1.plusserver.sovereignit.cloud:3000/d/9ltTEmlnk/openstack-health-monitor2?orgId=1&var-mycloud=plus-pco)
[HM2](https://health.prod1.plusserver.sovereignit.cloud:3000/d/9ltTEmlnk/openstack-health-monitor2?orgId=1&var-mycloud=plus-prod2)
[HM3](https://health.prod1.plusserver.sovereignit.cloud:3000/d/9ltTEmlnk/openstack-health-monitor2?orgId=1&var-mycloud=plus-prod3)
[HM4](https://health.prod1.plusserver.sovereignit.cloud:3000/d/9ltTEmlnk/openstack-health-monitor2?orgId=1&var-mycloud=plus-prod4) | | PoC KDO | Cloud PoC for FITKO | KDO Service GmbH / OSISM GmbH | {#- #} [{{ results | passed('poc-kdo', iaas) or '–' }}]({{ detail_url('poc-kdo', iaas) }}) {# -#} | (soon) | @@ -29,11 +32,11 @@ for the time being to have the highest degree of control | [REGIO.cloud](https://regio.digital) | Public cloud for customers | OSISM GmbH | {#- #} [{{ results | passed('regio-a', iaas) or '–' }}]({{ detail_url('regio-a', iaas) }}) {# -#} | [HM](https://apimon.services.regio.digital/public-dashboards/17cf094a47404398a5b8e35a4a3968d4?orgId=1&refresh=5m) | -| [syseleven](https://www.syseleven.de/en/products-services/openstack-cloud/)
- dus2
- ham1 | Public OpenStack Cloud (2 SCS regions) | SysEleven GmbH |  
-{#- #}[{{ results | passed('syseleven-dus2', iaas) or '–' }}]({{ detail_url('syseleven-dus2', iaas) }}){# -#} +| [syseleven](https://www.syseleven.de/en/products-services/openstack-cloud/)
(2 SCS regions) | Public OpenStack Cloud | SysEleven GmbH | {# #} +{#- #}dus2: [{{ results | passed('syseleven-dus2', iaas) or '–' }}]({{ detail_url('syseleven-dus2', iaas) }}){# -#}
-{#- #}[{{ results | passed('syseleven-ham1', iaas) or '–' }}]({{ detail_url('syseleven-ham1', iaas) }}) {# -#} -|  
(soon)
(soon) | +{#- #}ham1: [{{ results | passed('syseleven-ham1', iaas) or '–' }}]({{ detail_url('syseleven-ham1', iaas) }}) {# -#} +| (soon)
(soon) | | [Wavestack](https://www.noris.de/wavestack-cloud/) | Public cloud for customers | noris network AG/Wavecon GmbH | {#- #} [{{ results | passed('wavestack', iaas) or '–' }}]({{ detail_url('wavestack', iaas) }}) {# -#} | [HM](https://health.wavestack1.sovereignit.cloud:3000/) | diff --git a/compliance-monitor/templates/overview_fragment.html.j2 b/compliance-monitor/templates/overview_fragment.html.j2 deleted file mode 100644 index e352cc23a..000000000 --- a/compliance-monitor/templates/overview_fragment.html.j2 +++ /dev/null @@ -1,46 +0,0 @@ -{# -we could of course iterate over results etc., but hardcode the table (except the actual results, of course) -for the time being to have the highest degree of control --#} -{% set iaas = '50393e6f-2ae1-4c5c-a62c-3b75f2abef3f' -%} - - - - - - - - - - -
NameDescriptionOperatorSCS-compatible IaaSHealthMon
gx-scsDev environment provided for SCS & GAIA-X contextplusserver GmbH -{#- #}{{ results | passed('gx-scs', iaas) or '–' }}{# -#} - HM
CNDSPublic cloud for customersartcodix GmbH -{#- #}{{ results | passed('artcodix', iaas) or '–' }}{# -#} - HM
pluscloud open
- prod1
- prod2
- prod3
- prod4
Public cloud for customers (4 regions)plusserver GmbH 
-{#- #}{{ results | passed('pco-prod1', iaas) or '–' }}{# -#} -
-{#- #}{{ results | passed('pco-prod2', iaas) or '–' }}{# -#} -
-{#- #}{{ results | passed('pco-prod3', iaas) or '–' }}{# -#} -
-{#- #}{{ results | passed('pco-prod4', iaas) or '–' }}{# -#} -
 
-HM1
-HM2
-HM3
-HM4
PoC KDOCloud PoC for FITKOKDO Service GmbH / OSISM GmbH -{#- #}{{ results | passed('poc-kdo', iaas) or '–' }}{# -#} - (soon)
PoC WG-Cloud OSBACloud PoC for FITKOCloud&Heat Technologies GmbH -{#- #}{{ results | passed('poc-wgcloud', iaas) or '–' }}{# -#} - HM
REGIO.cloudPublic cloud for customersOSISM GmbH -{#- #}{{ results | passed('regio-a', iaas) or '–' }}{# -#} - HM
syseleven
- dus2
- ham1
Public OpenStack Cloud (2 SCS regions)SysEleven GmbH 
-{#- #}{{ results | passed('syseleven-dus2', iaas) or '–' }}{# -#} -
-{#- #}{{ results | passed('syseleven-ham1', iaas) or '–' }}{# -#} -
 
-(soon)
-(soon)
WavestackPublic cloud for customersnoris network AG/Wavecon GmbH -{#- #}{{ results | passed('wavestack', iaas) or '–' }}{# -#} - HM