11import json
22from types import NoneType
3- from typing import Annotated , Optional , Union
3+ from typing import Optional , Union , Annotated
44
5- from httpx import Auth
5+ from ..models import *
6+ from ..base_model import Page , Service
67from pydantic import BaseModel , Field
78from pydantic .fields import FieldInfo
8-
9- from ..base_model import Page , Service
9+ from httpx import Auth
1010from ..http_client import HttpClient
11- from ..models import *
12-
1311
1412class Cves (Service ):
15- def __init__ (
16- self , auth : Auth , base_url : str = "https://admin.api.crowdsec.net/v1"
17- ) -> None :
18- super ().__init__ (
19- base_url = base_url , auth = auth , user_agent = "crowdsec_tracker_api/1.95.2"
20- )
21-
13+ def __init__ (self , auth : Auth , base_url : str = "https://admin.api.crowdsec.net/v1" ) -> None :
14+ super ().__init__ (base_url = base_url , auth = auth , user_agent = "crowdsec_tracker_api/1.102.2" )
15+
2216 def get_cves (
2317 self ,
2418 query : Optional [str ] = None ,
2519 sort_by : Optional [GetCVEsSortBy ] = GetCVEsSortBy ("rule_release_date" ),
2620 sort_order : Optional [GetCVEsSortOrder ] = GetCVEsSortOrder ("desc" ),
21+ filters : Optional [list [GetCVEsFilterBy ]] = None ,
2722 page : int = 1 ,
2823 size : int = 50 ,
29- ) -> GetCVEsResponsePage :
24+ )-> GetCVEsResponsePage :
3025 endpoint_url = "/cves"
3126 loc = locals ()
3227 headers = {}
3328 params = json .loads (
34- CvesGetCvesQueryParameters (** loc ).model_dump_json (exclude_none = True )
29+ CvesGetCvesQueryParameters (** loc ).model_dump_json (
30+ exclude_none = True
31+ )
3532 )
3633 path_params = {}
37-
34+
3835 response = self .http_client .get (
3936 url = endpoint_url , path_params = path_params , params = params , headers = headers
4037 )
41-
38+
4239 return GetCVEsResponsePage (_client = self , ** response .json ())
43-
40+
4441 def get_cve (
4542 self ,
4643 cve_id : str ,
47- ) -> GetCVEResponse :
44+ )-> GetCVEResponse :
4845 endpoint_url = "/cves/{cve_id}"
4946 loc = locals ()
5047 headers = {}
5148 params = {}
5249 path_params = json .loads (
53- CvesGetCvePathParameters (** loc ).model_dump_json (exclude_none = True )
50+ CvesGetCvePathParameters (** loc ).model_dump_json (
51+ exclude_none = True
52+ )
5453 )
55-
54+
5655 response = self .http_client .get (
5756 url = endpoint_url , path_params = path_params , params = params , headers = headers
5857 )
59-
58+
6059 return GetCVEResponse (** response .json ())
61-
60+
6261 def download_cve_ips (
6362 self ,
6463 cve_id : str ,
65- ) -> str :
64+ )-> str :
6665 endpoint_url = "/cves/{cve_id}/ips-download"
6766 loc = locals ()
6867 headers = {}
6968 params = {}
7069 path_params = json .loads (
71- CvesDownloadCveIpsPathParameters (** loc ).model_dump_json (exclude_none = True )
70+ CvesDownloadCveIpsPathParameters (** loc ).model_dump_json (
71+ exclude_none = True
72+ )
7273 )
73-
74+
7475 response = self .http_client .get (
7576 url = endpoint_url , path_params = path_params , params = params , headers = headers
7677 )
77-
78+
7879 return response .text
79-
80+
8081 def get_cve_ips_details (
8182 self ,
8283 cve_id : str ,
8384 since : Optional [str ] = "14d" ,
8485 page : int = 1 ,
8586 size : int = 50 ,
86- ) -> GetCVEIPsResponsePage :
87+ )-> GetCVEIPsResponsePage :
8788 endpoint_url = "/cves/{cve_id}/ips-details"
8889 loc = locals ()
8990 headers = {}
@@ -93,21 +94,23 @@ def get_cve_ips_details(
9394 )
9495 )
9596 path_params = json .loads (
96- CvesGetCveIpsDetailsPathParameters (** loc ).model_dump_json (exclude_none = True )
97+ CvesGetCveIpsDetailsPathParameters (** loc ).model_dump_json (
98+ exclude_none = True
99+ )
97100 )
98-
101+
99102 response = self .http_client .get (
100103 url = endpoint_url , path_params = path_params , params = params , headers = headers
101104 )
102-
105+
103106 return GetCVEIPsResponsePage (_client = self , ** response .json ())
104-
107+
105108 def get_cve_subscribed_integrations (
106109 self ,
107110 cve_id : str ,
108111 page : int = 1 ,
109112 size : int = 50 ,
110- ) -> GetCVESubscribedIntegrationsResponsePage :
113+ )-> GetCVESubscribedIntegrationsResponsePage :
111114 endpoint_url = "/cves/{cve_id}/integrations"
112115 loc = locals ()
113116 headers = {}
@@ -121,13 +124,13 @@ def get_cve_subscribed_integrations(
121124 exclude_none = True
122125 )
123126 )
124-
127+
125128 response = self .http_client .get (
126129 url = endpoint_url , path_params = path_params , params = params , headers = headers
127130 )
128-
131+
129132 return GetCVESubscribedIntegrationsResponsePage (_client = self , ** response .json ())
130-
133+
131134 def subscribe_integration_to_cve (
132135 self ,
133136 request : SubscribeCVEIntegrationRequest ,
@@ -142,22 +145,18 @@ def subscribe_integration_to_cve(
142145 exclude_none = True
143146 )
144147 )
145-
146- payload = (
147- json . loads ( request .model_dump_json (exclude_none = True ))
148- if "request" in loc
149- else None
150- )
148+
149+ payload = json . loads (
150+ request .model_dump_json (
151+ exclude_none = True
152+ )
153+ ) if "request" in loc else None
151154 response = self .http_client .post (
152- url = endpoint_url ,
153- path_params = path_params ,
154- params = params ,
155- headers = headers ,
156- json = payload ,
155+ url = endpoint_url , path_params = path_params , params = params , headers = headers , json = payload
157156 )
158-
157+
159158 return None
160-
159+
161160 def unsubscribe_integration_from_cve (
162161 self ,
163162 cve_id : str ,
@@ -172,30 +171,35 @@ def unsubscribe_integration_from_cve(
172171 exclude_none = True
173172 )
174173 )
175-
174+
176175 response = self .http_client .delete (
177176 url = endpoint_url , path_params = path_params , params = params , headers = headers
178177 )
179-
178+
180179 return None
181-
180+
182181 def get_cve_timeline (
183182 self ,
184183 cve_id : str ,
185184 since_days : SinceOptions ,
186- ) -> list [TimelineItem ]:
185+ )-> list [TimelineItem ]:
187186 endpoint_url = "/cves/{cve_id}/timeline"
188187 loc = locals ()
189188 headers = {}
190189 params = json .loads (
191- CvesGetCveTimelineQueryParameters (** loc ).model_dump_json (exclude_none = True )
190+ CvesGetCveTimelineQueryParameters (** loc ).model_dump_json (
191+ exclude_none = True
192+ )
192193 )
193194 path_params = json .loads (
194- CvesGetCveTimelinePathParameters (** loc ).model_dump_json (exclude_none = True )
195+ CvesGetCveTimelinePathParameters (** loc ).model_dump_json (
196+ exclude_none = True
197+ )
195198 )
196-
199+
197200 response = self .http_client .get (
198201 url = endpoint_url , path_params = path_params , params = params , headers = headers
199202 )
200-
203+
201204 return [TimelineItem (** item ) for item in response .json ()]
205+
0 commit comments