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

Refinement: Removed Redundancy of Scan Config Passing #304

Merged
merged 3 commits into from
Nov 29, 2023
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
15 changes: 15 additions & 0 deletions src/gcp_scanner/crawler/interface_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class ICrawler(metaclass=ABCMeta):

"""

"""Variable to identify if config file is needed

Access Type: Private
"""
_config_dependency = False

@staticmethod
@abstractmethod
def crawl(project_name: str, service: discovery.Resource,
Expand All @@ -49,3 +55,12 @@ def crawl(project_name: str, service: discovery.Resource,
"""

raise NotImplementedError("Child class must implement the crawl() method.")

@property
def has_config_dependency(self) -> bool:
"""Checks if the class needs a config file

Returns:
bool: Returns config_dependency private variable which is False by default.
"""
return self._config_dependency
11 changes: 11 additions & 0 deletions src/gcp_scanner/crawler/storage_buckets_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
class StorageBucketsCrawler(ICrawler):
"""Handle crawling of bucket names data."""

_config_dependency = True # Define that config file is needed

def crawl(self, project_name: str, service: discovery.Resource,
config: Dict[str, Union[bool, str]] = None) -> Dict[str, Tuple[Any, List[Any]]]:
"""Retrieve a list of buckets available in the project.
Expand Down Expand Up @@ -77,6 +79,15 @@ def crawl(self, project_name: str, service: discovery.Resource,
if dump_fd is not None:
dump_fd.close()
return buckets_dict

@property
def has_config_dependency(self) -> bool:
"""Checks if the class needs a config file

Returns:
bool: Returns config_dependency private variable which is False by default.
"""
return self._config_dependency

@classmethod
def _get_bucket_iam(cls, bucket_name: str, service: discovery.Resource) -> List[Any]:
Expand Down
6 changes: 4 additions & 2 deletions src/gcp_scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ def get_crawl(
Returns:
scan_result: a dictionary with scanning results
"""

res = crawler.crawl(project_id, client, crawler_config)
if crawler.has_config_dependency:
res = crawler.crawl(project_id, client, crawler_config)
else:
res = crawler.crawl(project_id, client)
if res is not None and len(res) != 0:
scan_results[crawler_name] = res
return scan_results
Expand Down