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

refactor repetative if statements in the scanner.py #227

Closed
Tracked by #153
sudiptob2 opened this issue Jun 25, 2023 · 0 comments · Fixed by #228
Closed
Tracked by #153

refactor repetative if statements in the scanner.py #227

sudiptob2 opened this issue Jun 25, 2023 · 0 comments · Fixed by #228
Labels
enhancement New feature or request

Comments

@sudiptob2
Copy link
Contributor

sudiptob2 commented Jun 25, 2023

related to #153

Idea on refactoring repetitive if statements in the scanner.py

# crawl_name: client_name map
# crawl_name indicates the string depending on which crawl factory will work
# client_name indicates the string depending on which current client factory works
# crawl_name in the client_factory will be chosen in such a way that it matches with the keys in the config file

crawl_client_map = {
  'compute_instances': 'compute',
  'compute_images': 'compute',
  'machine_images': 'compute',
  'compute_disks': 'compute',
  'static_ips': 'compute',
  'app_services': 'appengine',
  'storage_buckets': 'storage',
  'managed_zones': 'managed_zones',
  # and so on
}

# replacing the repetitive if statements

for crawler_name, client_name in crawl_client_map.items():
  if is_set(scan_config, crawler_name):
    CrawlFactory.create_crawler(crawler_name).crawl(
      project_id,
      ClientFactory.get_client(client_name).get_service(credentials),
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant