This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push:
new 7cb9946 Move check task creation to the task subpackage
7cb9946 is described below
commit 7cb9946fad21cc7a94edb4036fc725f08bbcb5e4
Author: Sean B. Palmer <[email protected]>
AuthorDate: Fri Mar 21 20:08:01 2025 +0200
Move check task creation to the task subpackage
---
atr/routes/package.py | 65 ++++++-----------------------------
atr/tasks/__init__.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
atr/tasks/rsync.py | 18 +++++++---
atr/util.py | 11 ++++++
4 files changed, 130 insertions(+), 58 deletions(-)
diff --git a/atr/routes/package.py b/atr/routes/package.py
index 3633c54..603ef48 100644
--- a/atr/routes/package.py
+++ b/atr/routes/package.py
@@ -22,6 +22,7 @@ import datetime
import hashlib
import logging
import logging.handlers
+import os.path
import pathlib
import secrets
from collections.abc import Sequence
@@ -38,7 +39,7 @@ import werkzeug.wrappers.response as response
import atr.db as db
import atr.db.models as models
import atr.routes as routes
-import atr.tasks.archive as archive
+import atr.tasks as tasks
import atr.util as util
@@ -545,64 +546,20 @@ async def task_package_status_get(data: db.Session,
artifact_sha3: str) -> tuple
return tasks, has_active_tasks
-async def task_verification_create(data: db.Session, package: models.Package)
-> list[models.Task]:
+async def task_verification_create(data: db.Session, package: models.Package)
-> None:
"""Create verification tasks for a package."""
+ # NOTE: A database session must be open when calling this function
if not package.release or not package.release.committee:
raise routes.FlashError("Could not determine committee for package")
if package.signature_sha3 is None:
raise routes.FlashError("Package has no signature")
- # TODO: We should probably use an enum for task_type
- tasks = [
- models.Task(
- status=models.TaskStatus.QUEUED,
- task_type="verify_archive_integrity",
- task_args=archive.CheckIntegrity(path="releases/" +
package.artifact_sha3).model_dump(),
- package_sha3=package.artifact_sha3,
- ),
- models.Task(
- status=models.TaskStatus.QUEUED,
- task_type="verify_archive_structure",
- task_args=["releases/" + package.artifact_sha3, package.filename],
- package_sha3=package.artifact_sha3,
- ),
- models.Task(
- status=models.TaskStatus.QUEUED,
- task_type="verify_signature",
- task_args=[
- package.release.committee.name,
- "releases/" + package.artifact_sha3,
- "releases/" + package.signature_sha3,
- ],
- package_sha3=package.artifact_sha3,
- ),
- models.Task(
- status=models.TaskStatus.QUEUED,
- task_type="verify_license_files",
- task_args=["releases/" + package.artifact_sha3],
- package_sha3=package.artifact_sha3,
- ),
- models.Task(
- status=models.TaskStatus.QUEUED,
- task_type="verify_license_headers",
- task_args=["releases/" + package.artifact_sha3],
- package_sha3=package.artifact_sha3,
- ),
- models.Task(
- status=models.TaskStatus.QUEUED,
- task_type="verify_rat_license",
- task_args=["releases/" + package.artifact_sha3],
- package_sha3=package.artifact_sha3,
- ),
- models.Task(
- status=models.TaskStatus.QUEUED,
- task_type="generate_cyclonedx_sbom",
- task_args=["releases/" + package.artifact_sha3],
- package_sha3=package.artifact_sha3,
- ),
- ]
- for task in tasks:
+ artifact_path = os.path.join("releases", package.artifact_sha3)
+ signature_path = os.path.join("releases", package.signature_sha3)
+ committee_name = package.release.committee.name
+ artifact_tasks = await tasks.artifact_checks(
+ artifact_path, signature_path=signature_path,
committee_name=committee_name
+ )
+ for task in artifact_tasks:
data.add(task)
-
- return tasks
diff --git a/atr/tasks/__init__.py b/atr/tasks/__init__.py
new file mode 100644
index 0000000..985ef2f
--- /dev/null
+++ b/atr/tasks/__init__.py
@@ -0,0 +1,94 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import os.path
+
+import aiofiles.os
+
+import atr.db.models as models
+import atr.tasks.archive as archive
+import atr.util as util
+
+
+async def artifact_checks(
+ path: str, signature_path: str | None = None, committee_name: str | None =
None
+) -> list[models.Task]:
+ # TODO: We should probably use an enum for task_type
+ if path.startswith("releases/"):
+ artifact_sha3 = path.split("/")[1]
+ else:
+ artifact_sha3 = await util.file_sha3(path)
+ filename = os.path.basename(path)
+ if signature_path is None:
+ signature_path = path + ".asc"
+ if not (await aiofiles.os.path.exists(signature_path)):
+ signature_path = None
+
+ tasks = [
+ models.Task(
+ status=models.TaskStatus.QUEUED,
+ task_type="verify_archive_integrity",
+ task_args=archive.CheckIntegrity(path=path).model_dump(),
+ package_sha3=artifact_sha3,
+ ),
+ models.Task(
+ status=models.TaskStatus.QUEUED,
+ task_type="verify_archive_structure",
+ task_args=[path, filename],
+ package_sha3=artifact_sha3,
+ ),
+ models.Task(
+ status=models.TaskStatus.QUEUED,
+ task_type="verify_license_files",
+ task_args=[path],
+ package_sha3=artifact_sha3,
+ ),
+ models.Task(
+ status=models.TaskStatus.QUEUED,
+ task_type="verify_license_headers",
+ task_args=[path],
+ package_sha3=artifact_sha3,
+ ),
+ models.Task(
+ status=models.TaskStatus.QUEUED,
+ task_type="verify_rat_license",
+ task_args=[path],
+ package_sha3=artifact_sha3,
+ ),
+ models.Task(
+ status=models.TaskStatus.QUEUED,
+ task_type="generate_cyclonedx_sbom",
+ task_args=[path],
+ package_sha3=artifact_sha3,
+ ),
+ ]
+
+ if signature_path and committee_name:
+ tasks.append(
+ models.Task(
+ status=models.TaskStatus.QUEUED,
+ task_type="verify_signature",
+ task_args=[
+ committee_name,
+ path,
+ signature_path,
+ ],
+ package_sha3=artifact_sha3,
+ ),
+ )
+
+ return tasks
diff --git a/atr/tasks/rsync.py b/atr/tasks/rsync.py
index da21777..398f994 100644
--- a/atr/tasks/rsync.py
+++ b/atr/tasks/rsync.py
@@ -16,14 +16,17 @@
# under the License.
import logging
+import os
from typing import Any, Final
import pydantic
+import atr.config as config
+import atr.db.models as models
import atr.tasks.task as task
-from atr import analysis
-from atr.db import models
+import atr.util as util
+_CONFIG: Final = config.get()
_LOGGER: Final = logging.getLogger(__name__)
@@ -49,6 +52,13 @@ async def analyse(args: dict[str, Any]) ->
tuple[models.TaskStatus, str | None,
return task.COMPLETED, None, task_results
-async def _analyse_core(asf_uid: str, project_name: str, release_version: str)
-> str:
+async def _analyse_core(asf_uid: str, project_name: str, release_version: str)
-> dict[str, Any]:
"""Analyse an rsync upload."""
- return analysis.perform.__name__
+ base_path = os.path.join(_CONFIG.STATE_DIR, "rsync-files", project_name,
release_version)
+ paths = await util.paths_recursive(base_path)
+ # for path in paths:
+ # # Add new tasks for each path
+ # # We could use the SHA3 in input and output
+ # # Or, less securely, we could use path and mtime instead
+ # ...
+ return {"paths": paths}
diff --git a/atr/util.py b/atr/util.py
index 78fe788..adb9503 100644
--- a/atr/util.py
+++ b/atr/util.py
@@ -89,6 +89,17 @@ async def compute_sha512(file_path: pathlib.Path) -> str:
return sha512.hexdigest()
+async def file_sha3(path: str) -> str:
+ """Compute SHA3-256 hash of a file."""
+ sha3 = hashlib.sha3_256()
+ async with aiofiles.open(path, "rb") as f:
+ chunk = await f.read(4096)
+ while chunk:
+ sha3.update(chunk)
+ chunk = await f.read(4096)
+ return sha3.hexdigest()
+
+
@functools.cache
def get_admin_users() -> set[str]:
return set(config.get().ADMIN_USERS)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]