Skip to content

Commit

Permalink
Load required settings from django-ansible-base if not set. (ansible#…
Browse files Browse the repository at this point in the history
…2176)

* Load required settings from django-ansible-base if not set.

No-Issue
  • Loading branch information
rochacbruno authored Jun 18, 2024
1 parent db23c5c commit 2986b15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions galaxy_ng/app/dynaconf_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def post(settings: Dynaconf) -> Dict[str, Any]:
data.update(configure_password_validators(settings))
data.update(configure_api_base_path(settings))
data.update(configure_legacy_roles(settings))
data.update(configure_dab_required_settings(settings))
data.update(configure_resource_provider(settings))

# This should go last, and it needs to receive the data from the previous configuration
Expand Down Expand Up @@ -750,3 +751,14 @@ def alter_hostname_settings(
Action.AFTER_GET: hook_functions
}
}


def configure_dab_required_settings(settings: Dynaconf) -> Dict[str, Any]:
"""Load all keys defined on dab dynamic_settings if not already defined."""
data = {}
notset = object()
from ansible_base.lib.dynamic_config import dynamic_settings
for key in dir(dynamic_settings):
if key.isupper() and settings.get(key, notset) is notset:
data[key] = getattr(dynamic_settings, key)
return data
15 changes: 15 additions & 0 deletions galaxy_ng/tests/unit/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.test import TestCase
from django.conf import settings
from ansible_base.lib.dynamic_config import dynamic_settings


DAB_REQUIRED_SETTINGS = [key for key in dir(dynamic_settings) if key.isupper()]


class TestSetting(TestCase):
def test_dab_settings_are_loaded(self):
"""Ensure all required settings from DAB are configured on Galaxy"""
notset = object()
for key in DAB_REQUIRED_SETTINGS:
key_on_galaxy = settings.get(key, notset)
self.assertIsNot(key_on_galaxy, notset)

0 comments on commit 2986b15

Please sign in to comment.