Skip to content

Commit

Permalink
Fixed behaviour if parameter types value is empty string, behave th…
Browse files Browse the repository at this point in the history
…e same way as not set, not like no type.
  • Loading branch information
elsif2 committed Nov 20, 2024
1 parent e86912f commit 06b395b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

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

#### Parsers
- `intelmq.bots.parsers.shadowserver._config`:
Expand Down
13 changes: 9 additions & 4 deletions intelmq/bots/collectors/shadowserver/collector_reports_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ShadowServerAPICollectorBot(CollectorBot, HttpMixin, CacheMixin):
reports (list):
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').
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').
"""

country = None
Expand All @@ -48,6 +48,7 @@ class ShadowServerAPICollectorBot(CollectorBot, HttpMixin, CacheMixin):
redis_cache_ttl: int = 864000 # 10 days
redis_cache_password: Optional[str] = None
_report_list = []
_type_list = []

def init(self):
if not self.api_key:
Expand All @@ -62,7 +63,11 @@ def init(self):
elif isinstance(self.reports, list):
self._report_list = self.reports
if isinstance(self.types, str):
self.types = self.types.split(',')
# if types is an empty string (or only contains whitespace), behave as if the parameter is not set and select all types
types = self.types.strip()
self._type_list = types.split(',') if types else []
elif isinstance(self.types, list):
self._type_list = self.types
if self.country and self.country not in self._report_list:
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)
Expand Down Expand Up @@ -111,8 +116,8 @@ def _reports_list(self, date=None):
self.logger.debug('There was an error downloading the reports: %s', reports['error'])
return None

if self.types:
reports = [report for report in reports if any(report['type'] == rtype for rtype in self.types)]
if self._type_list:
reports = [report for report in reports if any(report['type'] == rtype for rtype in self._type_list)]
return reports

def _report_download(self, reportid: str):
Expand Down

0 comments on commit 06b395b

Please sign in to comment.