Skip to content

Commit

Permalink
Merge pull request #417 from crim-ca/wps-server-url
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault authored Mar 17, 2022
2 parents 56fde68 + 1dc443f commit cb17e37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Changes:

Fixes:
------
- Fix `WPS 1/2` endpoint not reporting the appropriate instance URL
(fixes `#83 <https://github.com/crim-ca/weaver/issues/83>`_).
- Fix `CLI` ``deploy`` operation headers incorrectly passed down to the deployment request.

.. _changes_4.14.0:
Expand Down
34 changes: 18 additions & 16 deletions weaver/wps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ def _get_settings_or_wps_config(container, # type: AnySettingsC
config_setting_name, # type: str
default_not_found, # type: str
message_not_found, # type: str
load=False, # type: bool
): # type: (...) -> str

settings = get_settings(container)
found = settings.get(weaver_setting_name)
if not found:
if not settings.get("weaver.wps_configured"):
if not settings.get("weaver.wps_configured") and load:
load_pywps_config(container)
# not yet defined on first load permitted if settings retrieved early on
if pywps_config.CONFIG:
Expand All @@ -60,59 +61,59 @@ def _get_settings_or_wps_config(container, # type: AnySettingsC
return found.strip()


def get_wps_path(container):
# type: (AnySettingsContainer) -> str
def get_wps_path(container, load=True):
# type: (AnySettingsContainer, bool) -> str
"""
Retrieves the WPS path (without hostname).
Searches directly in settings, then `weaver.wps_cfg` file, or finally, uses the default values if not found.
"""
path = _get_settings_or_wps_config(container, "weaver.wps_path", "server", "url", "/ows/wps", "WPS path")
path = _get_settings_or_wps_config(container, "weaver.wps_path", "server", "url", "/ows/wps", "WPS path", load)
return urlparse(path).path


def get_wps_url(container):
# type: (AnySettingsContainer) -> str
def get_wps_url(container, load=True):
# type: (AnySettingsContainer, bool) -> str
"""
Retrieves the full WPS URL (hostname + WPS path).
Searches directly in settings, then `weaver.wps_cfg` file, or finally, uses the default values if not found.
"""
return get_settings(container).get("weaver.wps_url") or get_weaver_url(container) + get_wps_path(container)
return get_settings(container).get("weaver.wps_url") or get_weaver_url(container) + get_wps_path(container, load)


def get_wps_output_dir(container):
# type: (AnySettingsContainer) -> str
def get_wps_output_dir(container, load=True):
# type: (AnySettingsContainer, bool) -> str
"""
Retrieves the WPS output directory path where to write XML and result files.
Searches directly in settings, then `weaver.wps_cfg` file, or finally, uses the default values if not found.
"""
tmp_dir = tempfile.gettempdir()
return _get_settings_or_wps_config(container, "weaver.wps_output_dir",
"server", "outputpath", tmp_dir, "WPS output directory")
"server", "outputpath", tmp_dir, "WPS output directory", load)


def get_wps_output_path(container):
# type: (AnySettingsContainer) -> str
def get_wps_output_path(container, load=True):
# type: (AnySettingsContainer, bool) -> str
"""
Retrieves the WPS output path (without hostname) for staging XML status, logs and process outputs.
Searches directly in settings, then `weaver.wps_cfg` file, or finally, uses the default values if not found.
"""
return get_settings(container).get("weaver.wps_output_path") or urlparse(get_wps_output_url(container)).path
return get_settings(container).get("weaver.wps_output_path") or urlparse(get_wps_output_url(container, load)).path


def get_wps_output_url(container):
# type: (AnySettingsContainer) -> str
def get_wps_output_url(container, load=True):
# type: (AnySettingsContainer, bool) -> str
"""
Retrieves the WPS output URL that maps to WPS output directory path.
Searches directly in settings, then `weaver.wps_cfg` file, or finally, uses the default values if not found.
"""
wps_output_default = get_weaver_url(container) + "/wpsoutputs"
wps_output_config = _get_settings_or_wps_config(
container, "weaver.wps_output_url", "server", "outputurl", wps_output_default, "WPS output url"
container, "weaver.wps_output_url", "server", "outputurl", wps_output_default, "WPS output url", load
)
return wps_output_config or wps_output_default

Expand Down Expand Up @@ -434,6 +435,7 @@ def load_pywps_config(container, config=None):
pywps_config.CONFIG.set("server", "sethomedir", "true")
pywps_config.CONFIG.set("server", "outputpath", settings["weaver.wps_output_dir"])
pywps_config.CONFIG.set("server", "outputurl", settings["weaver.wps_output_url"])
pywps_config.CONFIG.set("server", "url", get_wps_url(settings, load=False))
settings["weaver.wps_configured"] = True
return pywps_config.CONFIG

Expand Down

0 comments on commit cb17e37

Please sign in to comment.