mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Update the monkey patch of Django's column name digest to work with 2.0+
BaseDatabaseSchemaEditor no longer has a `_digest` classmethod, instead there is a call out to a new `names_digest` utility function.
This commit is contained in:
@@ -26,8 +26,8 @@ import hashlib
|
|||||||
try:
|
try:
|
||||||
import django
|
import django
|
||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
|
||||||
from django.db.backends.base import schema
|
from django.db.backends.base import schema
|
||||||
|
from django.db.backends.utils import names_digest
|
||||||
HAS_DJANGO = True
|
HAS_DJANGO = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_DJANGO = False
|
HAS_DJANGO = False
|
||||||
@@ -37,30 +37,33 @@ if HAS_DJANGO is True:
|
|||||||
# This line exists to make sure we don't regress on FIPS support if we
|
# This line exists to make sure we don't regress on FIPS support if we
|
||||||
# upgrade Django; if you're upgrading Django and see this error,
|
# upgrade Django; if you're upgrading Django and see this error,
|
||||||
# update the version check below, and confirm that FIPS still works.
|
# update the version check below, and confirm that FIPS still works.
|
||||||
if django.__version__ != '1.11.20':
|
# If operating in a FIPS environment, `hashlib.md5()` will raise a `ValueError`,
|
||||||
raise RuntimeError("Django version other than 1.11.20 detected {}. \
|
# but will support the `usedforsecurity` keyword on RHEL and Centos systems.
|
||||||
Subclassing BaseDatabaseSchemaEditor is known to work for Django 1.11.20 \
|
|
||||||
and may not work in newer Django versions.".format(django.__version__))
|
|
||||||
|
|
||||||
|
# Keep an eye on https://code.djangoproject.com/ticket/28401
|
||||||
|
target_version = '2.0.13'
|
||||||
|
if django.__version__ != target_version:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Django version other than {target} detected: {current}. "
|
||||||
|
"Overriding `names_digest` is known to work for Django {target} "
|
||||||
|
"and may not work in other Django versions.".format(target=target_version,
|
||||||
|
current=django.__version__)
|
||||||
|
)
|
||||||
|
|
||||||
class FipsBaseDatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
try:
|
||||||
|
names_digest('foo', 'bar', 'baz', length=8)
|
||||||
@classmethod
|
except ValueError:
|
||||||
def _digest(cls, *args):
|
def names_digest(*args, length):
|
||||||
"""
|
"""
|
||||||
Generates a 32-bit digest of a set of arguments that can be used to
|
Generate a 32-bit digest of a set of arguments that can be used to shorten
|
||||||
shorten identifying names.
|
identifying names. Support for use in FIPS environments.
|
||||||
"""
|
"""
|
||||||
try:
|
h = hashlib.md5(usedforsecurity=False)
|
||||||
h = hashlib.md5()
|
|
||||||
except ValueError:
|
|
||||||
h = hashlib.md5(usedforsecurity=False)
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
h.update(force_bytes(arg))
|
h.update(arg.encode())
|
||||||
return h.hexdigest()[:8]
|
return h.hexdigest()[:length]
|
||||||
|
|
||||||
|
schema.names_digest = names_digest
|
||||||
schema.BaseDatabaseSchemaEditor = FipsBaseDatabaseSchemaEditor
|
|
||||||
|
|
||||||
|
|
||||||
def find_commands(management_dir):
|
def find_commands(management_dir):
|
||||||
|
|||||||
Reference in New Issue
Block a user