You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by sb...@apache.org on 2025/04/04 15:24:02 UTC
(tooling-trusted-release) branch main updated: Send vote announcement emails from user ASF addresses
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 b5f691a Send vote announcement emails from user ASF addresses
b5f691a is described below
commit b5f691a08f698c488373656ba64c5f3b75d519ea
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Fri Apr 4 16:20:44 2025 +0100
Send vote announcement emails from user ASF addresses
- Vote announcements are now sent from {USER}@apache.org.
- The user must be actually logged in via OAuth, so this is authenticated.
- We use the actual ASF DKIM selector.
- Outgoing email is signed with a Tooling test key, not the real ASF DKIM key.
- DKIM validation of outgoing email will fail, because a test key is used.
- Outgoing email is only ever sent to user-tests@tooling and no other destination.
- This commit also fixes a problem with displaying sent email Message-Id fields.
---
atr/mail.py | 35 ++++++++++++++++-------------------
atr/routes/candidate.py | 45 ++++++++++++++++++++++++++-------------------
atr/tasks/vote.py | 1 +
3 files changed, 43 insertions(+), 38 deletions(-)
diff --git a/atr/mail.py b/atr/mail.py
index 14ad402..169c9f7 100644
--- a/atr/mail.py
+++ b/atr/mail.py
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
+import dataclasses
import datetime
import email.utils as utils
import logging
@@ -32,11 +33,10 @@ _LOGGER = logging.getLogger(__name__)
# We could e.g. use uppercase instead of global_
# It's not always worth identifying globals as globals
# But in many cases we should do so
-# TODO: Get at least global_domain from configuration
+# TODO: Get at least global_dkim_domain from configuration
# And probably global_dkim_selector too
-global_dkim_selector: str = "202501"
-global_domain: str = "tooling-vm-ec2-de.apache.org"
-global_email_contact: str = f"contact@{global_domain}"
+global_dkim_selector: str = "mail"
+global_dkim_domain: str = "apache.org"
global_secret_key: str | None = None
_MAIL_RELAY: Final[str] = "mail-relay.apache.org"
@@ -44,31 +44,28 @@ _SMTP_PORT: Final[int] = 587
_SMTP_TIMEOUT: Final[int] = 30
+@dataclasses.dataclass
class VoteEvent:
- """Data class to represent a release vote event."""
-
- def __init__(
- self, release_name: str, email_recipient: str, subject: str, body: str, vote_end: datetime.datetime
- ) -> None:
- self.release_name = release_name
- self.email_recipient = email_recipient
- self.subject = subject
- self.body = body
- self.vote_end = vote_end
+ release_name: str
+ email_sender: str
+ email_recipient: str
+ subject: str
+ body: str
+ vote_end: datetime.datetime
async def send(event: VoteEvent) -> str:
"""Send an email notification about an artifact or a vote."""
_LOGGER.info(f"Sending email for event: {event}")
- from_addr = global_email_contact
- if not from_addr.endswith(f"@{global_domain}"):
- raise ValueError(f"from_addr must end with @{global_domain}, got {from_addr}")
+ from_addr = event.email_sender
+ if not from_addr.endswith(f"@{global_dkim_domain}"):
+ raise ValueError(f"from_addr must end with @{global_dkim_domain}, got {from_addr}")
to_addr = event.email_recipient
_validate_recipient(to_addr)
# UUID4 is entirely random, with no timestamp nor namespace
# It does have 6 version and variant bits, so only 122 bits are random
- mid = f"{uuid.uuid4()}@{global_domain}"
+ mid = f"{uuid.uuid4()}@{global_dkim_domain}"
msg_text = f"""
From: {from_addr}
To: {to_addr}
@@ -119,7 +116,7 @@ async def _send_many(from_addr: str, to_addrs: list[str], msg_text: str) -> None
sig = dkim.sign(
message=message_bytes,
selector=bytes(global_dkim_selector, "utf-8"),
- domain=bytes(global_domain, "utf-8"),
+ domain=bytes(global_dkim_domain, "utf-8"),
privkey=private_key,
include_headers=[b"From", b"To", b"Subject", b"Date", b"Message-ID"],
)
diff --git a/atr/routes/candidate.py b/atr/routes/candidate.py
index 49508c6..9683501 100644
--- a/atr/routes/candidate.py
+++ b/atr/routes/candidate.py
@@ -18,7 +18,6 @@
"""candidate.py"""
import json
-import logging
import aiofiles.os
import aioshutil
@@ -342,24 +341,7 @@ async def _resolve_get(session: routes.CommitterSession) -> str:
break
if latest_vote_task and (latest_vote_task.status == models.TaskStatus.COMPLETED) and latest_vote_task.result:
- try:
- # Result is stored as a JSON string
- # Handle that defensively
- if isinstance(latest_vote_task.result, str):
- parsed_result = json.loads(latest_vote_task.result)
- elif isinstance(latest_vote_task.result, dict):
- parsed_result = latest_vote_task.result
- else:
- parsed_result = {}
-
- if isinstance(parsed_result, dict):
- logging.info(f"Vote task result: {parsed_result}")
- task_mid = parsed_result.get("mid", "(mid not found in result)")
- else:
- task_mid = "(no result)"
-
- except (json.JSONDecodeError, TypeError):
- task_mid = "(malformed result)"
+ task_mid = _task_mid(latest_vote_task)
candidate_vote_tasks[candidate.name] = (latest_vote_task, task_mid)
@@ -444,3 +426,28 @@ async def _resolve_post_files(project_name: str, release: models.Release, vote_r
if await aiofiles.os.path.exists(target):
raise base.ASFQuartException("Release already exists", errorcode=400)
await aioshutil.move(source, target)
+
+
+def _task_mid(latest_vote_task: models.Task) -> str:
+ try:
+ # Result is stored as a JSON string
+ # Handle that defensively
+ if isinstance(latest_vote_task.result, str):
+ parsed_result = json.loads(latest_vote_task.result)
+ if not isinstance(parsed_result, list):
+ raise TypeError("Unexpected result type")
+ elif isinstance(latest_vote_task.result, list):
+ parsed_result = latest_vote_task.result
+ else:
+ raise TypeError("Unexpected result type")
+
+ task_mid = "(no result)"
+ for result in parsed_result:
+ if isinstance(result, dict):
+ task_mid = result.get("mid", "(mid not found in result)")
+ break
+
+ except (json.JSONDecodeError, TypeError):
+ task_mid = "(malformed result)"
+
+ return task_mid
diff --git a/atr/tasks/vote.py b/atr/tasks/vote.py
index 1494fbd..ef1bd56 100644
--- a/atr/tasks/vote.py
+++ b/atr/tasks/vote.py
@@ -126,6 +126,7 @@ async def _initiate_core_logic(args: Initiate) -> dict[str, Any]:
# Use test account instead of actual PMC list
event = mail.VoteEvent(
release_name=args.release_name,
+ email_sender=f"{args.initiator_id}@apache.org",
email_recipient=tooling_test_recipient,
subject=subject,
body=body,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org