Skip to content

Commit

Permalink
Add logic to retrieve Galaxy api prefix when resource_provider is pre…
Browse files Browse the repository at this point in the history
…sent (#403)
  • Loading branch information
bmclaughlin authored Jun 5, 2024
1 parent f8463c3 commit 548c17e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelogs/fragments/api_prefix_with_resource_provider.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
minor_changes:
- Retrieves Galaxy api prefix when resource_provider is present, defaults to existing behavior.
...
31 changes: 30 additions & 1 deletion plugins/module_utils/ah_api_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self, argument_spec, direct_params=None, **kwargs):
self.session = Request(validate_certs=self.verify_ssl, headers=self.headers, follow_redirects=True, timeout=self.request_timeout)

# Define the API paths
self.galaxy_path_prefix = "/api/{prefix}".format(prefix=self.path_prefix.strip("/"))
self.galaxy_path_prefix = self.get_galaxy_path_prefix()
self.ui_path_prefix = "{galaxy_prefix}/_ui/v1".format(galaxy_prefix=self.galaxy_path_prefix)
self.plugin_path_prefix = "{galaxy_prefix}/v3/plugin".format(galaxy_prefix=self.galaxy_path_prefix)
self.authenticate()
Expand Down Expand Up @@ -486,6 +486,35 @@ def exit_json(self, **kwargs):
self.logout()
super(AHAPIModule, self).exit_json(**kwargs)

def get_galaxy_path_prefix(self):
"""Return the automation hub/galaxy path prefix
:return: '/api/{prefix}' unless behind resource_server wherein the api path prefix may differ.
resource_server expected response structure:
{
"description": "",
"apis": {
"galaxy": "/api/galaxy/"
}
}
:rtype: String
"""

url = self._build_url(prefix="api", endpoint=None, query_params=None)

try:
response = self.make_request("GET", url)
except AHAPIModuleError as e:
self.fail_json(msg="Error while contacting server for Galaxy path prefix: {error} \nurl: {url}".format(error=e, url=url))
if response["status_code"] == 404:
return "/api/{prefix}".format(prefix=self.path_prefix.strip("/"))
else:
try:
rs_prefix = response["json"]["apis"]["galaxy"]
except KeyError as e:
self.fail_json(msg="Error while getting Galaxy api path prefix: {error}".format(error=e))
return rs_prefix.strip("/")

def get_server_version(self):
"""Return the automation hub/galaxy server version.
Expand Down

0 comments on commit 548c17e

Please sign in to comment.