You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tooling.apache.org by sb...@apache.org on 2025/02/20 13:34:18 UTC
(tooling-atr-experiments) branch main updated: Add ability to attach checksum file to a release candidate
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-atr-experiments.git
The following commit(s) were added to refs/heads/main by this push:
new 0410267 Add ability to attach checksum file to a release candidate
0410267 is described below
commit 04102672dea2e7de51677c6c5b48d93714b89e03
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Thu Feb 20 15:34:03 2025 +0200
Add ability to attach checksum file to a release candidate
---
atr/db/models.py | 2 +-
atr/routes.py | 146 ++++++++++++++-------
atr/static/css/atr.css | 4 +
atr/templates/candidate-attach.html | 47 ++++++-
atr/templates/candidate-review.html | 31 +++++
...al_schema.py => d8434a3de3da_initial_schema.py} | 6 +-
6 files changed, 182 insertions(+), 54 deletions(-)
diff --git a/atr/db/models.py b/atr/db/models.py
index f7a37d8..4c07ae6 100644
--- a/atr/db/models.py
+++ b/atr/db/models.py
@@ -142,7 +142,7 @@ class Package(SQLModel, table=True):
# SHA-512 hash of the file
sha512: str
# The signature file
- signature_sha3: str
+ signature_sha3: str | None = None
# Uploaded timestamp
uploaded: datetime.datetime
# The size of the file in bytes
diff --git a/atr/routes.py b/atr/routes.py
index ad60c3e..2ef95a5 100644
--- a/atr/routes.py
+++ b/atr/routes.py
@@ -99,71 +99,116 @@ async def ephemeral_gpg_home():
async def release_attach_post(session: ClientSession, request: Request) -> Response:
"""Handle POST request for attaching package artifacts to a release."""
+
+ async def flash_error_and_redirect(message: str) -> Response:
+ await flash(message, "error")
+ return redirect(url_for("root_candidate_attach"))
+
form = await request.form
# TODO: Check that the submitter is a committer of the project
release_key = form.get("release_key")
if not release_key:
- raise ASFQuartException("Release key is required", errorcode=400)
+ return await flash_error_and_redirect("Release key is required")
# Get all uploaded files
files = await request.files
- # Get the release artifact and signature files
+ # Get the release artifact, checksum, and signature files
artifact_file = files.get("release_artifact")
+ checksum_file = files.get("release_checksum")
signature_file = files.get("release_signature")
+ if not isinstance(artifact_file, FileStorage):
+ return await flash_error_and_redirect("Release artifact file is required")
+ if artifact_file.filename is None:
+ return await flash_error_and_redirect("Release artifact filename is required")
+ if checksum_file is not None and not isinstance(checksum_file, FileStorage):
+ return await flash_error_and_redirect("Problem with checksum file")
+ if signature_file is not None and not isinstance(signature_file, FileStorage):
+ return await flash_error_and_redirect("Problem with signature file")
+
+ # Save files and create package record in one transaction
+ async with get_session() as db_session:
+ async with db_session.begin():
+ # First check for duplicates
+ statement = select(Package).where(
+ Package.release_key == release_key,
+ Package.filename == artifact_file.filename,
+ )
+ duplicate = (await db_session.execute(statement)).first()
+
+ if duplicate:
+ return await flash_error_and_redirect("This release artifact has already been uploaded")
+
+ # Process and save the files
+ try:
+ ok, artifact_sha3, artifact_size, artifact_sha512, signature_sha3 = await release_attach_post_helper(
+ artifact_file, checksum_file, signature_file
+ )
+ if not ok:
+ # The flash error is already set by the helper
+ return redirect(url_for("root_candidate_attach"))
+
+ # Create the package record
+ package = Package(
+ artifact_sha3=artifact_sha3,
+ filename=artifact_file.filename,
+ signature_sha3=signature_sha3,
+ sha512=artifact_sha512,
+ release_key=release_key,
+ uploaded=datetime.datetime.now(datetime.UTC),
+ bytes_size=artifact_size,
+ )
+ db_session.add(package)
+
+ except Exception as e:
+ return await flash_error_and_redirect(f"Error processing files: {e!s}")
+
+ # Otherwise redirect to review page
+ return redirect(url_for("root_candidate_review"))
- if not artifact_file:
- raise ASFQuartException("Release artifact file is required", errorcode=400)
- if not signature_file:
- raise ASFQuartException("Detached GPG signature file is required", errorcode=400)
- if not signature_file.filename.endswith(".asc"):
- # TODO: Could also check that it's artifact name + ".asc"
- # And at least warn if it's not
- raise ASFQuartException("Signature file must have .asc extension", errorcode=400)
+async def release_attach_post_helper(
+ artifact_file: FileStorage, checksum_file: FileStorage | None, signature_file: FileStorage | None
+) -> tuple[bool, str, int, str, str | None]:
+ """Helper function for release_attach_post."""
# Save files using their hashes as filenames
uploads_path = Path(get_release_storage_dir())
- artifact_sha3, artifact_size = await save_file_by_hash(uploads_path, artifact_file)
- signature_sha3, _ = await save_file_by_hash(uploads_path, signature_file)
-
- # Check if these files are already attached to this release
- async with get_session() as db_session:
- # Check for duplicate artifact or signature in a single query
- statement = select(Package).where(
- Package.release_key == release_key,
- (Package.artifact_sha3 == artifact_sha3) | (Package.signature_sha3 == signature_sha3),
- )
- duplicate = (await db_session.execute(statement)).first()
-
- if duplicate:
- package = duplicate[0]
- # TODO: This logic should be improved
- if package.artifact_sha3 == artifact_sha3:
- raise ASFQuartException("This release artifact has already been uploaded", errorcode=400)
- else:
- raise ASFQuartException("This signature file has already been uploaded", errorcode=400)
-
+ try:
+ artifact_sha3, artifact_size = await save_file_by_hash(uploads_path, artifact_file)
# Compute SHA-512 of the artifact for the package record
- sha512 = compute_sha512(uploads_path / artifact_sha3)
-
- # Create the package record in the database
- async with get_session() as db_session:
- async with db_session.begin():
- package = Package(
- artifact_sha3=artifact_sha3,
- filename=artifact_file.filename,
- signature_sha3=signature_sha3,
- sha512=sha512,
- release_key=release_key,
- uploaded=datetime.datetime.now(datetime.UTC),
- bytes_size=artifact_size,
- )
- db_session.add(package)
-
- # Redirect to the release candidate review page
- return redirect(url_for("root_candidate_review"))
+ artifact_sha512 = compute_sha512(uploads_path / artifact_sha3)
+ except Exception as e:
+ await flash(f"Error saving artifact file: {e!s}", "error")
+ return False, "", 0, "", None
+ # Note: "error" is not permitted past this point
+ # Because we don't want to roll back saving the artifact
+
+ # Validate checksum file if provided
+ if checksum_file:
+ try:
+ # Read only the number of bytes required for the checksum
+ bytes_required: int = len(artifact_sha512)
+ checksum_content = checksum_file.read(bytes_required).decode().strip()
+ if checksum_content.lower() != artifact_sha512.lower():
+ await flash("Warning: Provided checksum does not match computed SHA-512", "warning")
+ except UnicodeDecodeError:
+ await flash("Warning: Could not read checksum file as text", "warning")
+ except Exception as e:
+ await flash(f"Warning: Error validating checksum file: {e!s}", "warning")
+
+ # Process signature file if provided
+ signature_sha3 = None
+ if signature_file and signature_file.filename:
+ if not signature_file.filename.endswith(".asc"):
+ await flash("Warning: Signature file should have .asc extension", "warning")
+ try:
+ signature_sha3, _ = await save_file_by_hash(uploads_path, signature_file)
+ except Exception as e:
+ await flash(f"Warning: Could not save signature file: {e!s}", "warning")
+
+ return True, artifact_sha3, artifact_size, artifact_sha512, signature_sha3
async def release_create_post(session: ClientSession, request: Request) -> Response:
@@ -329,6 +374,11 @@ async def root_candidate_signatures_verify(release_key: str) -> str:
result = {"file": package.artifact_sha3}
artifact_path = storage_dir / package.artifact_sha3
+ if package.signature_sha3 is None:
+ result["error"] = "No signature file provided"
+ verification_results.append(result)
+ continue
+
signature_path = storage_dir / package.signature_sha3
if not artifact_path.exists():
diff --git a/atr/static/css/atr.css b/atr/static/css/atr.css
index 6625b04..29d1ebe 100644
--- a/atr/static/css/atr.css
+++ b/atr/static/css/atr.css
@@ -35,6 +35,10 @@ input, textarea, button, select, option {
font-weight: 425;
}
+select, input[type="file"] {
+ padding: 6px 12px;
+}
+
a { font-weight: 450; }
h1, h2, h3 {
diff --git a/atr/templates/candidate-attach.html b/atr/templates/candidate-attach.html
index b304560..c92c8e2 100644
--- a/atr/templates/candidate-attach.html
+++ b/atr/templates/candidate-attach.html
@@ -58,6 +58,30 @@
opacity: 0.5;
cursor: not-allowed;
}
+
+ .flash-message {
+ padding: 1rem;
+ margin-bottom: 1rem;
+ border-radius: 4px;
+ }
+
+ .flash-warning {
+ background-color: #fff3cd;
+ border: 1px solid #ffeeba;
+ color: #856404;
+ }
+
+ .flash-error {
+ background-color: #f8d7da;
+ border: 1px solid #f5c6cb;
+ color: #721c24;
+ }
+
+ .flash-success {
+ background-color: #d4edda;
+ border: 1px solid #c3e6cb;
+ color: #155724;
+ }
</style>
{% endblock stylesheets %}
@@ -68,6 +92,12 @@
to an existing release candidate.
</p>
+ {% with messages = get_flashed_messages(with_categories=true) %}
+ {% if messages %}
+ {% for category, message in messages %}<div class="flash-message flash-{{ category }}">{{ message }}</div>{% endfor %}
+ {% endif %}
+ {% endwith %}
+
<form method="post" enctype="multipart/form-data" class="striking">
<table class="form-table">
<tbody>
@@ -109,6 +139,20 @@
</td>
</tr>
+ <tr>
+ <th>
+ <label for="release_checksum">SHA-512 Checksum File:</label>
+ </th>
+ <td>
+ <input type="file"
+ id="release_checksum"
+ name="release_checksum"
+ accept=".sha512,.sha,.txt"
+ aria-describedby="checksum-help" />
+ <span id="checksum-help" class="help-text">Optional: Upload the SHA-512 checksum file for verification</span>
+ </td>
+ </tr>
+
<tr>
<th>
<label for="release_signature">Detached GPG Signature:</label>
@@ -117,10 +161,9 @@
<input type="file"
id="release_signature"
name="release_signature"
- required
accept="application/pgp-signature,.asc"
aria-describedby="signature-help" />
- <span id="signature-help" class="help-text">Upload the detached GPG signature (.asc) file for the release candidate</span>
+ <span id="signature-help" class="help-text">Optional: Upload the detached GPG signature (.asc) file</span>
</td>
</tr>
diff --git a/atr/templates/candidate-review.html b/atr/templates/candidate-review.html
index 983d244..d118e6b 100644
--- a/atr/templates/candidate-review.html
+++ b/atr/templates/candidate-review.html
@@ -95,11 +95,42 @@
.candidate-meta-item:last-child::after {
content: none;
}
+
+ .flash-message {
+ padding: 1rem;
+ margin-bottom: 1rem;
+ border-radius: 4px;
+ }
+
+ .flash-warning {
+ background-color: #fff3cd;
+ border: 1px solid #ffeeba;
+ color: #856404;
+ }
+
+ .flash-error {
+ background-color: #f8d7da;
+ border: 1px solid #f5c6cb;
+ color: #721c24;
+ }
+
+ .flash-success {
+ background-color: #d4edda;
+ border: 1px solid #c3e6cb;
+ color: #155724;
+ }
</style>
{% endblock stylesheets %}
{% block content %}
<h1>Release candidates</h1>
+
+ {% with messages = get_flashed_messages(with_categories=true) %}
+ {% if messages %}
+ {% for category, message in messages %}<div class="flash-message flash-{{ category }}">{{ message }}</div>{% endfor %}
+ {% endif %}
+ {% endwith %}
+
<p class="intro">Here are all the release candidates to which you have access.</p>
{% if releases %}
diff --git a/migrations/versions/5d63e3dd5e93_initial_schema.py b/migrations/versions/d8434a3de3da_initial_schema.py
similarity index 84%
rename from migrations/versions/5d63e3dd5e93_initial_schema.py
rename to migrations/versions/d8434a3de3da_initial_schema.py
index 104e000..82f8c3a 100644
--- a/migrations/versions/5d63e3dd5e93_initial_schema.py
+++ b/migrations/versions/d8434a3de3da_initial_schema.py
@@ -1,15 +1,15 @@
"""initial_schema
-Revision ID: 5d63e3dd5e93
+Revision ID: d8434a3de3da
Revises:
-Create Date: 2025-02-19 20:56:26.175412
+Create Date: 2025-02-20 15:24:43.391427
"""
from collections.abc import Sequence
# revision identifiers, used by Alembic.
-revision: str = "5d63e3dd5e93"
+revision: str = "d8434a3de3da"
down_revision: str | None = None
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org