Skip to content

Commit a486071

Browse files
authored
Merge pull request #2536 from certtools/shadowserver-intelmq-manager-types
Fixed behaviour if parameter `types` value is empty string, behave th…
2 parents e86912f + 06b395b commit a486071

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
### Bots
2121
#### Collectors
22+
- `intelmq.bots.collectors.shadowserver.collector_reports_api.py`:
23+
- Fixed behaviour if parameter `types` value is empty string, behave the same way as not set, not like no type.
2224

2325
#### Parsers
2426
- `intelmq.bots.parsers.shadowserver._config`:

intelmq/bots/collectors/shadowserver/collector_reports_api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ShadowServerAPICollectorBot(CollectorBot, HttpMixin, CacheMixin):
3333
reports (list):
3434
A list of strings or a comma-separated list of the mailing lists you want to process.
3535
types (list):
36-
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').
36+
A list of strings or a string of comma-separated values with the names of report types 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').
3737
"""
3838

3939
country = None
@@ -48,6 +48,7 @@ class ShadowServerAPICollectorBot(CollectorBot, HttpMixin, CacheMixin):
4848
redis_cache_ttl: int = 864000 # 10 days
4949
redis_cache_password: Optional[str] = None
5050
_report_list = []
51+
_type_list = []
5152

5253
def init(self):
5354
if not self.api_key:
@@ -62,7 +63,11 @@ def init(self):
6263
elif isinstance(self.reports, list):
6364
self._report_list = self.reports
6465
if isinstance(self.types, str):
65-
self.types = self.types.split(',')
66+
# if types is an empty string (or only contains whitespace), behave as if the parameter is not set and select all types
67+
types = self.types.strip()
68+
self._type_list = types.split(',') if types else []
69+
elif isinstance(self.types, list):
70+
self._type_list = self.types
6671
if self.country and self.country not in self._report_list:
6772
self.logger.warn("Deprecated parameter 'country' found. Please use 'reports' instead. The backwards-compatibility will be removed in IntelMQ version 4.0.0.")
6873
self._report_list.append(self.country)
@@ -111,8 +116,8 @@ def _reports_list(self, date=None):
111116
self.logger.debug('There was an error downloading the reports: %s', reports['error'])
112117
return None
113118

114-
if self.types:
115-
reports = [report for report in reports if any(report['type'] == rtype for rtype in self.types)]
119+
if self._type_list:
120+
reports = [report for report in reports if any(report['type'] == rtype for rtype in self._type_list)]
116121
return reports
117122

118123
def _report_download(self, reportid: str):

0 commit comments

Comments
 (0)