Skip to content
Open
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
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: v7.3.0-24-g169e035
_commit: v8.5.0-4-gd5f8597
_src_path: gh:eccenca/cmem-plugin-template
author_mail: cmempy-developer@eccenca.com
author_name: eccenca GmbH
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ jobs:
- name: Check out repository
uses: actions/checkout@v5

- name: Cache Trivy DB
id: cache-trivydb
uses: actions/cache@v4
with:
path: .trivycache
key: ${{ runner.os }}-trivydb

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

Expand All @@ -38,10 +45,6 @@ jobs:
virtualenvs-in-project: true
installer-parallel: true

- name: Install dynamic versioning plugin
run: |
poetry self add "poetry-dynamic-versioning[plugin]"

- name: mypy
run: |
task check:mypy
Expand All @@ -61,9 +64,13 @@ jobs:
run: |
task check:deptry

- name: safety
- name: trivy
env:
TRIVY_NO_PROGRESS: "true"
TRIVY_CACHE_DIR: ".trivycache/"
TRIVY_DISABLE_VEX_NOTICE: "true"
run: |
task check:safety
task check:trivy

- name: Publish Test Report in Action
uses: mikepenz/action-junit-report@v4
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ jobs:
virtualenvs-in-project: true
installer-parallel: true

- name: Install dynamic versioning plugin
run: |
poetry self add "poetry-dynamic-versioning[plugin]"

- name: Publish Package
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ dmypy.json
# Cython debug symbols
cython_debug/

# Claude code specifics
.claude/settings.local.json

# project build plan specific ignores
version.py
co
Expand Down
15 changes: 11 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
default:
image: docker-registry.eccenca.com/eccenca-python:v3.13.8
image: docker-registry.eccenca.com/eccenca-python:v3.13.13
# all jobs can be interrupted in case a new commit is pushed
interruptible: true
before_script:
Expand Down Expand Up @@ -60,17 +60,24 @@ deptry:
script:
- task check:deptry

safety:
trivy:
stage: test
variables:
TRIVY_NO_PROGRESS: "true"
TRIVY_CACHE_DIR: ".trivycache/"
TRIVY_DISABLE_VEX_NOTICE: "true"
script:
- task check:safety
- task check:trivy
cache:
paths:
- .trivycache/

build:
stage: build
needs:
- mypy
- pytest
- safety
- trivy
- deptry
script:
- task build
Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
default_language_version:
python: python3.13

repos:
- repo: local
hooks:
Expand Down Expand Up @@ -36,3 +39,9 @@ repos:
stages: [post-checkout, post-merge]
always_run: true

- id: trivy
name: check:trivy
description: run trivy to scan for vulnerabilities
entry: task check:trivy
language: python
pass_filenames: false
4 changes: 4 additions & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# .trivyignore

# ignore 51358 safety - dev dependency only
CVE-2022-39280
44 changes: 11 additions & 33 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,9 @@ tasks:
cmds:
- mkdir -p {{.DIST_DIR}}/coverage

poetry:check:
internal: true
platforms: [darwin, linux]
summary: |
Check poetry versioning plugin. Currently not under Windows
run: once
preconditions:
- sh: '[ -d .git ]'
msg: >
Your newly created project directory needs to be initialized
as a git repository.
- sh: '[[ {{.PDV_VERSION}} > {{.PDV_VERSION_MIN}} ]]'
msg: >
This project needs the poetry-dynamic-versioning
plugin > v{{.PDV_VERSION_MIN}}.

You can install it with the following command:
poetry self add "poetry-dynamic-versioning[plugin]"
vars:
PDV_VERSION_MIN: 0.20
PDV_VERSION:
sh: >
poetry self show --addons poetry-dynamic-versioning --tree
| head -1 | cut -d " " -f 2 | cut -d "." -f 1-2

poetry:install:
desc: Install dependencies managed by Poetry
run: once
deps:
- poetry:check
cmds:
- poetry install

Expand Down Expand Up @@ -112,7 +85,7 @@ tasks:
- task: check:ruff
- task: check:mypy
- task: check:deptry
- task: check:safety
- task: check:trivy

check:pytest:
desc: Run unit and integration tests
Expand Down Expand Up @@ -154,12 +127,17 @@ tasks:
vars:
JUNIT_FILE: ./{{.DIST_DIR}}/junit-mypy.xml

check:safety:
desc: Complain about vulnerabilities in dependencies
check:trivy:
desc: Scan for vulnerabilities using Trivy
<<: *preparation
cmds:
# ignore 51358 safety - dev dependency only
- poetry run safety check -i 51358
- >
poetry run trivy fs
--include-dev-deps
--scanners vuln
--skip-files .poetry/plugins/poetry.lock
--exit-code 1
.

check:deptry:
desc: Complain about unused or missing dependencies
Expand All @@ -185,7 +163,7 @@ tasks:
<<: *preparation
deps:
- clean
- poetry:check
cmds:
- poetry build
- poetry export --without=dev -f requirements.txt >dist/requirements.txt

