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 3ca0328  Fix a problem with import ordering
3ca0328 is described below

commit 3ca0328326143098589f8866334f9cf8fe053dc6
Author: Sean B. Palmer <[email protected]>
AuthorDate: Thu Sep 4 15:43:15 2025 +0100

    Fix a problem with import ordering
---
 atr/routes/keys.py         | 29 +----------------------------
 atr/storage/writers/ssh.py |  4 ++--
 atr/util.py                | 25 +++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/atr/routes/keys.py b/atr/routes/keys.py
index 055b88d..5ec0c13 100644
--- a/atr/routes/keys.py
+++ b/atr/routes/keys.py
@@ -18,10 +18,7 @@
 """keys.py"""
 
 import asyncio
-import base64
-import binascii
 import datetime
-import hashlib
 from collections.abc import Awaitable, Callable, Sequence
 
 import aiohttp
@@ -321,30 +318,6 @@ async def import_selected_revision(
     )
 
 
-def key_ssh_fingerprint(ssh_key_string: str) -> str:
-    # The format should be as in *.pub or authorized_keys files
-    # I.e. TYPE DATA COMMENT
-    ssh_key_parts = ssh_key_string.strip().split()
-    if len(ssh_key_parts) >= 2:
-        # We discard the type, which is ssh_key_parts[0]
-        key_data = ssh_key_parts[1]
-        # We discard the comment, which is ssh_key_parts[2]
-
-        # Standard fingerprint calculation
-        try:
-            decoded_key_data = base64.b64decode(key_data)
-        except binascii.Error as e:
-            raise ValueError(f"Invalid base64 encoding in key data: {e}") from 
e
-
-        digest = hashlib.sha256(decoded_key_data).digest()
-        fingerprint_b64 = base64.b64encode(digest).decode("utf-8").rstrip("=")
-
-        # Prefix follows the standard format
-        return f"SHA256:{fingerprint_b64}"
-
-    raise ValueError("Invalid SSH key format")
-
-
 @routes.committer("/keys")
 async def keys(session: routes.CommitterSession) -> str:
     """View all keys associated with the user's account."""
@@ -413,7 +386,7 @@ async def ssh_add(session: routes.CommitterSession) -> 
response.Response | str:
 
 async def ssh_key_add(key: str, asf_uid: str) -> str:
     try:
-        fingerprint = key_ssh_fingerprint(key)
+        fingerprint = util.key_ssh_fingerprint(key)
     except Exception as e:
         raise SshFingerprintError(str(e)) from e
     async with db.session() as data:
diff --git a/atr/storage/writers/ssh.py b/atr/storage/writers/ssh.py
index 9ba656a..8a65d5e 100644
--- a/atr/storage/writers/ssh.py
+++ b/atr/storage/writers/ssh.py
@@ -22,8 +22,8 @@ import time
 
 import atr.db as db
 import atr.models.sql as sql
-import atr.routes.keys as keys
 import atr.storage as storage
+import atr.util as util
 
 
 class GeneralPublic:
@@ -74,7 +74,7 @@ class CommitteeParticipant(FoundationCommitter):
         # Twenty minutes to upload all files
         ttl = 20 * 60
         expires = now + ttl
-        fingerprint = keys.key_ssh_fingerprint(key)
+        fingerprint = util.key_ssh_fingerprint(key)
         wsk = sql.WorkflowSSHKey(
             fingerprint=fingerprint,
             key=key,
diff --git a/atr/util.py b/atr/util.py
index f84f140..ba707d6 100644
--- a/atr/util.py
+++ b/atr/util.py
@@ -16,6 +16,7 @@
 # under the License.
 
 import asyncio
+import base64
 import binascii
 import contextlib
 import dataclasses
@@ -523,6 +524,30 @@ def is_user_viewing_as_admin(uid: str | None) -> bool:
         return True
 
 
+def key_ssh_fingerprint(ssh_key_string: str) -> str:
+    # The format should be as in *.pub or authorized_keys files
+    # I.e. TYPE DATA COMMENT
+    ssh_key_parts = ssh_key_string.strip().split()
+    if len(ssh_key_parts) >= 2:
+        # We discard the type, which is ssh_key_parts[0]
+        key_data = ssh_key_parts[1]
+        # We discard the comment, which is ssh_key_parts[2]
+
+        # Standard fingerprint calculation
+        try:
+            decoded_key_data = base64.b64decode(key_data)
+        except binascii.Error as e:
+            raise ValueError(f"Invalid base64 encoding in key data: {e}") from 
e
+
+        digest = hashlib.sha256(decoded_key_data).digest()
+        fingerprint_b64 = base64.b64encode(digest).decode("utf-8").rstrip("=")
+
+        # Prefix follows the standard format
+        return f"SHA256:{fingerprint_b64}"
+
+    raise ValueError("Invalid SSH key format")
+
+
 async def number_of_release_files(release: sql.Release) -> int:
     """Return the number of files in a release."""
     if (path := release_directory_revision(release)) is None:


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to