Skip to content

Commit

Permalink
Removed file_format parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
elsif2 committed Jul 28, 2023
1 parent 3d6a87e commit af69480
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions intelmq/bots/collectors/shadowserver/collector_reports_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ class ShadowServerAPICollectorBot(CollectorBot, HttpMixin, CacheMixin):
A list of strings or a comma-separated list of the mailing lists you want to process.
types (list):
A list of strings or a string of comma-separated values with the names of reporttypes you want to process. If you leave this empty, all the available reports will be downloaded and processed (i.e. 'scan', 'drones', 'intel', 'sandbox_connection', 'sinkhole_combined').
file_format (str): File format to download ('csv'). The 'json' option is no longer supported.
"""

country = None
api_key = None
secret = None
types = None
reports = None
file_format = None
rate_limit: int = 86400
redis_cache_db: int = 12
redis_cache_host: str = "127.0.0.1" # TODO: type could be ipadress
Expand All @@ -66,18 +64,12 @@ def init(self):
self.logger.warn("Deprecated parameter 'country' found. Please use 'reports' instead. The backwards-compatibility will be removed in IntelMQ version 4.0.0.")
self._report_list.append(self.country)

if self.file_format is not None:
if not (self.file_format == 'csv'):
raise ValueError("Invalid file_format '%s'. Must be 'csv'." % self.file_format)
else:
self.file_format = 'csv'

self.preamble = f'{{ "apikey": "{self.api_key}" '

def check(parameters: dict):
for key in parameters:
if key == 'file_format' and parameters[key] != 'csv':
return [["error", "Invalid file_format '%s'. Must be 'csv'." % parameters[key]]]
if key == 'file_format':
return [["error", "The file_format parameter is no longer supported. All reports are CSV."]]
elif key == 'country':
return [["warning", "Deprecated parameter 'country' found. Please use 'reports' instead. The backwards-compatibility will be removed in IntelMQ version 4.0.0."]]

Expand Down Expand Up @@ -129,11 +121,7 @@ def _report_download(self, reportid: str):
data = self.preamble
data += f',"id": "{reportid}"}}'
self.logger.debug('Downloading report with data: %s.', data)

if (self.file_format == 'json'):
response = self.http_session().post(APIROOT + 'reports/download', data=data, headers=self._headers(data))
else:
response = self.http_session().get(DLROOT + reportid)
response = self.http_session().get(DLROOT + reportid)
response.raise_for_status()

return response.text
Expand All @@ -150,7 +138,7 @@ def process(self):

for item in reportslist:
filename = item['file']
filename_fixed = FILENAME_PATTERN.sub('.' + self.file_format, filename, count=1)
filename_fixed = FILENAME_PATTERN.sub('.csv', filename, count=1)
if self.cache_get(filename):
self.logger.debug('Processed file %r (fixed: %r) already.', filename, filename_fixed)
continue
Expand Down

0 comments on commit af69480

Please sign in to comment.