Skip to content

Commit 01a3eca

Browse files
update template to v8.3.0, allow urn URIs
1 parent a2c9e25 commit 01a3eca

12 files changed

Lines changed: 1137 additions & 936 deletions

File tree

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: v7.3.0
2+
_commit: v8.3.0
33
_src_path: gh:eccenca/cmem-plugin-template
44
author_mail: cmempy-developer@eccenca.com
55
author_name: eccenca GmbH

.github/workflows/check.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,23 @@ jobs:
2020

2121
steps:
2222
- name: Check out repository
23-
uses: actions/checkout@v4
23+
uses: actions/checkout@v5
24+
25+
- name: Cache Trivy DB
26+
id: cache-trivydb
27+
uses: actions/cache@v4
28+
with:
29+
path: .trivycache
30+
key: ${{ runner.os }}-trivydb
2431

2532
- name: Install Task
2633
uses: arduino/setup-task@v2
2734

2835
- name: Set up python
2936
id: setup-python
30-
uses: actions/setup-python@v5
37+
uses: actions/setup-python@v6
3138
with:
32-
python-version: '3.11'
39+
python-version: '3.13'
3340

3441
- name: Install and configure poetry
3542
uses: snok/install-poetry@v1
@@ -61,9 +68,13 @@ jobs:
6168
run: |
6269
task check:deptry
6370
64-
- name: safety
71+
- name: trivy
72+
env:
73+
TRIVY_NO_PROGRESS: "true"
74+
TRIVY_CACHE_DIR: ".trivycache/"
75+
TRIVY_DISABLE_VEX_NOTICE: "true"
6576
run: |
66-
task check:safety
77+
task check:trivy
6778
6879
- name: Publish Test Report in Action
6980
uses: mikepenz/action-junit-report@v4

.github/workflows/publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ jobs:
1717

1818
steps:
1919
- name: Check out repository
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@v5
2121

2222
- name: Install Task
2323
uses: arduino/setup-task@v2
2424

2525
- name: Set up python
2626
id: setup-python
27-
uses: actions/setup-python@v5
27+
uses: actions/setup-python@v6
2828
with:
29-
python-version: '3.11'
29+
python-version: '3.13'
3030

3131
- name: Install and configure poetry
3232
uses: snok/install-poetry@v1

