Skip to content

Commit

Permalink
final touch + using forked dab
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Feb 10, 2025
1 parent 7cdfe26 commit 598a36d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 43 deletions.
3 changes: 1 addition & 2 deletions awx/api/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ def get_view_description(view, html=False):


def get_default_schema():
# TODO: get current_env
if settings.SETTINGS_MODULE == 'awx.settings.development':
if settings.DYNACONF.is_development_mode:
from awx.api.swagger import schema_view

return schema_view
Expand Down
1 change: 0 additions & 1 deletion awx/api/views/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class ApiVersionRootView(APIView):
def get(self, request, format=None):
'''List top level resources'''
data = OrderedDict()
data["foo"] = settings.FOO
data['ping'] = reverse('api:api_v2_ping_view', request=request)
data['instances'] = reverse('api:instance_list', request=request)
data['instance_groups'] = reverse('api:instance_group_list', request=request)
Expand Down
2 changes: 0 additions & 2 deletions awx/main/tests/settings_for_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Python
import uuid

# TODO: move to settings test

# Load development settings for base variables.
from awx.settings.development import * # NOQA

Expand Down
48 changes: 27 additions & 21 deletions awx/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# Copyright (c) 2015 Ansible, Inc.
# All Rights Reserved.
import os
from ansible_base.lib.dynamic_config import factory, export, load_standard_settings_files
from ansible_base.lib.dynamic_config import (
factory,
export,
load_envvars,
load_standard_settings_files,
validate,
)
from .application_name import merge_application_name
from dynaconf import Validator
from dynaconf.loaders import env_loader


# Create a the standard DYNACONF instance which will come with DAB defaults
# This loads defaults.py and environment specific file e.g: development_defaults.py
DYNACONF = factory(
__name__,
"AWX",
environments=("development", "production", "quiet", "kube"),
settings_files=["defaults.py"],
)
DYNACONF.validators.register(Validator("FOO", required=True, gt=99))

# Store snapshot before loading any custom config file
DEFAULTS_SNAPSHOT = {}
Expand All @@ -22,35 +27,36 @@
DYNACONF.as_dict(internal=False), # should use deepcopy here?
loader_identifier="awx.settings:DEFAULTS_SNAPSHOT",
)
###############################################################################################
#
##########################################################################################
# Any settings loaded after this point will be marked as as a read_only database setting
#
################################################################################################
##########################################################################################

# Load extra config
# Load extra config from the now deprecated /etc/tower/ directory
# This is only for backwards compatibility and will be removed in the future
# Load settings from any .py files in the global conf.d directory specified in
# the environment, defaulting to /etc/tower/conf.d/.
settings_dir = os.environ.get('AWX_SETTINGS_DIR', '/etc/tower/conf.d/')
settings_files_path = os.path.join(settings_dir, '*.py')
# Load remaining settings from the global settings file specified in the
# environment, defaulting to /etc/tower/settings.py.
settings_file_path = os.environ.get('AWX_SETTINGS_FILE', '/etc/tower/settings.py')
# Attempt to load settings from /etc/tower/settings.py first, followed by
# /etc/tower/conf.d/*.py.
settings_dir = os.environ.get('AWX_SETTINGS_DIR', '/etc/tower/conf.d/')
settings_files_path = os.path.join(settings_dir, '*.py')
settings_file_path = os.environ.get('AWX_SETTINGS_FILE', '/etc/tower/settings.py')
DYNACONF.load_file(settings_file_path)
DYNACONF.load_file(settings_files_path)

# Load new standard settings files from
# /etc/ansible-automation-platform/ and /etc/ansible-automation-platform/awx/
# this is to allow for a smoother transition from legacy (above) to new settings standard paths
load_standard_settings_files(DYNACONF)

# Load optional development only settings
if DYNACONF.get_environ("AWX_KUBE_DEVEL"):
DYNACONF.load_file("kube_defaults.py")
else:
DYNACONF.load_file("local_*.py")

# Load new standard settings files from /etc/ansible-automation-platform/config/awx/
load_standard_settings_files(DYNACONF)

# Check at least one required setting file has been loaded
# NOTE: This potentially could be moved to a validator
if "production" in DYNACONF.current_env.lower():
required_settings_paths = [
os.path.dirname(settings_file_path),
Expand All @@ -70,8 +76,8 @@
msg += 'specify an alternate path.'
raise ImproperlyConfigured(msg)

# Load envvars at the end to allow them to override everything
env_loader.load(DYNACONF, identifier="awx.settings")
# Load envvars at the end to allow them to override everything loaded so far
load_envvars(DYNACONF)

# This must run after all custom settings are imported
DYNACONF.update(
Expand All @@ -81,7 +87,7 @@
)

# Update django.conf.settings with DYNACONF keys.
export(DYNACONF)
export(__name__, DYNACONF)

# Validate the settings according to the validators registered
DYNACONF.validators.validate()
validate(DYNACONF)
8 changes: 0 additions & 8 deletions awx/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import socket
from datetime import timedelta

from split_settings.tools import include

FOO = 0
DEBUG = True
SQL_DEBUG = DEBUG

Expand Down Expand Up @@ -1012,11 +1009,6 @@
ANSIBLE_BASE_RESOURCE_CONFIG_MODULE = 'awx.resource_api'
ANSIBLE_BASE_PERMISSION_MODEL = 'main.Permission'

# TODO: Move this to the settings object from DAB
from ansible_base.lib import dynamic_config # noqa: E402

include(os.path.join(os.path.dirname(dynamic_config.__file__), 'dynamic_settings.py'))

# Add a postfix to the API URL patterns
# example if set to '' API pattern will be /api
# example if set to 'controller' API pattern will be /api AND /api/controller
Expand Down
15 changes: 7 additions & 8 deletions awx/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ def get_urlpatterns(prefix=None):
re_path(r'^(?!api/).*', include('awx.ui.urls', namespace='ui')),
]

# TODO: check current_env
# if settings.SETTINGS_MODULE == 'awx.settings.development':
# try:
# import debug_toolbar

# urlpatterns += [re_path(r'^__debug__/', include(debug_toolbar.urls))]
# except ImportError:
# pass
if settings.DYNACONF.is_development_mode:
try:
import debug_toolbar

urlpatterns += [re_path(r'^__debug__/', include(debug_toolbar.urls))]
except ImportError:
pass

return urlpatterns

Expand Down
3 changes: 2 additions & 1 deletion requirements/requirements_git.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
git+https://github.com/ansible/system-certifi.git@devel#egg=certifi
# Remove pbr from requirements.in when moving ansible-runner to requirements.in
git+https://github.com/ansible/ansible-runner.git@devel#egg=ansible-runner
django-ansible-base @ git+https://github.com/ansible/django-ansible-base@devel#egg=django-ansible-base[rest-filters,jwt_consumer,resource-registry,rbac]
# django-ansible-base @ git+https://github.com/ansible/django-ansible-base@devel#egg=django-ansible-base[rest-filters,jwt_consumer,resource-registry,rbac]
django-ansible-base @ git+https://github.com/rochacbruno/django-ansible-base@dynaconf_settings#egg=django-ansible-base[rest-filters,jwt_consumer,resource-registry,rbac,feature-flags]
awx-plugins-core @ git+https://github.com/ansible/awx-plugins.git@devel#egg=awx-plugins-core
awx_plugins.interfaces @ git+https://github.com/ansible/awx_plugins.interfaces.git

0 comments on commit 598a36d

Please sign in to comment.