aboutsummaryrefslogtreecommitdiff
path: root/rpki/django_settings
diff options
context:
space:
mode:
Diffstat (limited to 'rpki/django_settings')
-rw-r--r--rpki/django_settings/common.py46
-rw-r--r--rpki/django_settings/irdb.py9
-rw-r--r--rpki/django_settings/pubd.py8
-rw-r--r--rpki/django_settings/rpkid.py8
4 files changed, 48 insertions, 23 deletions
diff --git a/rpki/django_settings/common.py b/rpki/django_settings/common.py
index d410d984..ef386cf0 100644
--- a/rpki/django_settings/common.py
+++ b/rpki/django_settings/common.py
@@ -50,11 +50,47 @@ if os.getenv("RPKI_DJANGO_DEBUG") == "yes":
DEBUG = True
-# Database configuration is handled in the modules that import this
-# one, as it differs from program to program. We tried using a Django
-# "database router" here, and it sort of worked, but it was a bit
-# fragile, tedious to use, and generally more complex than we need,
-# because any given program is only going to be using one database.
+# Database configuration differs from program to program, but includes
+# a lot of boilerplate. So we define a class here to handle this,
+# then use it and clean up in the modules that import from this one.
+
+class DatabaseConfigurator(object):
+
+ def configure(self, cfg, section):
+ self.cfg = cfg
+ self.section = section
+ return dict(default = getattr(self, cfg.get("sql-engine", section = section, default = "mysql"))())
+
+ def mysql(self):
+ return dict(
+ ENGINE = "django.db.backends.mysql",
+ NAME = cfg.get("sql-database", section = self.section),
+ USER = cfg.get("sql-username", section = self.section),
+ PASSWORD = cfg.get("sql-password", section = self.section),
+ #
+ # Using "latin1" here is totally evil and wrong, but
+ # without it MySQL 5.6 (and, probably, later versions)
+ # whine incessantly about bad UTF-8 characters when one
+ # stores ASN.1 DER in BLOB columns. Which makes no
+ # freaking sense at all, but this is MySQL, which has a
+ # character set management interface from hell, so good
+ # luck with that. If anybody really understands how to
+ # fix this, tell me; for now, we force MySQL to revert to
+ # the default behavior in MySQL 5.5.
+ #
+ OPTIONS = dict(charset = "latin1"))
+
+ def sqlite3(self):
+ return dict(
+ ENGINE = "django.db.backends.sqlite3",
+ NAME = cfg.get("sql-database", section = self.section))
+
+ def postgresql(self):
+ return dict(
+ ENGINE = "django.db.backends.postgresql_psycopg2",
+ NAME = cfg.get("sql-database", section = section),
+ USER = cfg.get("sql-username", section = section),
+ PASSWORD = cfg.get("sql-password", section = section))
# Apps are also handled by the modules that import this one, now that
diff --git a/rpki/django_settings/irdb.py b/rpki/django_settings/irdb.py
index 56ed92ff..2a49739b 100644
--- a/rpki/django_settings/irdb.py
+++ b/rpki/django_settings/irdb.py
@@ -28,12 +28,9 @@ __version__ = "$Id$"
# Database configuration.
-DATABASES = dict(
- default = dict(ENGINE = "django.db.backends.mysql",
- NAME = cfg.get("sql-database", section = "irdbd"),
- USER = cfg.get("sql-username", section = "irdbd"),
- PASSWORD = cfg.get("sql-password", section = "irdbd"),
- OPTIONS = dict(charset = "latin1")))
+DATABASES = DatabaseConfigurator().configure(cfg, "irdbd")
+del DatabaseConfigurator
+
# Apps.
diff --git a/rpki/django_settings/pubd.py b/rpki/django_settings/pubd.py
index 8539b8e5..0df0ddb9 100644
--- a/rpki/django_settings/pubd.py
+++ b/rpki/django_settings/pubd.py
@@ -26,12 +26,8 @@ __version__ = "$Id$"
# Database configuration.
-DATABASES = dict(
- default = dict(ENGINE = "django.db.backends.mysql",
- NAME = cfg.get("sql-database", section = "pubd"),
- USER = cfg.get("sql-username", section = "pubd"),
- PASSWORD = cfg.get("sql-password", section = "pubd"),
- OPTIONS = dict(charset = "latin1")))
+DATABASES = DatabaseConfigurator().configure(cfg, "pubd")
+del DatabaseConfigurator
# Apps.
diff --git a/rpki/django_settings/rpkid.py b/rpki/django_settings/rpkid.py
index 1c302b2e..70987315 100644
--- a/rpki/django_settings/rpkid.py
+++ b/rpki/django_settings/rpkid.py
@@ -26,12 +26,8 @@ __version__ = "$Id$"
# Database configuration.
-DATABASES = dict(
- default = dict(ENGINE = "django.db.backends.mysql",
- NAME = cfg.get("sql-database", section = "rpkid"),
- USER = cfg.get("sql-username", section = "rpkid"),
- PASSWORD = cfg.get("sql-password", section = "rpkid"),
- OPTIONS = dict(charset = "latin1")))
+DATABASES = DatabaseConfigurator().configure(cfg, "rpkid")
+del DatabaseConfigurator
# Apps.