fix: send the full webhook and skip /users/me in the point alarm register client

The backend requires a webhook with a delivery policy on every point alarm register call and resolves the account from the caller, so the register client no longer calls /v1/users/me (account is null for some users), no longer sends the accountId-only webhook and no longer relies on IKLIM_WEBHOOK_INITIALIZED.
This commit is contained in:
2026-10-23 19:45:02 +03:00
parent f04fd728e0
commit e17c06da4a
4 changed files with 17 additions and 22 deletions
+7 -14
View File
@@ -18,10 +18,8 @@ from uuid import uuid4
from common import ApiError, ConfigurationError, IklimClient
from common.client import ApiResponse
from common.client import RETRYABLE_STATUS_CODES
from common.config import env_bool
from nowcast_common import (
as_uuid,
fetch_account_id,
load_webhook_config,
read_json_object,
response_warnings,
@@ -355,9 +353,6 @@ class PointAlarmService:
def __init__(self, client: IklimClient) -> None:
self.client = client
def get_account_id(self) -> str:
return fetch_account_id(self.client)
def page(
self,
*,
@@ -652,10 +647,11 @@ class PointRegistrationProcessor:
def run(self) -> None:
rows, fieldnames = self._read_csv()
filters = load_point_alarm_filter(self.filter_config_path)
webhook_initialized = env_bool("IKLIM_WEBHOOK_INITIALIZED", False)
full_webhook = None if webhook_initialized else load_webhook_config(self.webhook_config_path)
account_id = self.service.get_account_id()
LOGGER.info("Kullanıcı hesabı doğrulandı; accountId API'den alındı.")
# The backend requires a webhook with a delivery policy on every register call; it reuses
# the account's stored webhook and resolves the account from the caller, so accountId is not sent.
webhook = load_webhook_config(self.webhook_config_path)
if not isinstance(webhook.get("deliveryPolicy"), dict):
raise ConfigurationError("Nokta alarm kaydı için webhook.deliveryPolicy zorunludur.")
for row_number, row in enumerate(rows, start=2):
if str(row.get("status", "")).strip().upper() == "SUCCESS":
LOGGER.info("Satır %s zaten SUCCESS; atlandı.", row_number)
@@ -670,13 +666,10 @@ class PointRegistrationProcessor:
payload = {
"recipientId": recipient_id,
"boundary": {"point": {"lat": lat, "lng": lng}, "radius": radius},
"webhook": {"accountId": account_id} if webhook_initialized else deepcopy(full_webhook),
"webhook": deepcopy(webhook),
"filter": deepcopy(filters),
}
registered = self._register(row_number, payload, row)
if registered and not webhook_initialized:
webhook_initialized = True
self.service.client.token_store.set_webhook_initialized(True)
self._register(row_number, payload, row)
self._write_csv(rows, fieldnames)
def _register(self, row_number: int, payload: dict[str, Any], row: dict[str, Any]) -> bool: