only override django for FIPS in environments where Django is installed

isolated awx installs don't have this tooling, and so they don't need
this specific monkey-patch
This commit is contained in:
Ryan Petrello
2018-11-26 09:17:48 -05:00
parent d310c48988
commit 32e7ddd43a

View File

@@ -22,22 +22,28 @@ except ImportError: # pragma: no cover
import hashlib import hashlib
import django
from django.utils.encoding import force_bytes try:
from django.db.backends.base.schema import BaseDatabaseSchemaEditor import django
from django.db.backends.base import schema from django.utils.encoding import force_bytes
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.backends.base import schema
HAS_DJANGO = True
except ImportError:
HAS_DJANGO = False
# This line exists to make sure we don't regress on FIPS support if we if HAS_DJANGO is True:
# upgrade Django; if you're upgrading Django and see this error, # This line exists to make sure we don't regress on FIPS support if we
# update the version check below, and confirm that FIPS still works. # upgrade Django; if you're upgrading Django and see this error,
if django.__version__ != '1.11.16': # update the version check below, and confirm that FIPS still works.
if django.__version__ != '1.11.16':
raise RuntimeError("Django version other than 1.11.16 detected {}. \ raise RuntimeError("Django version other than 1.11.16 detected {}. \
Subclassing BaseDatabaseSchemaEditor is known to work for Django 1.11.16 \ Subclassing BaseDatabaseSchemaEditor is known to work for Django 1.11.16 \
and may not work in newer Django versions.".format(django.__version__)) and may not work in newer Django versions.".format(django.__version__))
class FipsBaseDatabaseSchemaEditor(BaseDatabaseSchemaEditor): class FipsBaseDatabaseSchemaEditor(BaseDatabaseSchemaEditor):
@classmethod @classmethod
def _digest(cls, *args): def _digest(cls, *args):
@@ -54,7 +60,7 @@ class FipsBaseDatabaseSchemaEditor(BaseDatabaseSchemaEditor):
return h.hexdigest()[:8] return h.hexdigest()[:8]
schema.BaseDatabaseSchemaEditor = FipsBaseDatabaseSchemaEditor schema.BaseDatabaseSchemaEditor = FipsBaseDatabaseSchemaEditor
def find_commands(management_dir): def find_commands(management_dir):