diff --git a/config/settings/__init__.py b/config/settings/__init__.py index e1b6ddcda39b913da1c6a32fa286789bf936690e..ca525702058271303aa75914cde914de87fd45dd 100644 --- a/config/settings/__init__.py +++ b/config/settings/__init__.py @@ -16,24 +16,3 @@ Description of settings files: dev.py - defines settings for a development or testing server. Imports base.py settings and overrides/adds settings. """ - - -# Import either production or test settings -try: - from .local import IS_PRODUCTION_SERVER - if IS_PRODUCTION_SERVER: - settings_file = 'production' - else: - # If IS_PRODUCTION_SERVER is not defined, use development/test settings - settings_file = 'dev' -except ImportError: - # If local.py does not exist, use development/test settings - settings_file = 'dev' -settings_module = __import__(settings_file, globals(), locals()) - -# Put these settings into the local scope -for setting in dir(settings_module): - # Only add uppercase variables. We use lowercase as - # temporary variables in the settings files. - if setting == setting.upper(): - locals()[setting] = getattr(settings_module, setting) diff --git a/config/settings/base.py b/config/settings/base.py index 3c3dafe7b367509ad1875bf2ce7faca04b4e471e..220919192487f2e61b1125e9a82515fa2f254a92 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -1,15 +1,8 @@ +from cloghandler import ConcurrentRotatingFileHandler +from datetime import datetime, timedelta import os, time, logging from os.path import abspath, dirname, join -from datetime import datetime, timedelta -from cloghandler import ConcurrentRotatingFileHandler - -# Get local settings: -# SERVER_HOSTNAME, SERVER_FQDN, IS_PRODUCTION_SERVER, ADMINS, GRACEDB_PATHS -from .local import * -# Get secret settings: -# DEFAULT_DB_PASSWORD, DEFAULT_SECRET_KEY, TWILIO_ACCOUNT_SID, -# TWILIO_AUTH_TOKEN, TWIML_BIN -from .secret import * +import socket # Set up path to root of project BASE_DIR = abspath(join(dirname(__file__), "..", "..")) @@ -19,6 +12,10 @@ PROJECT_ROOT = join(BASE_DIR, "gracedb") # Other useful paths PROJECT_DATA_DIR = join(BASE_DIR, "..", "project_data") +# Server hostname and FQDN +SERVER_HOSTNAME = socket.gethostname() +SERVER_FQDN = socket.getfqdn() + # Unauthenticated access ------------------------------------------------------ # This variable controls whether unauthenticated access is allowed *ANYWHERE* # on this service, except the home page, which is always public. @@ -40,6 +37,9 @@ TEST_RUNNER = 'django.test.runner.DiscoverRunner' # ADMINS defines who gets code error notifications. # MANAGERS defines who gets broken link notifications when # BrokenLinkEmailsMiddleware is enabled +ADMINS = [ + ("Tanner Prestegard", "tanner.prestegard@ligo.org"), +] MANAGERS = ADMINS # Client versions allowed - pip-like specifier strings, @@ -55,6 +55,12 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') # Base URL for TwiML bins (for Twilio phone/text alerts) TWIML_BASE_URL = 'https://handler.twilio.com/twiml/' +# TwiML bin SIDs (for Twilio) +TWIML_BIN = { + 'create': 'EH761b6a35102737e3d21830a484a98a08', + 'label': 'EHb596a53b9c92a41950ce1a47335fd834', + 'test': 'EH6c0a168b0c6b011047afa1caeb49b241', +} # Use timezone-aware datetimes internally USE_TZ = True @@ -206,8 +212,6 @@ UPTIME_REPORT_DIR = PROJECT_DATA_DIR RATE_INFO_FILE = join(PROJECT_DATA_DIR, "rate_info.json") # URL prefix for serving report information (usually plots and tables) -# This is aliased to GRACEDB_PATHS["latency"] in the Apache virtualhost -# configuration. If you change this, you will need to change that. REPORT_INFO_URL_PREFIX = "/report_info/" # Directory for CBC IFAR Reports @@ -222,19 +226,6 @@ FEED_MAX_RESULTS = 50 # Django and server settings -------------------------------------------------- -# Nested dict of settings for all databases -DATABASES = { - 'default' : { - 'NAME' : 'gracedb', - 'ENGINE' : 'django.db.backends.mysql', - 'USER' : 'gracedb', - 'PASSWORD' : DEFAULT_DB_PASSWORD, - 'OPTIONS' : { - 'init_command': 'SET storage_engine=MyISAM', - }, - } -} - # Location of database GRACEDB_DATA_DIR = join(BASE_DIR, "..", "db_data") # First level subdirs with 2 chars, second level with 1 char @@ -252,10 +243,6 @@ CACHES = { } } -# Secret key for a Django installation -# Make this unique, and don't share it with anybody. -SECRET_KEY = DEFAULT_SECRET_KEY - # List of settings for all template engines. Each item is a dict # containing options for an individual engine TEMPLATES = [ diff --git a/config/settings/container.py b/config/settings/container.py new file mode 100644 index 0000000000000000000000000000000000000000..03ff8a9ace9d43a5b39d43a98681061c43e51c5f --- /dev/null +++ b/config/settings/container.py @@ -0,0 +1,38 @@ +# For running a containerized version of the service that gets secrets +# from environment variables. Builds on base.py settings. + +import os +from django.core.exceptions import ImproperlyConfigured +from .base import * + +# Get database password from environment and check +DB_PASSWORD = os.environ.get('DJANGO_DB_PASSWORD', None) +if DB_PASSWORD is None: + raise ImproperlyConfigured('Could not get database password from envvars.') + +# Secret key for a Django installation +SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', None) +if SECRET_KEY is None: + raise ImproperlyConfigured('Could not get secret key from envvars.') + +# Get Twilio account information from environment +# FIXME +TWILIO_ACCOUNT_SID = os.environ.get('DJANGO_TWILIO_ACCOUNT_SID', 'abcd') +TWILIO_AUTH_TOKEN = os.environ.get('DJANGO_TWILIO_AUTH_TOKEN', 'abcd') + +# Database settings +DATABASES = { + 'default' : { + 'NAME': 'gracedb', + 'ENGINE': 'django.db.backends.mysql', + 'USER': os.environ.get('DJANGO_DB_USER', 'gracedb'), + 'PASSWORD': DB_PASSWORD, + 'HOST': os.environ.get('DJANGO_DB_HOST', ''), + 'PORT': os.environ.get('DJANGO_DB_PORT', ''), + 'OPTIONS': { + 'init_command': 'SET storage_engine=MyISAM', + }, + } +} + + diff --git a/config/settings/dev.py b/config/settings/dev.py index 0685aa98dc91e6a48ad1ec94ae91c29f71587587..7c7d92d551d2b99a9dd8633399e4eb394b5d0eae 100644 --- a/config/settings/dev.py +++ b/config/settings/dev.py @@ -1,7 +1,8 @@ -# Settings for a test GraceDB instance. -# Starts with base.py settings and overrides or adds to them. -from .base import * +# Settings for a test/dev GraceDB instance running on a VM with Puppet +# provisioning. Starts with vm.py settings (which inherits from base.py +# settings) and overrides or adds to them. import socket +from .vm import * CONFIG_NAME = "TEST" @@ -45,5 +46,5 @@ if 'silk' in INSTALLED_APPS: # it to be used through this server. You need to configure a SOCKS proxy # on your local machine to use DJDT (see admin docs). INTERNAL_IPS = [ - socket.gethostbyname(socket.gethostname()), + socket.gethostbyname(SERVER_HOSTNAME), ] diff --git a/config/settings/production.py b/config/settings/production.py index f5d976d5065987684f63bb11f510a153738a05f9..678eaf19eb1b696be4c78fe73c051d4cafa97bb9 100644 --- a/config/settings/production.py +++ b/config/settings/production.py @@ -1,14 +1,7 @@ -# Settings for a production GraceDB instance. -# Starts with base.py settings and overrides or adds to them. -from .base import * - -# TP 12/22/2016: I don't think we need this anymore. -#SHIB_AUTHENTICATION_SESSION_INITIATOR = 'https://archie.phys.uwm.edu/Shibboleth.sso/Login' - -CONFIG_NAME = "PRODUCTION" - -# TP 12/22/2016: Doesn't seem to be used anywhere. -SITE_ID = 3 +# Settings for a production GraceDB instance running on a VM with Puppet +# provisioning. Starts with vm.py settings (which inherits from base.py +# settings) and overrides or adds to them. +from .vm import * # LVAlert Overseer settings ALERT_XMPP_SERVERS = ["lvalert.cgca.uwm.edu"] diff --git a/config/settings/vm.py b/config/settings/vm.py new file mode 100644 index 0000000000000000000000000000000000000000..7f823d3de4455771dedaf03d99ebb977834eefc5 --- /dev/null +++ b/config/settings/vm.py @@ -0,0 +1,24 @@ +# For running a VM that is provisioned by Puppet with +# a secret.py file for secret settings + +# Get secret settings: +# DEFAULT_DB_PASSWORD, DEFAULT_SECRET_KEY, TWILIO_ACCOUNT_SID, +# TWILIO_AUTH_TOKEN +from .base import * +from .secret import * + +# Nested dict of settings for all databases +DATABASES = { + 'default' : { + 'NAME': 'gracedb', + 'ENGINE': 'django.db.backends.mysql', + 'USER': 'gracedb', + 'PASSWORD': DEFAULT_DB_PASSWORD, + 'OPTIONS': { + 'init_command': 'SET storage_engine=MyISAM', + }, + } +} + +# Secret key for a Django installation +SECRET_KEY = DEFAULT_SECRET_KEY diff --git a/config/wsgi.py b/config/wsgi.py index 38eb90c54b58d8652096c26867f477998ca7afa4..d9e80a8a2adca45b5c846a2e1be17fbc19f22210 100644 --- a/config/wsgi.py +++ b/config/wsgi.py @@ -3,12 +3,12 @@ import sys from os.path import abspath, dirname, join # Parameters -SETTINGS_MODULE = 'config.settings' +DEFAULT_SETTINGS_MODULE = 'config.settings.dev' PROJECT_ROOT_NAME = 'gracedb' VENV_NAME = 'djangoenv' # Set DJANGO_SETTINGS_MODULE environment variable if not already set -os.environ.setdefault('DJANGO_SETTINGS_MODULE', SETTINGS_MODULE) +os.environ.setdefault('DJANGO_SETTINGS_MODULE', DEFAULT_SETTINGS_MODULE) # Set up base dir of repository BASE_DIR = abspath(join(dirname(__file__), "..")) diff --git a/manage.py b/manage.py index c0cd72c28e2625cc4f10b6c81dc8107fb8d033c4..e6f0036723059f777c523ec964e1ebddcc870cef 100755 --- a/manage.py +++ b/manage.py @@ -5,12 +5,12 @@ from os.path import abspath, dirname, join import sys # Parameters -SETTINGS_MODULE = 'config.settings' +DEFAULT_SETTINGS_MODULE = 'config.settings.dev' PROJECT_ROOT_NAME = 'gracedb' VENV_NAME = 'djangoenv' if __name__ == '__main__': - os.environ.setdefault('DJANGO_SETTINGS_MODULE', SETTINGS_MODULE) + os.environ.setdefault('DJANGO_SETTINGS_MODULE', DEFAULT_SETTINGS_MODULE) # Add the project root to the python path. BASE_DIR = abspath(dirname(__file__))