Skip to content

Commit

Permalink
Use GeoNode base URL when replacing service URLs (#228)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ricardo Garcia Silva authored Feb 9, 2022
1 parent 55b3efb commit 3347cc4
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions src/qgis_geonode/apiclient/geonode_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 3347cc4

Please sign in to comment.