11"""Main module."""
2+
23import argparse
34import logging
45import sys
6+ from collections .abc import Sequence
57from datetime import datetime , timezone
68from importlib .metadata import version
7- from typing import IO , List , Optional , Sequence , Set
9+ from typing import IO , Optional
810
911import yaml
1012
2325
2426
2527def get_security_vulnerability_database_apis () -> (
26- List [SecurityVulnerabilityDatabaseAPI ]
28+ list [SecurityVulnerabilityDatabaseAPI ]
2729):
2830 """Return the APIs to use for fetching vulnerabilities."""
2931 return [GithubSecurityAdvisoryAPI ()]
3032
3133
3234def fetch_vulnerabilities (
33- apis : Sequence [SecurityVulnerabilityDatabaseAPI ], severities : Set [SeverityLevel ]
34- ) -> List [SecurityVulnerability ]:
35+ apis : Sequence [SecurityVulnerabilityDatabaseAPI ], severities : set [SeverityLevel ]
36+ ) -> list [SecurityVulnerability ]:
3537 """Use apis to fetch and return vulnerabilities."""
36- vulnerabilities : List [SecurityVulnerability ] = []
38+ vulnerabilities : list [SecurityVulnerability ] = []
3739 for api in apis :
3840 LOGGER .debug ("Fetching vulnerabilities from %s..." , api .get_database_name ())
3941 vulnerabilities .extend (api .get_vulnerabilities (severities = severities ))
4042 return vulnerabilities
4143
4244
4345def filter_vulnerabilities (
44- config : Configuration , vulnerabilities : List [SecurityVulnerability ]
45- ) -> List [SecurityVulnerability ]:
46+ config : Configuration , vulnerabilities : list [SecurityVulnerability ]
47+ ) -> list [SecurityVulnerability ]:
4648 """Filter out vulnerabilities that should be ignored and return the rest."""
4749 if config .ignore_ids :
4850 LOGGER .debug ("Applying ignore-ids..." )
@@ -53,8 +55,8 @@ def filter_vulnerabilities(
5355
5456
5557def sort_vulnerabilities (
56- vulnerabilities : List [SecurityVulnerability ],
57- ) -> List [SecurityVulnerability ]:
58+ vulnerabilities : list [SecurityVulnerability ],
59+ ) -> list [SecurityVulnerability ]:
5860 """Sort vulnerabilities into the order they should appear in the constraints."""
5961 sorted_vulnerabilities = sorted (vulnerabilities , key = lambda v : v .identifier )
6062 sorted_vulnerabilities .sort (key = lambda v : v .package )
@@ -69,7 +71,7 @@ def get_safe_version_constraints(
6971 See SecurityVulnerability documentation for more information.
7072
7173 """
72- safe_specs : List [str ] = []
74+ safe_specs : list [str ] = []
7375 vulnerable_spec : str
7476 if "," in vulnerability .vulnerable_range :
7577 # If there is a known min and max affected version, make the constraints
@@ -124,9 +126,9 @@ def create_header(
124126 """Create the comment header which goes at the top of the output."""
125127 time_format : str = "%Y-%m-%dT%H:%M:%S.%fZ" # ISO with Z for UTC
126128 timestamp : str = datetime .now (tz = timezone .utc ).strftime (time_format )
127- sources : List [str ] = [api .get_database_name () for api in apis ]
129+ sources : list [str ] = [api .get_database_name () for api in apis ]
128130 app_name : str = "security-constraints"
129- lines : List [str ] = [
131+ lines : list [str ] = [
130132 f"Generated by { app_name } { version (app_name )} on { timestamp } " ,
131133 f"Data sources: { ', ' .join (sources )} " ,
132134 f"Configuration: { config .to_dict ()} " ,
@@ -259,11 +261,11 @@ def main() -> int:
259261 yaml .safe_dump (config .to_dict (), stream = sys .stdout )
260262 return 0
261263
262- apis : List [
263- SecurityVulnerabilityDatabaseAPI
264- ] = get_security_vulnerability_database_apis ( )
264+ apis : list [ SecurityVulnerabilityDatabaseAPI ] = (
265+ get_security_vulnerability_database_apis ()
266+ )
265267
266- vulnerabilities : List [SecurityVulnerability ] = fetch_vulnerabilities (
268+ vulnerabilities : list [SecurityVulnerability ] = fetch_vulnerabilities (
267269 apis , severities = config .min_severity .get_higher_or_equal_severities ()
268270 )
269271 vulnerabilities = filter_vulnerabilities (config , vulnerabilities )
0 commit comments