From 8d012de3e255f0bcf3e3dab57e0c9fc486619dac Mon Sep 17 00:00:00 2001 From: adamscmRH Date: Thu, 8 Nov 2018 17:08:12 -0500 Subject: [PATCH] monkey-patch _digest for fips --- awx/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/awx/__init__.py b/awx/__init__.py index 8f35750c48..c1b6f8eb4b 100644 --- a/awx/__init__.py +++ b/awx/__init__.py @@ -21,6 +21,32 @@ except ImportError: # pragma: no cover MODE = 'production' +import hashlib +from django.utils.encoding import force_bytes +from django.db.backends.base.schema import BaseDatabaseSchemaEditor +from django.db.backends.base import schema + +class FipsBaseDatabaseSchemaEditor(BaseDatabaseSchemaEditor): + + @classmethod + def _digest(cls, *args): + """ + Generates a 32-bit digest of a set of arguments that can be used to + shorten identifying names. + """ + try: + h = hashlib.md5() + except ValueError: + h = hashlib.md5(usedforsecurity=False) + for arg in args: + h.update(force_bytes(arg)) + return h.hexdigest()[:8] + +schema.BaseDatabaseSchemaEditor = FipsBaseDatabaseSchemaEditor + + + + def find_commands(management_dir): # Modified version of function from django/core/management/__init__.py. command_dir = os.path.join(management_dir, 'commands')