server: validate that settings.yaml exists before bootstrapping
Otherwise, if settings.yaml could not be read, the server would silently fall back to the default settings. Now the server will refuse to start with a descriptive error message if the settings.yaml file doesn't exist or can't be accessed. Fixes: https://github.com/ansible-community/ara/issues/117 Change-Id: I8ac3001b7b19ead619ee911e19cb210a347f1c0a
This commit is contained in:
parent
821b0fe880
commit
c86758350a
|
@ -21,7 +21,12 @@ import sys
|
|||
|
||||
from django.conf import settings
|
||||
|
||||
from ara.setup.exceptions import MissingDjangoException, MissingMysqlclientException, MissingPsycopgException
|
||||
from ara.setup.exceptions import (
|
||||
MissingDjangoException,
|
||||
MissingMysqlclientException,
|
||||
MissingPsycopgException,
|
||||
MissingSettingsException,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -32,6 +37,12 @@ def main():
|
|||
except ImportError as e:
|
||||
raise MissingDjangoException from e
|
||||
|
||||
# Validate that the settings file exists and is readable before bootstrapping
|
||||
if not os.path.exists(settings.ARA_SETTINGS):
|
||||
print("[ara] Unable to access or read settings file: %s" % settings.ARA_SETTINGS)
|
||||
raise MissingSettingsException
|
||||
print("[ara] Using settings file: %s" % settings.ARA_SETTINGS)
|
||||
|
||||
if settings.DATABASE_ENGINE == "django.db.backends.postgresql":
|
||||
try:
|
||||
import psycopg2 # noqa
|
||||
|
@ -45,7 +56,6 @@ def main():
|
|||
raise MissingMysqlclientException from e
|
||||
|
||||
execute_from_command_line(sys.argv)
|
||||
print("[ara] Using settings file: %s" % settings.ARA_SETTINGS)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -32,3 +32,9 @@ class MissingMysqlclientException(Exception):
|
|||
def __init__(self):
|
||||
exc = "The mysqlclient python library must be installed in order to use the MySQL database engine."
|
||||
super().__init__(exc)
|
||||
|
||||
|
||||
class MissingSettingsException(Exception):
|
||||
def __init__(self):
|
||||
exc = "The specified settings file does not exist or permissions are insufficient to read it."
|
||||
super().__init__(exc)
|
||||
|
|
Loading…
Reference in New Issue