42 changes: 15 additions & 27 deletions cmem_plugin_validation/validate_entities/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
from types import SimpleNamespace
from typing import Any

from cmem.cmempy.workspace.projects.resources.resource import get_resource_response
from cmem.cmempy.workspace.tasks import get_task
from cmem_client.client import Client
from cmem_plugin_base.dataintegration.context import (
ExecutionContext,
ExecutionReport,
UserContext,
)
from cmem_plugin_base.dataintegration.description import Icon, Plugin, PluginParameter
from cmem_plugin_base.dataintegration.entity import Entities
Expand All @@ -24,11 +22,6 @@
FlexibleNumberOfInputs,
UnknownSchemaPort,
)
from cmem_plugin_base.dataintegration.utils import (
setup_cmempy_user_access,
split_task_id,
write_to_dataset,
)
from cmem_plugin_base.dataintegration.utils.entity_builder import build_entities_from_data
from jsonschema import validate
from jsonschema.exceptions import ValidationError
Expand Down Expand Up @@ -77,13 +70,6 @@

DEFAULT_FAIL_ON_VIOLATION = False


def get_task_metadata(project: str, task: str, context: UserContext) -> dict:
"""Get metadata information of a task"""
setup_cmempy_user_access(context=context)
return dict(get_task(project=project, task=task))


SOURCE = SimpleNamespace()
SOURCE.entities = "entities"
SOURCE.dataset = "dataset"
Expand Down Expand Up @@ -172,7 +158,7 @@ class ValidateEntity(WorkflowPlugin):
inputs: Sequence[Entities]
execution_context: ExecutionContext

def __init__( # noqa: PLR0913
def __init__( # noqa: PLR0913 PLR0917
self,
source_mode: str,
target_mode: str,
Expand Down Expand Up @@ -297,10 +283,10 @@ def execute(
)
)
if self.target_mode == TARGET.dataset:
write_to_dataset(
dataset_id=f"{context.task.project_id()}:{self.target_dataset}",
file_resource=io.StringIO(json.dumps(valid_json_objects)),
context=context.user,
Client.from_context(context=context).datasets.post_file_resource(
project_id=context.task.project_id(),
dataset_id=self.target_dataset,
file_resource=io.BytesIO(json.dumps(valid_json_objects).encode("utf-8")),
)
return None

Expand All @@ -319,16 +305,18 @@ def _validate_json(self, json: dict, schema: dict) -> bool:
@staticmethod
def _get_json_dataset_content(context: ExecutionContext, dataset: str) -> dict | list[dict]:
"""Get json dataset content"""
dataset_id = f"{context.task.project_id()}:{dataset}"
project_id, task_id = split_task_id(dataset_id)
task_meta_data = get_task_metadata(project_id, task_id, context.user)
resource_name = str(task_meta_data["data"]["parameters"]["file"]["value"])
response = get_resource_response(project_id, resource_name)
return response.json() # type: ignore[no-any-return]
client = Client.from_context(context=context)
project_id = context.task.project_id()
resource_name = str(
client.datasets.get_item(project_id=project_id, dataset_id=dataset).data.parameters[
"file"
]
)
return json.loads(client.files.read(f"{project_id}:{resource_name}")) # type: ignore[no-any-return]

def _convert_entities_to_json(
self, inputs: Sequence[Entities], path_to_entities: dict[str, Entities], path: str = ""
) -> Generator[dict[str, Any], None, None]:
) -> Generator[dict[str, Any]]:
"""Convert a sequence of Entities into JSON-like dictionaries using recursive traversal."""
for entities in inputs:
# Initialize path-to-entities map for the root level
Expand Down
19 changes: 11 additions & 8 deletions cmem_plugin_validation/validate_graph/state.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Graph validation process state"""

from cmem.cmempy.dp.shacl import validation
from cmem_client.client import Client


class State:
"""State of a validation process"""

client: Client
id_: str
data: dict
status: str
Expand All @@ -14,15 +15,17 @@ class State:
with_violations: int
violations: int

def __init__(self, id_: str):
def __init__(self, client: Client, id_: str):
self.client = client
self.id_ = id_
self.refresh()

def refresh(self) -> None:
"""Refresh state of validation process"""
self.data = validation.get_aggregation(batch_id=self.id_)
self.status = self.data.get("state", "UNKNOWN")
self.completed = self.data.get("resourceProcessedCount", 0)
self.total = self.data.get("resourceCount", 0)
self.with_violations = self.data.get("resourcesWithViolationsCount", 0)
self.violations = self.data.get("violationsCount", 0)
aggregation = self.client.validations.get_aggregation(batch_id=self.id_)
self.data = aggregation.model_dump(by_alias=True, exclude_none=True)
self.status = aggregation.state
self.completed = aggregation.resource_processed_count
self.total = aggregation.resource_count
self.with_violations = aggregation.resources_with_violations_count
self.violations = aggregation.violations_count
Loading
Loading