formatting

stix2.1
mbastian1135 2017-07-12 11:26:50 -04:00 committed by Greg Back
parent 9d72d60706
commit 9f659f9ecb
1 changed files with 14 additions and 14 deletions

View File

@ -191,13 +191,13 @@ class FileSystemSource(DataSource):
# the corresponding subdirectories as well # the corresponding subdirectories as well
include_paths = [] include_paths = []
declude_paths = [] declude_paths = []
if "type" in [filter_['field'] for filter_ in file_filters]: if "type" in [filter_["field"] for filter_ in file_filters]:
for filter_ in file_filters: for filter_ in file_filters:
if filter_['field'] == "type": if filter_["field"] == "type":
if filter_['op'] == '=': if filter_["op"] == '=':
include_paths.append(os.path.join(self.stix_dir, filter_['value'])) include_paths.append(os.path.join(self.stix_dir, filter_["value"]))
elif filter_['op'] == "!=": elif filter_["op"] == "!=":
declude_paths.append(os.path.join(self.stix_dir, filter_['value'])) declude_paths.append(os.path.join(self.stix_dir, filter_["value"]))
else: else:
# have to walk entire STIX directory # have to walk entire STIX directory
include_paths.append(self.stix_dir) include_paths.append(self.stix_dir)
@ -220,26 +220,26 @@ class FileSystemSource(DataSource):
# grab stix object ID as well - if present in filters, as # grab stix object ID as well - if present in filters, as
# may forgo the loading of STIX content into memory # may forgo the loading of STIX content into memory
if "id" in [filter_['field'] for filter_ in file_filters]: if "id" in [filter_["field"] for filter_ in file_filters]:
for filter_ in file_filters: for filter_ in file_filters:
if filter_['field'] == 'id' and filter_['field'] == '=': if filter_["field"] == "id" and filter_["field"] == '=':
id_ = filter_['value'] id_ = filter_["value"]
else: else:
id_ = None id_ = None
# now iterate through all STIX objs # now iterate through all STIX objs
for path in include_paths: for path in include_paths:
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
for file in files: for file_ in files:
if id_: if id_:
if id_ == file.split(".")[0]: if id_ == file_.split(".")[0]:
# since ID is specified in one of filters, can evaluate against filename first without loading # since ID is specified in one of filters, can evaluate against filename first without loading
stix_obj = json.load(file)['objects'] stix_obj = json.load(file_)["objects"]
# check against other filters, add if match # check against other filters, add if match
all_data.extend(self.apply_common_filters([stix_obj], query)) all_data.extend(self.apply_common_filters([stix_obj], query))
else: else:
# have to load into memory regardless to evaluate other filters # have to load into memory regardless to evaluate other filters
stix_obj = json.load(file)['objects'] stix_obj = json.load(file_)["objects"]
all_data.extend(self.apply_common_filters([stix_obj], query)) all_data.extend(self.apply_common_filters([stix_obj], query))
all_data = self.deduplicate(all_data) all_data = self.deduplicate(all_data)
@ -251,6 +251,6 @@ class FileSystemSource(DataSource):
""" """
file_filters = [] file_filters = []
for filter_ in query: for filter_ in query:
if filter_['field'] == "id" or filter_['field'] == "type": if filter_["field"] == "id" or filter_["field"] == "type":
file_filters.append(filter_) file_filters.append(filter_)
return file_filters return file_filters