From 7bdf8dd60096d62c9d3bd2ffb5e5c65ac7f95877 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Thu, 14 Mar 2024 11:10:52 -0400 Subject: [PATCH] Utilize url from ANSIBLE_BASE_JWT_KEY to make Galaxy aware of the AAP proxy AAP-20998 No-Issue --- galaxy_ng/app/dynaconf_hooks.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/galaxy_ng/app/dynaconf_hooks.py b/galaxy_ng/app/dynaconf_hooks.py index e6390fd911..42f2c5b0f5 100755 --- a/galaxy_ng/app/dynaconf_hooks.py +++ b/galaxy_ng/app/dynaconf_hooks.py @@ -5,6 +5,7 @@ import os import re from typing import Any, Dict, List +from urllib.parse import urlparse, urlunparse from django_auth_ldap.config import LDAPSearch from dynaconf import Dynaconf, Validator from galaxy_ng.app.dynamic_settings import DYNAMIC_SETTINGS_SCHEMA @@ -41,6 +42,7 @@ def post(settings: Dynaconf) -> Dict[str, Any]: data.update(configure_api_base_path(settings)) data.update(configure_legacy_roles(settings)) data.update(configure_dab_resource_registry(settings)) + data.update(configure_aap_proxy(settings)) # This should go last, and it needs to receive the data from the previous configuration # functions because this function configures the rest framework auth classes based off @@ -578,6 +580,27 @@ def configure_legacy_roles(settings: Dynaconf) -> Dict[str, Any]: return data +def configure_aap_proxy(settings: Dynaconf) -> Dict[str, Any]: + ANSIBLE_BASE_JWT_KEY = settings.get("ANSIBLE_BASE_JWT_KEY") + if ANSIBLE_BASE_JWT_KEY: + data = { + "ANSIBLE_API_HOSTNAME": settings.get("ANSIBLE_API_HOSTNAME"), + "ANSIBLE_CONTENT_HOSTNAME": settings.get("ANSIBLE_CONTENT_HOSTNAME"), + } + gw_url = urlparse(ANSIBLE_BASE_JWT_KEY) + if gw_url.scheme and gw_url.hostname: + for k in data: + k_parsed = urlparse(data[k]) + if gw_url.scheme and gw_url.hostname: + k_updated = k_parsed._replace( + scheme=gw_url.scheme, + netloc=gw_url.netloc, + ) + data.update({k: urlunparse(k_updated)}) + return data + return {} + + def validate(settings: Dynaconf) -> None: """Validate the configuration, raise ValidationError if invalid""" settings.validators.register(