|
1 | 1 | # Copyright (c) 2015 Ansible, Inc.
|
2 | 2 | # All Rights Reserved.
|
3 | 3 | 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 | +) |
5 | 11 | from .application_name import merge_application_name
|
6 |
| -from dynaconf import Validator |
7 |
| -from dynaconf.loaders import env_loader |
8 |
| - |
9 | 12 |
|
| 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 |
10 | 15 | DYNACONF = factory(
|
| 16 | + __name__, |
11 | 17 | "AWX",
|
12 | 18 | environments=("development", "production", "quiet", "kube"),
|
13 | 19 | settings_files=["defaults.py"],
|
14 | 20 | )
|
15 |
| -DYNACONF.validators.register(Validator("FOO", required=True, gt=99)) |
16 | 21 |
|
17 | 22 | # Store snapshot before loading any custom config file
|
18 | 23 | DEFAULTS_SNAPSHOT = {}
|
|
22 | 27 | DYNACONF.as_dict(internal=False), # should use deepcopy here?
|
23 | 28 | loader_identifier="awx.settings:DEFAULTS_SNAPSHOT",
|
24 | 29 | )
|
25 |
| -############################################################################################### |
26 |
| -# |
| 30 | +########################################################################################## |
27 | 31 | # Any settings loaded after this point will be marked as as a read_only database setting
|
28 |
| -# |
29 |
| -################################################################################################ |
| 32 | +########################################################################################## |
30 | 33 |
|
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 |
32 | 36 | # Load settings from any .py files in the global conf.d directory specified in
|
33 | 37 | # 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') |
36 | 38 | # Load remaining settings from the global settings file specified in the
|
37 | 39 | # environment, defaulting to /etc/tower/settings.py.
|
38 |
| -settings_file_path = os.environ.get('AWX_SETTINGS_FILE', '/etc/tower/settings.py') |
39 | 40 | # Attempt to load settings from /etc/tower/settings.py first, followed by
|
40 | 41 | # /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') |
41 | 45 | DYNACONF.load_file(settings_file_path)
|
42 | 46 | DYNACONF.load_file(settings_files_path)
|
43 | 47 |
|
| 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 |
44 | 54 | if DYNACONF.get_environ("AWX_KUBE_DEVEL"):
|
45 | 55 | DYNACONF.load_file("kube_defaults.py")
|
46 | 56 | else:
|
47 | 57 | DYNACONF.load_file("local_*.py")
|
48 | 58 |
|
49 |
| -# Load new standard settings files from /etc/ansible-automation-platform/config/awx/ |
50 |
| -load_standard_settings_files(DYNACONF) |
51 |
| - |
52 | 59 | # Check at least one required setting file has been loaded
|
53 |
| -# NOTE: This potentially could be moved to a validator |
54 | 60 | if "production" in DYNACONF.current_env.lower():
|
55 | 61 | required_settings_paths = [
|
56 | 62 | os.path.dirname(settings_file_path),
|
|
70 | 76 | msg += 'specify an alternate path.'
|
71 | 77 | raise ImproperlyConfigured(msg)
|
72 | 78 |
|
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) |
75 | 81 |
|
76 | 82 | # This must run after all custom settings are imported
|
77 | 83 | DYNACONF.update(
|
|
81 | 87 | )
|
82 | 88 |
|
83 | 89 | # Update django.conf.settings with DYNACONF keys.
|
84 |
| -export(DYNACONF) |
| 90 | +export(__name__, DYNACONF) |
85 | 91 |
|
86 | 92 | # Validate the settings according to the validators registered
|
87 |
| -DYNACONF.validators.validate() |
| 93 | +validate(DYNACONF) |
0 commit comments