From 3347cc4780fc9bac8ca5e353ce3a8702d1d7efa4 Mon Sep 17 00:00:00 2001 From: Ricardo Garcia Silva Date: Wed, 9 Feb 2022 18:00:46 +0000 Subject: [PATCH] Use GeoNode base URL when replacing service URLs (#228) When using the GeoNode proxy to GeoServer we need to ensure we are referring to the GeoNode base URL and not whatever URL is GeoServer's base --- src/qgis_geonode/apiclient/geonode_v3.py | 47 +++++++++++------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/qgis_geonode/apiclient/geonode_v3.py b/src/qgis_geonode/apiclient/geonode_v3.py index a1dc7e10..8768bb6c 100644 --- a/src/qgis_geonode/apiclient/geonode_v3.py +++ b/src/qgis_geonode/apiclient/geonode_v3.py @@ -135,9 +135,9 @@ def handle_dataset_list(self, task_result: bool) -> None: try: parsed_properties = self._get_common_model_properties(raw_brief_ds) brief_dataset = models.BriefDataset(**parsed_properties) - except ValueError: + except ValueError as exc: log( - f"Could not parse {raw_brief_ds!r} into a valid item", + f"Could not parse {raw_brief_ds!r} into a valid item: {str(exc)}", debug=False, ) else: @@ -237,6 +237,19 @@ def _retrieve_response( error_signal[str].emit("Could not complete network request") return result + def _get_sld_url(self, raw_style: typing.Dict) -> typing.Optional[str]: + auth_manager = qgis.core.QgsApplication.authManager() + auth_provider_name = auth_manager.configAuthMethodKey(self.auth_config).lower() + sld_url = raw_style.get("sld_url") + if auth_provider_name == "basic": + try: + prefix, suffix = sld_url.partition("geoserver")[::2] + sld_url = f"{self.base_url}/gs{suffix}" + log(f"sld_url: {sld_url}") + except AttributeError: + pass + return sld_url + def _get_common_model_properties(self, raw_dataset: typing.Dict) -> typing.Dict: raise NotImplementedError @@ -327,17 +340,6 @@ def handle_layer_upload(self, result: bool): "Could not upload layer to GeoNode" ) - def _get_sld_url(self, raw_style: typing.Dict) -> typing.Optional[str]: - auth_manager = qgis.core.QgsApplication.authManager() - auth_provider_name = auth_manager.configAuthMethodKey(self.auth_config).lower() - sld_url = raw_style.get("sld_url") - if auth_provider_name == "basic": - try: - sld_url = sld_url.replace("geoserver", "gs") - except AttributeError: - pass - return sld_url - def _get_service_urls( self, raw_links: typing.Dict, @@ -356,7 +358,9 @@ def _get_service_urls( if auth_provider_name == "basic": for service_type, retrieved_url in result.items(): try: - result[service_type] = retrieved_url.replace("geoserver", "gs") + prefix, suffix = retrieved_url.partition("geoserver")[::2] + result[service_type] = f"{self.base_url}/gs{suffix}" + log(f"result[service_type]: {self.base_url}/gs{suffix}") except AttributeError: pass return result @@ -454,17 +458,6 @@ def build_search_query( query.removeQueryItem(subtype_key) return query - def _get_sld_url(self, raw_style: typing.Dict) -> typing.Optional[str]: - auth_manager = qgis.core.QgsApplication.authManager() - auth_provider_name = auth_manager.configAuthMethodKey(self.auth_config).lower() - sld_url = raw_style.get("sld_url") - if auth_provider_name == "basic": - try: - sld_url = sld_url.replace("geoserver", "gs") - except AttributeError: - pass - return sld_url - def _get_service_urls( self, raw_dataset: typing.Dict, @@ -485,7 +478,9 @@ def _get_service_urls( if auth_provider_name == "basic": for service_type, retrieved_url in result.items(): try: - result[service_type] = retrieved_url.replace("geoserver", "gs") + prefix, suffix = retrieved_url.partition("geoserver")[::2] + result[service_type] = f"{self.base_url}/gs{suffix}" + log(f"result[service_type]: {self.base_url}/gs{suffix}") except AttributeError: pass return result