diff options
Diffstat (limited to 'lib/orm/management/commands/checksettings.py')
-rw-r--r-- | lib/orm/management/commands/checksettings.py | 110 |
1 files changed, 71 insertions, 39 deletions
diff --git a/lib/orm/management/commands/checksettings.py b/lib/orm/management/commands/checksettings.py index 65e9ab8a..e65d16ac 100644 --- a/lib/orm/management/commands/checksettings.py +++ b/lib/orm/management/commands/checksettings.py @@ -29,7 +29,7 @@ class Command(BaseCommand): def _verify_srt_source(self): ds_loaded = {} - + needs_import = False if 0 == DataSource.objects.all().count(): needs_import = True @@ -46,7 +46,7 @@ class Command(BaseCommand): print("Loading default settings") call_command("loaddata", "settings") - # Import the Common fixture if it's present + # Import the common fixture with warnings.catch_warnings(): warnings.filterwarnings( action="ignore", @@ -54,41 +54,57 @@ class Command(BaseCommand): print("Importing Common settings if present") try: call_command("loaddata", "common") - except: - print("NOTE: optional fixture 'common' not found") - - # Import the Mitre fixture if it's present - with warnings.catch_warnings(): - warnings.filterwarnings( - action="ignore", - message="^.*No fixture named.*$") - print("Importing Mitre settings if present") - try: - call_command("loaddata", "mitre") - except: - print("NOTE: optional fixture 'mitre' not found") + except Exception as e: + print("NOTE: optional fixture 'common' not found (%s)" % e) - # Import the NIST fixture if it's present + # Import the 'custom' fixture to allow local custom overrides with warnings.catch_warnings(): warnings.filterwarnings( action="ignore", message="^.*No fixture named.*$") - print("Importing NIST settings if present") - try: - call_command("loaddata", "nist") - except: - print("NOTE: optional fixture 'nist' not found") - - # Import the Sample_Test fixture if it's present - with warnings.catch_warnings(): - warnings.filterwarnings( - action="ignore", - message="^.*No fixture named.*$") - print("Importing Sample Test settings if present") + print("Importing Common settings if present") try: - call_command("loaddata", "samples") - except: - print("NOTE: optional fixture 'samples' not found") + call_command("loaddata", "custom") + except Exception as e: + print("NOTE: optional fixture 'custom' not found (%s)" % e) + + # Promote fallback values to missing configure defines + for setting in SrtSetting.objects.all(): + if '_fallback' in setting.name: + name = setting.name.replace('_fallback','') + s,create = SrtSetting.objects.get_or_create(name=key) + if create: + s.value = setting.value + s.save + + # Import the requested source fixture list + try: + fixture_list = SrtSetting.objects.get(name='SRTOOL_FIXTURE_LIST').value + except: + fixture_list = 'yp,nist' + for fixture in fixture_list.split(','): + fixture = fixture.strip() + with warnings.catch_warnings(): + warnings.filterwarnings( + action="ignore", + message="^.*No fixture named.*$") + print("Importing %s fixture if present" % fixture) + try: + call_command("loaddata", fixture) + except Exception as e: + print("NOTE: optional fixture '%s' not found (%s)" % (fixture,e)) + + # Import the Sample_Test fixture if it's requested and present + if self._test_settings_get('SRTDBG_SAMPLES'): + with warnings.catch_warnings(): + warnings.filterwarnings( + action="ignore", + message="^.*No fixture named.*$") + print("Importing Sample Test settings if present") + try: + call_command("loaddata", "samples") + except Exception as e: + print("NOTE: optional fixture 'samples' not found (%s)" % e) # restore data source loaded flags for source in DataSource.objects.all(): @@ -109,8 +125,20 @@ class Command(BaseCommand): traceback.print_exc() return 0 - - def _test_settings(self,key): + + def _test_settings_get(self,key): + try: + key_record = SrtSetting.objects.get(name=key) + if 'yes' == key_record.value: + return True + elif 'no' == key_record.value: + return False + else: + return key_record.value + except: + return False + + def _test_settings_set(self,key): key_record,create = SrtSetting.objects.get_or_create(name=key) if key in os.environ.keys(): key_record.value = 'yes' if os.environ[key].startswith('1') else 'no' @@ -127,12 +155,16 @@ class Command(BaseCommand): SrtSetting.objects.get_or_create(name='DEFAULT_RELEASE', value='') # TEST: set up the test flags based on ENVIRONMENT values - # * export TEST_SKIP_NIST_IMPORT=1: we already have NIST data in the DB - # * export TEST_SKIP_CPE_IMPORT=1: we do not need to (re-)scan the CPEs for vulnerable CVEs - # * export TEST_MINIMAL_DB=1: only load the minimal database items for fast GUI tests - self._test_settings('TEST_SKIP_NIST_IMPORT') - self._test_settings('TEST_SKIP_CPE_IMPORT') - self._test_settings('TEST_MINIMAL_DB') + # * export SRTDBG_SKIP_CVE_IMPORT=1: we do not need to (re-)scan the CVE data + # * export SRTDBG_SKIP_CPE_IMPORT=1: we do not need to (re-)scan the CPE data + # * export SRTDBG_SKIP_DEFECT_IMPORT=1: we do not need to (re-)scan the CPE data + # * export SRTDBG_MINIMAL_DB=1: only load the minimal database items for fast GUI tests + # * export SRTDBG_SAMPLES=1: load sample fixture (if any) database items for fast GUI tests + self._test_settings_set('SRTDBG_SKIP_CVE_IMPORT') + self._test_settings_set('SRTDBG_SKIP_CPE_IMPORT') + self._test_settings_set('SRTDBG_SKIP_DEFECT_IMPORT') + self._test_settings_set('SRTDBG_MINIMAL_DB') + self._test_settings_set('SRTDBG_SAMPLES') # TEMP: set up default user info current_user = SrtSetting.objects.get_or_create(name='current_user')[0] |