Exemplo n.º 1
0
def fs_sink():
    # create
    fs = FileSystemSink(FS_PATH)
    assert fs.stix_dir == FS_PATH
    yield fs

    # remove campaign dir
    shutil.rmtree(os.path.join(FS_PATH, "campaign"), True)
Exemplo n.º 2
0
def test_filesystem_sink_nonexistent_folder():
    with pytest.raises(ValueError) as excinfo:
        FileSystemSink('nonexistent-folder')
    assert "for STIX data does not exist" in str(excinfo)
Exemplo n.º 3
0
        print('\n')
    except Exception as e:
        print('Some other exception parsing:', o)
        print(e, '\n')


if __name__ == '__main__':
    from stix2 import FileSystemSink
    store_path = pathlib.Path('/Users/priezm/repos/GTO/stix_worknench/')
    path = pathlib.Path('/Users/priezm/repos/GTO/working_stix_corpora')
    if not store_path.exists():
        store_path.mkdir(parents=True)
    fs = workbench.FileSystemSource(str(store_path))
    workbench.add_data_source(fs)

    sink = FileSystemSink('/Users/priezm/repos/GTO/stix_worknench/',
                          allow_custom=True)
    if path.is_dir():
        for p in tqdm(list(path.glob('**/*.json')), 'Files'):
            with open(p, 'r') as f:
                print(
                    '\n\n***********************************************************'
                )
                print('adding file: {}'.format(p))
                try:
                    irl = json.load(f)
                    print('our irl: ', irl)
                    print('our objects: ', irl['objects'])
                    for o in tqdm(irl['objects'], 'Objects'):
                        new_obj = obj_to_21(o)
                        print('adding to sink')
                        if new_obj is not None: