google / gcp_scanner

A comprehensive scanner for Google Cloud
Apache License 2.0
305 stars 95 forks source link

GCP Scanner does not work on older versions of Python3 #238

Closed mshudrak closed 1 year ago

mshudrak commented 1 year ago

Affected Component

Describe the bug Currently we are having the following error on older versions of Python3.

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/mshudrak/.local/lib/python3.9/site-packages/gcp_scanner/__main__.py", line 19, in <module>
    from . import scanner
  File "/home/mshudrak/.local/lib/python3.9/site-packages/gcp_scanner/scanner.py", line 40, in <module>
    from .crawler.crawler_factory import CrawlerFactory
  File "/home/mshudrak/.local/lib/python3.9/site-packages/gcp_scanner/crawler/crawler_factory.py", line 43, in <module>
    from gcp_scanner.crawler.storage_buckets_crawler import StorageBucketsCrawler
  File "/home/mshudrak/.local/lib/python3.9/site-packages/gcp_scanner/crawler/storage_buckets_crawler.py", line 24, in <module>
    class StorageBucketsCrawler(ICrawler):
  File "/home/mshudrak/.local/lib/python3.9/site-packages/gcp_scanner/crawler/storage_buckets_crawler.py", line 108, in StorageBucketsCrawler
    def _get_dump_file_dir(cls, config: Dict[str, Union[bool, str]]) -> TextIO | None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

To Reproduce Use python 3.9.2 + GCP Scanner main branch.

Expected behavior We need to support older versions of Python at least default versions of Linux, Windows and MacOS. We also need to have tests for older versions of Python3.

ZetaTwo commented 1 year ago

This can be solved by replacing TextIO | None with Optional[TextIO], the pipe syntax is newer but in this case the two statements are exactly equivalent.

mshudrak commented 1 year ago

Thanks @ZetaTwo, it works! I will submit PR soon. I will also make a separate issue to have in mind that we need to add a test for GCP Scanner on older versions of Python3.