.gitlab-ci.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
default:
3-
image: docker-registry.eccenca.com/eccenca-python:v3.11.9-2
3+
image: docker-registry.eccenca.com/eccenca-python:v3.13.8
44
# all jobs can be interrupted in case a new commit is pushed
55
interruptible: true
66
before_script:
@@ -53,27 +53,32 @@ pytest:
5353
junit:
5454
- dist/junit-pytest.xml
5555
paths:
56-
- dist/badge-coverage.svg
57-
- dist/badge-tests.svg
58-
- dist/coverage
59-
- dist/coverage.xml
56+
- dist/*
6057

6158
deptry:
6259
stage: test
6360
script:
6461
- task check:deptry
6562

66-
safety:
63+
trivy:
6764
stage: test
65+
variables:
66+
TRIVY_NO_PROGRESS: "true"
67+
TRIVY_CACHE_DIR: ".trivycache/"
68+
TRIVY_DISABLE_VEX_NOTICE: "true"
6869
script:
69-
- task check:safety
70+
- task check:trivy
71+
cache:
72+
paths:
73+
- .trivycache/
7074

7175
build:
7276
stage: build
7377
needs:
7478
- mypy
7579
- pytest
76-
- safety
80+
- trivy
81+
- deptry
7782
script:
7883
- task build
7984
artifacts:

.idea/cmem-plugin-pyshacl.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
default_language_version:
3+
python: python3.13
4+
25
repos:
36
- repo: local
47
hooks:
@@ -36,3 +39,9 @@ repos:
3639
stages: [post-checkout, post-merge]
3740
always_run: true
3841

42+
- id: trivy
43+
name: check:trivy
44+
description: run trivy to scan for vulnerabilities
45+
entry: task check:trivy
46+
language: python
47+
pass_filenames: false

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11
1+
3.13

.trivyignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# .trivyignore
2+
3+
# ignore 51358 safety - dev dependency only
4+
CVE-2022-39280

Taskfile.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ includes:
2020
custom:
2121
taskfile: ./TaskfileCustom.yaml
2222
optional: true
23+
flatten: true
2324
plugin:
2425
taskfile: .tasks-plugin.yml
2526
optional: true
27+
flatten: true
2628

2729
tasks:
2830

@@ -49,7 +51,7 @@ tasks:
4951
Check poetry versioning plugin. Currently not under Windows
5052
run: once
5153
preconditions:
52-
- sh: '[ -d .git ]'
54+
- sh: git -C . rev-parse
5355
msg: >
5456
Your newly created project directory needs to be initialized
5557
as a git repository.
@@ -110,7 +112,7 @@ tasks:
110112
- task: check:ruff
111113
- task: check:mypy
112114
- task: check:deptry
113-
- task: check:safety
115+
- task: check:trivy
114116

115117
check:pytest:
116118
desc: Run unit and integration tests
@@ -152,12 +154,16 @@ tasks:
152154
vars:
153155
JUNIT_FILE: ./{{.DIST_DIR}}/junit-mypy.xml
154156

155-
check:safety:
156-
desc: Complain about vulnerabilities in dependencies
157+
check:trivy:
158+
desc: Scan for vulnerabilities using Trivy
157159
<<: *preparation
158160
cmds:
159-
# ignore 51358 safety - dev dependency only
160-
- poetry run safety check -i 51358
161+
- >
162+
poetry run trivy fs
163+
--include-dev-deps
164+
--scanners vuln
165+
--exit-code 1
166+
.
161167
162168
check:deptry:
163169
desc: Complain about unused or missing dependencies

cmem_plugin_pyshacl/plugin_pyshacl.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""CMEM plugin for SHACl validation using pySHACL"""
22

3+
import re
34
from collections import OrderedDict
45
from datetime import UTC, datetime
56
from tempfile import NamedTemporaryFile
@@ -352,6 +353,14 @@ def __init__( # noqa: PLR0913
352353
self.remove_shape_catalog_graph_type = remove_shape_catalog_graph_type
353354
self.max_validation_depth = max_validation_depth
354355

356+
@staticmethod
357+
def is_valid_uri(uri: str | None) -> bool:
358+
"""Validate URI"""
359+
if not isinstance(uri, str):
360+
return False
361+
urn_pattern = r"^urn:[a-zA-Z][a-zA-Z0-9-]{0,31}:.+$"
362+
return validators.url(uri) is True or bool(re.match(urn_pattern, uri, re.IGNORECASE))
363+
355364
def add_prov(self, validation_graph: Graph, utctime: str) -> Graph:
356365
"""Add provenance data"""
357366
self.log.info("Adding PROV information validation graph")
@@ -551,14 +560,14 @@ def check_parameters( # noqa: C901 PLR0912
551560
raise ValueError(
552561
"Generate validation graph or Output values parameter needs to be set to true"
553562
)
554-
if not validators.url(self.data_graph_uri):
563+
if not self.is_valid_uri(self.data_graph_uri):
555564
raise ValueError("Data graph URI parameter is invalid")
556-
if not validators.url(self.shacl_graph_uri):
565+
if not self.is_valid_uri(self.shacl_graph_uri):
557566
raise ValueError("SHACL graph URI parameter is invalid")
558567
graphs_dict = {graph["iri"]: graph["assignedClasses"] for graph in get_graphs_list()}
559568

560569
if self.ontology_graph_uri:
561-
if not validators.url(self.ontology_graph_uri):
570+
if not self.is_valid_uri(self.ontology_graph_uri):
562571
raise ValueError("Ontology graph URI parameter is invalid")
563572
if self.ontology_graph_uri not in graphs_dict:
564573
raise ValueError(f"Ontology graph <{self.ontology_graph_uri}> not found")
@@ -576,7 +585,7 @@ def check_parameters( # noqa: C901 PLR0912
576585
if "https://vocab.eccenca.com/shui/ShapeCatalog" not in graphs_dict[self.shacl_graph_uri]:
577586
raise ValueError(f"Invalid graph type for SHACL graph <{self.shacl_graph_uri}>")
578587
if self.generate_graph:
579-
if not validators.url(self.validation_graph_uri):
588+
if not self.is_valid_uri(self.validation_graph_uri):
580589
raise ValueError("Validation graph URI parameter is invalid")
581590
if self.validation_graph_uri in graphs_dict:
582591
self.log.warning(f"Graph <{self.validation_graph_uri}> already exists")

0 commit comments

Comments
 (0)