From 94f20998af2087cfca93046ff180c33a848dda36 Mon Sep 17 00:00:00 2001 From: Daniel Sotirhos Date: Wed, 27 Nov 2024 10:40:04 -0800 Subject: [PATCH] Refactor get_duos() to return the DUOS ID --- src/azul/plugins/repository/tdr_anvil/__init__.py | 7 +++++-- src/azul/terra.py | 15 +++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/azul/plugins/repository/tdr_anvil/__init__.py b/src/azul/plugins/repository/tdr_anvil/__init__.py index b376636400..031b2264f3 100644 --- a/src/azul/plugins/repository/tdr_anvil/__init__.py +++ b/src/azul/plugins/repository/tdr_anvil/__init__.py @@ -479,8 +479,11 @@ def _supplementary_bundle(self, bundle_fqid: TDRAnvilBundleFQID) -> TDRAnvilBund def _duos_bundle(self, bundle_fqid: TDRAnvilBundleFQID) -> TDRAnvilBundle: assert not bundle_fqid.is_batched, bundle_fqid - duos_info = self.tdr.get_duos(bundle_fqid.source) - description = None if duos_info is None else duos_info.get('studyDescription') + duos_id, duos_info = self.tdr.get_duos(bundle_fqid.source) + if duos_info is None: + description = None + else: + description = duos_info.get('studyDescription') ref, row = self._get_dataset(bundle_fqid.source.spec) expected_entity_id = change_version(bundle_fqid.uuid, self.bundle_uuid_version, diff --git a/src/azul/terra.py b/src/azul/terra.py index e5046850a7..0ae3f870c4 100644 --- a/src/azul/terra.py +++ b/src/azul/terra.py @@ -646,19 +646,26 @@ def for_registered_user(cls, authentication: OAuth2) -> 'TDRClient': def drs_client(self) -> DRSClient: return DRSClient(http_client=self._http_client) - def get_duos(self, source: TDRSourceRef) -> Optional[MutableJSON]: + def get_duos(self, + source: TDRSourceRef + ) -> tuple[str | None, MutableJSON | None]: response = self._retrieve_source(source) try: duos_id = response['duosFirecloudGroup']['duosId'] except (KeyError, TypeError): log.warning('No DUOS ID available for %r', source.spec) - return None + return None, None else: url = self._duos_endpoint('dataset', 'registration', duos_id) response = self._request('GET', url) if response.status == 404: log.warning('No DUOS dataset registration with ID %r from %r', duos_id, source.spec) - return None + return None, None else: - return self._check_response(url, response) + response = self._check_response(url, response) + assert response['consentGroups'] + for consent_group in response['consentGroups']: + assert duos_id == consent_group['datasetIdentifier'], \ + (duos_id, consent_group['datasetIdentifier']) + return duos_id, response