Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed behaviour if parameter types value is empty string, behave th… #2536

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Fixed behaviour if parameter `types` value is empty string, behave the same way as not set, not like no type.
- Fixed behaviour if parameter `types` value is empty string, behave the same way as not set, not like no type (PR#2536 by Jason).


#### 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
Loading