Skip to content

Commit

Permalink
Utilize url from ANSIBLE_BASE_JWT_KEY to make Galaxy aware of the AAP…
Browse files Browse the repository at this point in the history
… proxy

AAP-20998
No-Issue
  • Loading branch information
bmclaughlin committed Apr 2, 2024
1 parent f3c93fc commit 7bdf8dd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions galaxy_ng/app/dynaconf_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7bdf8dd

Please sign in to comment.