33
33
34
34
35
35
class DebianCVETracker :
36
+ """
37
+ A class for tracking CVEs (Common Vulnerabilities and Exposures) for Debian-based distributions.
38
+
39
+ This class is designed to monitor CVEs specific to a given Debian distribution,
40
+ taking into account the distribution name, codename, and whether the package is a backport.
41
+
42
+ Attributes:
43
+ distro_name (str): The name of the Debian-based distribution (e.g., "Debian", "Ubuntu").
44
+ distro_codename (str): The codename of the distribution release (e.g., "buster", "focal").
45
+ is_backport (bool): Flag indicating if the package is a backport.
46
+ """
47
+
36
48
def __init__ (self , distro_name : str , distro_codename : str , is_backport : bool ):
49
+ """
50
+ Initializes a DebianCVETracker instance with distribution information.
51
+
52
+ Parameters:
53
+ distro_name (str): The name of the Debian-based distribution.
54
+ distro_codename (str): The codename for the distribution release.
55
+ is_backport (bool): Specifies if the package is a backport.
56
+ """
37
57
self .distro_name = distro_name
38
58
self .distro_codename = distro_codename
39
59
self .is_backport = is_backport
@@ -42,7 +62,17 @@ def cve_info(
42
62
self ,
43
63
all_cve_data : dict [ProductInfo , CVEData ],
44
64
):
45
- """Produces the Backported fixes' info"""
65
+ """
66
+ Generates information on backported CVE fixes for a given set of CVE data.
67
+
68
+ This function processes CVE data and checks for resolved vulnerabilities in
69
+ the Debian or Ubuntu distributions. If a fix is available or backported, it logs
70
+ relevant information about the fix's availability and version.
71
+
72
+ Parameters:
73
+ all_cve_data (dict[ProductInfo, CVEData]): Dictionary containing CVE data,
74
+ organized by product and version.
75
+ """
46
76
47
77
cve_data = format_output (all_cve_data , None )
48
78
json_data = self .get_data ()
@@ -72,19 +102,43 @@ def cve_info(
72
102
)
73
103
74
104
def get_data (self ):
105
+ """
106
+ Retrieves CVE data from the Debian CVE JSON file.
107
+
108
+ This method opens and loads the Debian CVE JSON file for processing
109
+ vulnerability data, calling `check_json` to verify that the file is
110
+ up-to-date before loading.
111
+
112
+ Returns:
113
+ dict: Loaded JSON data from the Debian CVE JSON file.
114
+ """
75
115
check_json ()
76
116
with open (DEB_CVE_JSON_PATH ) as jsonfile :
77
117
return load (jsonfile )
78
118
79
119
def compute_distro (self ):
120
+ """
121
+ Computes the distribution codename based on the Debian or Ubuntu release.
122
+
123
+ Maps the specified distribution codename to either Ubuntu or Debian based
124
+ on the provided `distro_name`.
125
+
126
+ Returns:
127
+ str: The mapped codename for the distribution.
128
+ """
80
129
if self .distro_name == "ubuntu" :
81
130
return UBUNTU_DEBIAN_MAP [self .distro_codename ]
82
131
elif self .distro_name == "debian" :
83
132
return self .distro_codename
84
133
85
134
86
135
def check_json ():
87
- """Check to update the Debian CVE JSON file"""
136
+ """
137
+ Verifies if the Debian CVE JSON file is current and triggers an update if outdated.
138
+
139
+ This function checks the modification time of the JSON file. If it's older than
140
+ one day, it calls `update_json` to download a fresh version.
141
+ """
88
142
89
143
if (
90
144
not DEB_CVE_JSON_PATH .exists ()
@@ -94,7 +148,12 @@ def check_json():
94
148
95
149
96
150
def update_json ():
97
- """Update the Debian CVE JSON file"""
151
+ """
152
+ Updates the Debian CVE JSON file by downloading the latest data.
153
+
154
+ This function requests the JSON data from the specified URL and saves it to
155
+ the `DEB_CVE_JSON_PATH` location, logging the update status.
156
+ """
98
157
99
158
LOGGER .info ("Updating Debian CVE JSON file for checking available fixes." )
100
159
# timeout = 300s = 5min. This is a guess at a valid default
0 commit comments