Skip to content

Commit

Permalink
Use ANSIBLE_BASE_JWT_KEY to make Galaxy aware of Envoy (#2102)
Browse files Browse the repository at this point in the history
Utilize url from ANSIBLE_BASE_JWT_KEY to make Galaxy aware of the RESOURCE_PROVIDER
AAP-20998
No-Issue
  • Loading branch information
bmclaughlin authored Apr 25, 2024
1 parent ca0dd64 commit 3ed26c9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 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_resource_provider(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 @@ -582,6 +584,28 @@ def configure_legacy_roles(settings: Dynaconf) -> Dict[str, Any]:
return data


def configure_resource_provider(settings: Dynaconf) -> Dict[str, Any]:
# The following variable is either a URL or a key file path.
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 3ed26c9

Please sign in to comment.