diff options
author | Rob Austein <sra@hactrn.net> | 2015-10-25 03:58:19 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2015-10-25 03:58:19 +0000 |
commit | a0da0a0088a8c8da50bd6b1ebb88277f58e88a81 (patch) | |
tree | bdbf8bab3788027288c49c4d3bb5e84d269049b2 | |
parent | afdeab028259c9cbab6112fe005a1e78c135fe43 (diff) |
Make SQL engine configurable. Works for MySQL, not yet tested for anything else.
svn path=/branches/tk705/; revision=6147
-rw-r--r-- | ca/rpki-confgen.xml | 81 | ||||
-rw-r--r-- | rpki/django_settings/common.py | 46 | ||||
-rw-r--r-- | rpki/django_settings/irdb.py | 9 | ||||
-rw-r--r-- | rpki/django_settings/pubd.py | 8 | ||||
-rw-r--r-- | rpki/django_settings/rpkid.py | 8 |
5 files changed, 118 insertions, 34 deletions
diff --git a/ca/rpki-confgen.xml b/ca/rpki-confgen.xml index 63e9d793..c100b7b9 100644 --- a/ca/rpki-confgen.xml +++ b/ca/rpki-confgen.xml @@ -282,11 +282,25 @@ </doc> </option> + <option name = "shared_sql_engine" + value = "mysql"> + <doc> + Database engine to use. Default is MySQL, because that's what + we've been using for years. Now that all runtime database + access is via Django ORM, changing to another engine supported + by Django is just a configuration issue. + </doc> + <doc> + Current supported values are "mysql" (the default), "sqlite3", + and "postgresql". + </doc> + </option> + <option name = "shared_sql_username" value = "rpki"> <doc> If you're comfortable with having all of the databases use the - same MySQL username, set that value here. The default setting + same SQL username, set that value here. The default setting of this variable should be fine. </doc> </option> @@ -294,7 +308,7 @@ <option name = "shared_sql_password"> <doc> If you're comfortable with having all of the databases use the - same MySQL password, set that value here. You should use a + same SQL password, set that value here. You should use a locally generated password either here or in the individual settings below. The installation process generates a random value for this option, which satisfies this requirement, so @@ -302,6 +316,14 @@ </doc> </option> + <option name = "rpkid_sql_engine" + value = "${myrpki::shared_sql_engine}"> + <doc> + SQL engine to use for rpkid's database. The default setting + of this variable should be fine. + </doc> + </option> + <option name = "rpkid_sql_database" value = "rpkid"> <doc> @@ -326,6 +348,14 @@ </doc> </option> + <option name = "irdbd_sql_engine" + value = "${myrpki::shared_sql_engine}"> + <doc> + SQL engine to use for irdbd's database. The default setting + of this variable should be fine. + </doc> + </option> + <option name = "irdbd_sql_database" value = "irdbd"> <doc> @@ -350,6 +380,14 @@ </doc> </option> + <option name = "pubd_sql_engine" + value = "${myrpki::shared_sql_engine}"> + <doc> + SQL engine to use for pubd's database. The default setting + of this variable should be fine. + </doc> + </option> + <option name = "pubd_sql_database" value = "pubd"> <doc> @@ -385,24 +423,31 @@ Certificates and keys may be in either DER or PEM format. </doc> + <option name = "sql-engine" + value = "${myrpki::rpkid_sql_engine}"> + <doc> + SQL engine for rpkid. + </doc> + </option> + <option name = "sql-database" value = "${myrpki::rpkid_sql_database}"> <doc> - MySQL database name for rpkid. + SQL database name for rpkid. </doc> </option> <option name = "sql-username" value = "${myrpki::rpkid_sql_username}"> <doc> - MySQL user name for rpkid. + SQL user name for rpkid. </doc> </option> <option name = "sql-password" value = "${myrpki::rpkid_sql_password}"> <doc> - MySQL password for rpkid. + SQL password for rpkid. </doc> </option> @@ -490,24 +535,31 @@ configuration than the other daemons. </doc> + <option name = "sql-engine" + value = "${myrpki::irdbd_sql_engine}"> + <doc> + SQL engine for irdbd. + </doc> + </option> + <option name = "sql-database" value = "${myrpki::irdbd_sql_database}"> <doc> - MySQL database name for irdbd. + SQL database name for irdbd. </doc> </option> <option name = "sql-username" value = "${myrpki::irdbd_sql_username}"> <doc> - MySQL user name for irdbd. + SQL user name for irdbd. </doc> </option> <option name = "sql-password" value = "${myrpki::irdbd_sql_password}"> <doc> - MySQL password for irdbd. + SQL password for irdbd. </doc> </option> @@ -543,24 +595,31 @@ BPKI certificates and keys may be either DER or PEM format. </doc> + <option name = "sql-engine" + value = "${myrpki::pubd_sql_engine}"> + <doc> + SQL engine for pubd. + </doc> + </option> + <option name = "sql-database" value = "${myrpki::pubd_sql_database}"> <doc> - MySQL database name for pubd. + SQL database name for pubd. </doc> </option> <option name = "sql-username" value = "${myrpki::pubd_sql_username}"> <doc> - MySQL user name for pubd. + SQL user name for pubd. </doc> </option> <option name = "sql-password" value = "${myrpki::pubd_sql_password}"> <doc> - MySQL password for pubd. + SQL password for pubd. </doc> </option> 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. |