Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions galaxy_ng/app/dynaconf_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 @@ -737,3 +738,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)
Loading