|
5 | 5 | import os
|
6 | 6 | import re
|
7 | 7 | from typing import Any, Dict, List
|
| 8 | +from urllib.parse import urlparse, urlunparse |
8 | 9 | from django_auth_ldap.config import LDAPSearch
|
9 | 10 | from dynaconf import Dynaconf, Validator
|
10 | 11 | from galaxy_ng.app.dynamic_settings import DYNAMIC_SETTINGS_SCHEMA
|
@@ -41,6 +42,7 @@ def post(settings: Dynaconf) -> Dict[str, Any]:
|
41 | 42 | data.update(configure_api_base_path(settings))
|
42 | 43 | data.update(configure_legacy_roles(settings))
|
43 | 44 | data.update(configure_dab_resource_registry(settings))
|
| 45 | + data.update(configure_resource_provider(settings)) |
44 | 46 |
|
45 | 47 | # This should go last, and it needs to receive the data from the previous configuration
|
46 | 48 | # functions because this function configures the rest framework auth classes based off
|
@@ -582,6 +584,28 @@ def configure_legacy_roles(settings: Dynaconf) -> Dict[str, Any]:
|
582 | 584 | return data
|
583 | 585 |
|
584 | 586 |
|
| 587 | +def configure_resource_provider(settings: Dynaconf) -> Dict[str, Any]: |
| 588 | + # The following variable is either a URL or a key file path. |
| 589 | + ANSIBLE_BASE_JWT_KEY = settings.get("ANSIBLE_BASE_JWT_KEY") |
| 590 | + if ANSIBLE_BASE_JWT_KEY: |
| 591 | + data = { |
| 592 | + "ANSIBLE_API_HOSTNAME": settings.get("ANSIBLE_API_HOSTNAME"), |
| 593 | + "ANSIBLE_CONTENT_HOSTNAME": settings.get("ANSIBLE_CONTENT_HOSTNAME"), |
| 594 | + } |
| 595 | + gw_url = urlparse(ANSIBLE_BASE_JWT_KEY) |
| 596 | + if gw_url.scheme and gw_url.hostname: |
| 597 | + for k in data: |
| 598 | + k_parsed = urlparse(data[k]) |
| 599 | + if gw_url.scheme and gw_url.hostname: |
| 600 | + k_updated = k_parsed._replace( |
| 601 | + scheme=gw_url.scheme, |
| 602 | + netloc=gw_url.netloc, |
| 603 | + ) |
| 604 | + data.update({k: urlunparse(k_updated)}) |
| 605 | + return data |
| 606 | + return {} |
| 607 | + |
| 608 | + |
585 | 609 | def validate(settings: Dynaconf) -> None:
|
586 | 610 | """Validate the configuration, raise ValidationError if invalid"""
|
587 | 611 | settings.validators.register(
|
|
0 commit comments