diff --git a/backend/pashub_fetcher/pashub_service.py b/backend/pashub_fetcher/pashub_service.py index 2b8f0926..0a5fb535 100644 --- a/backend/pashub_fetcher/pashub_service.py +++ b/backend/pashub_fetcher/pashub_service.py @@ -44,12 +44,26 @@ class PashubService: self._coordination_client_factory = coordination_client_factory self._coordination_client: Optional[PashubClient] = None + def _get_coordination_client(self) -> PashubClient: + if self._coordination_client_factory is None: + raise UnauthorizedError("No coordination client factory configured") + if self._coordination_client is None: + self._coordination_client = self._coordination_client_factory() + return self._coordination_client + def run(self, request: PashubToAraTriggerRequest) -> List[str]: job_id = request.pashub_job_id + active_client = self._pashub_client + + if request.uprn: + uprn: Optional[str] = request.uprn + else: + try: + uprn = active_client.get_uprn_by_job_id(job_id) + except UnauthorizedError: + active_client = self._get_coordination_client() + uprn = active_client.get_uprn_by_job_id(job_id) - uprn: Optional[str] = request.uprn or self._pashub_client.get_uprn_by_job_id( - job_id - ) hubspot_deal_id: Optional[str] = request.hubspot_deal_id if uprn: @@ -57,7 +71,7 @@ class PashubService: else: logger.info(f"No UPRN found for job {job_id}") - job_files: List[str] = self._pashub_client.get_core_evidence_files_by_job_id( + job_files: List[str] = active_client.get_core_evidence_files_by_job_id( job_id )