def datastore(datastore_connection, filestore): ds = datastore_connection try: random_data.create_heuristics(ds, heuristics_count=10) random_data.create_services(ds) random_data.create_signatures(ds) random_data.create_users(ds) random_data.create_workflows(ds) submissions = [] for _ in range(2): submissions.append(random_data.create_submission( ds, filestore)) random_data.create_alerts(ds, alert_count=10, submission_list=submissions) yield ds finally: # Cleanup test data random_data.wipe_alerts(ds) random_data.wipe_heuristics(ds) random_data.wipe_services(ds) random_data.wipe_signatures(ds) random_data.wipe_submissions(ds, filestore) random_data.wipe_users(ds) random_data.wipe_workflows(ds)
def datastore(datastore_connection): try: create_users(datastore_connection) create_services(datastore_connection) create_signatures(datastore_connection) yield datastore_connection finally: wipe_users(datastore_connection) wipe_services(datastore_connection) wipe_signatures(datastore_connection)
def datastore(request, datastore_connection, fs): purge_data(datastore_connection, fs) create_alerts(datastore_connection, alert_count=1) create_heuristics(datastore_connection) create_services(datastore_connection) create_signatures(datastore_connection) create_submission(datastore_connection, fs) create_users(datastore_connection) create_workflows(datastore_connection) request.addfinalizer(lambda: purge_data(datastore_connection, fs)) return datastore_connection
def create_basic_data(log=None, ds=None, svc=True, sigs=True, reset=False): ds = ds or forge.get_datastore() if reset: log.info("Wiping all collections...") for name in ds.ds._models: collection = ds.ds.__getattr__(name) collection.wipe() log.info(f"\t{name}") log.info("\nCreating user objects...") create_users(ds, log=log) if svc: log.info("\nCreating services...") create_services(ds, log=log) if sigs: log.info("\nImporting test signatures...") signatures = create_signatures(ds) for s in signatures: log.info(f"\t{s}") if svc: log.info("\nCreating random heuristics...") create_heuristics(ds, log=log)
def datastore(datastore_connection): ds = datastore_connection try: create_users(ds) signatures.extend(create_signatures(ds)) ds.signature.commit() for _ in range(TEST_SIZE): f = random_model_obj(File) ds.file.save(f.sha256, f) file_list.append(f.sha256) ds.file.commit() for x in range(TEST_SIZE): a = random_model_obj(Alert) a.file.sha256 = file_list[x] ds.alert.save(a.alert_id, a) ds.alert.commit() for x in range(TEST_SIZE): r = random_model_obj(Result) r.sha256 = file_list[x] ds.result.save(r.build_key(), r) ds.result.commit() for x in range(TEST_SIZE): s = random_model_obj(Submission) for f in s.files: f.sha256 = file_list[x] ds.submission.save(s.sid, s) ds.submission.commit() for x in range(TEST_SIZE): h = random_model_obj(Heuristic) h.heur_id = f"AL_TEST_{x}" ds.heuristic.save(h.heur_id, h) ds.heuristic.commit() for _ in range(TEST_SIZE): w_id = get_random_id() w = random_model_obj(Workflow) ds.workflow.save(w_id, w) ds.workflow.commit() yield ds finally: ds.alert.wipe() ds.file.wipe() ds.result.wipe() ds.signature.wipe() ds.submission.wipe() ds.heuristic.wipe() ds.workflow.wipe() wipe_users(ds)