Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve Galaxy api prefix when resource_provider is present #403

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading