Skip to content

Commit 598a36d

Browse files
committed
final touch + using forked dab
1 parent 7cdfe26 commit 598a36d

File tree

7 files changed

+37
-43
lines changed

7 files changed

+37
-43
lines changed

awx/api/generics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ def get_view_description(view, html=False):
161161

162162

163163
def get_default_schema():
164-
# TODO: get current_env
165-
if settings.SETTINGS_MODULE == 'awx.settings.development':
164+
if settings.DYNACONF.is_development_mode:
166165
from awx.api.swagger import schema_view
167166

168167
return schema_view

awx/api/views/root.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class ApiVersionRootView(APIView):
6666
def get(self, request, format=None):
6767
'''List top level resources'''
6868
data = OrderedDict()
69-
data["foo"] = settings.FOO
7069
data['ping'] = reverse('api:api_v2_ping_view', request=request)
7170
data['instances'] = reverse('api:instance_list', request=request)
7271
data['instance_groups'] = reverse('api:instance_group_list', request=request)

awx/main/tests/settings_for_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Python
22
import uuid
33

4-
# TODO: move to settings test
5-
64
# Load development settings for base variables.
75
from awx.settings.development import * # NOQA
86

awx/settings/__init__.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# Copyright (c) 2015 Ansible, Inc.
22
# All Rights Reserved.
33
import os
4-
from ansible_base.lib.dynamic_config import factory, export, load_standard_settings_files
4+
from ansible_base.lib.dynamic_config import (
5+
factory,
6+
export,
7+
load_envvars,
8+
load_standard_settings_files,
9+
validate,
10+
)
511
from .application_name import merge_application_name
6-
from dynaconf import Validator
7-
from dynaconf.loaders import env_loader
8-
912

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

1722
# Store snapshot before loading any custom config file
1823
DEFAULTS_SNAPSHOT = {}
@@ -22,35 +27,36 @@
2227
DYNACONF.as_dict(internal=False), # should use deepcopy here?
2328
loader_identifier="awx.settings:DEFAULTS_SNAPSHOT",
2429
)
25-
###############################################################################################
26-
#
30+
##########################################################################################
2731
# Any settings loaded after this point will be marked as as a read_only database setting
28-
#
29-
################################################################################################
32+
##########################################################################################
3033

31-
# Load extra config
34+
# Load extra config from the now deprecated /etc/tower/ directory
35+
# This is only for backwards compatibility and will be removed in the future
3236
# Load settings from any .py files in the global conf.d directory specified in
3337
# the environment, defaulting to /etc/tower/conf.d/.
34-
settings_dir = os.environ.get('AWX_SETTINGS_DIR', '/etc/tower/conf.d/')
35-
settings_files_path = os.path.join(settings_dir, '*.py')
3638
# Load remaining settings from the global settings file specified in the
3739
# environment, defaulting to /etc/tower/settings.py.
38-
settings_file_path = os.environ.get('AWX_SETTINGS_FILE', '/etc/tower/settings.py')
3940
# Attempt to load settings from /etc/tower/settings.py first, followed by
4041
# /etc/tower/conf.d/*.py.
42+
settings_dir = os.environ.get('AWX_SETTINGS_DIR', '/etc/tower/conf.d/')
43+
settings_files_path = os.path.join(settings_dir, '*.py')
44+
settings_file_path = os.environ.get('AWX_SETTINGS_FILE', '/etc/tower/settings.py')
4145
DYNACONF.load_file(settings_file_path)
4246
DYNACONF.load_file(settings_files_path)
4347

48+
# Load new standard settings files from
49+
# /etc/ansible-automation-platform/ and /etc/ansible-automation-platform/awx/
50+
# this is to allow for a smoother transition from legacy (above) to new settings standard paths
51+
load_standard_settings_files(DYNACONF)
52+
53+
# Load optional development only settings
4454
if DYNACONF.get_environ("AWX_KUBE_DEVEL"):
4555
DYNACONF.load_file("kube_defaults.py")
4656
else:
4757
DYNACONF.load_file("local_*.py")
4858

49-
# Load new standard settings files from /etc/ansible-automation-platform/config/awx/
50-
load_standard_settings_files(DYNACONF)
51-
5259
# Check at least one required setting file has been loaded
53-
# NOTE: This potentially could be moved to a validator
5460
if "production" in DYNACONF.current_env.lower():
5561
required_settings_paths = [
5662
os.path.dirname(settings_file_path),
@@ -70,8 +76,8 @@
7076
msg += 'specify an alternate path.'
7177
raise ImproperlyConfigured(msg)
7278

73-
# Load envvars at the end to allow them to override everything
74-
env_loader.load(DYNACONF, identifier="awx.settings")
79+
# Load envvars at the end to allow them to override everything loaded so far
80+
load_envvars(DYNACONF)
7581

7682
# This must run after all custom settings are imported
7783
DYNACONF.update(
@@ -81,7 +87,7 @@
8187
)
8288

8389
# Update django.conf.settings with DYNACONF keys.
84-
export(DYNACONF)
90+
export(__name__, DYNACONF)
8591

8692
# Validate the settings according to the validators registered
87-
DYNACONF.validators.validate()
93+
validate(DYNACONF)

awx/settings/defaults.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import socket
1010
from datetime import timedelta
1111

12-
from split_settings.tools import include
13-
14-
FOO = 0
1512
DEBUG = True
1613
SQL_DEBUG = DEBUG
1714

@@ -1012,11 +1009,6 @@
10121009
ANSIBLE_BASE_RESOURCE_CONFIG_MODULE = 'awx.resource_api'
10131010
ANSIBLE_BASE_PERMISSION_MODEL = 'main.Permission'
10141011

1015-
# TODO: Move this to the settings object from DAB
1016-
from ansible_base.lib import dynamic_config # noqa: E402
1017-
1018-
include(os.path.join(os.path.dirname(dynamic_config.__file__), 'dynamic_settings.py'))
1019-
10201012
# Add a postfix to the API URL patterns
10211013
# example if set to '' API pattern will be /api
10221014
# example if set to 'controller' API pattern will be /api AND /api/controller

awx/urls.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ def get_urlpatterns(prefix=None):
3737
re_path(r'^(?!api/).*', include('awx.ui.urls', namespace='ui')),
3838
]
3939

40-
# TODO: check current_env
41-
# if settings.SETTINGS_MODULE == 'awx.settings.development':
42-
# try:
43-
# import debug_toolbar
44-
45-
# urlpatterns += [re_path(r'^__debug__/', include(debug_toolbar.urls))]
46-
# except ImportError:
47-
# pass
40+
if settings.DYNACONF.is_development_mode:
41+
try:
42+
import debug_toolbar
43+
44+
urlpatterns += [re_path(r'^__debug__/', include(debug_toolbar.urls))]
45+
except ImportError:
46+
pass
4847

4948
return urlpatterns
5049

requirements/requirements_git.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
git+https://github.com/ansible/system-certifi.git@devel#egg=certifi
22
# Remove pbr from requirements.in when moving ansible-runner to requirements.in
33
git+https://github.com/ansible/ansible-runner.git@devel#egg=ansible-runner
4-
django-ansible-base @ git+https://github.com/ansible/django-ansible-base@devel#egg=django-ansible-base[rest-filters,jwt_consumer,resource-registry,rbac]
4+
# django-ansible-base @ git+https://github.com/ansible/django-ansible-base@devel#egg=django-ansible-base[rest-filters,jwt_consumer,resource-registry,rbac]
5+
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]
56
awx-plugins-core @ git+https://github.com/ansible/awx-plugins.git@devel#egg=awx-plugins-core
67
awx_plugins.interfaces @ git+https://github.com/ansible/awx_plugins.interfaces.git

0 commit comments

Comments
 (0)