def fs_sink():
    # create
    fs = stix2.FileSystemSink(FS_PATH)
    assert fs.stix_dir == FS_PATH
    yield fs

    # remove campaign dir
    shutil.rmtree(os.path.join(FS_PATH, "campaign"), True)
Esempio n. 2
0
def save_results_in_file(report, title, date, ttps):
    """
	Save prediction in a JSON file under STIX format
	"""
    publication_date = datetime.datetime.strptime(date, "%Y-%m-%d")
    stix_report = stx.Report(
        type="report",
        labels=["threat-report"],
        name=title,  #request from user
        published=publication_date,  #timestamp
        description=report,  #report
        object_refs=ttps)  #list of related identifiers techniques and tactics
    fss = stx.FileSystemSink("./")
    fss._check_path_and_write(stix_report)
    folder_of_created_report = "./report/" + stix_report.id + "/*"
    list_of_files = glob.glob(
        folder_of_created_report
    )  # * means all if need specific format then *.csv
    file_to_save = max(list_of_files, key=os.path.getctime)
    return file_to_save
def test_filesystem_sink_nonexistent_folder():
    with pytest.raises(ValueError):
        stix2.FileSystemSink('nonexistent-folder')
Esempio n. 4
0
def test_filesystem_sink_nonexistent_folder():
    with pytest.raises(ValueError) as excinfo:
        stix2.FileSystemSink('nonexistent-folder')
    assert "for STIX data does not exist" in str(excinfo)