1010from probely_cli .sdk .client import ProbelyAPIClient
1111from probely_cli .sdk .helpers import validate_resource_ids
1212from probely_cli .settings import (
13- PROBELY_API_BULK_START_SCANS_URL ,
13+ PROBELY_API_SCANS_BULK_START_URL ,
1414 PROBELY_API_PAGE_SIZE ,
1515 PROBELY_API_SCAN_CANCEL_URL ,
1616 PROBELY_API_SCAN_PAUSE_URL ,
1919 PROBELY_API_SCANS_BULK_PAUSE_URL ,
2020 PROBELY_API_SCANS_BULK_RESUME_URL ,
2121 PROBELY_API_SCANS_URL ,
22- PROBELY_API_START_SCAN_URL ,
22+ PROBELY_API_TARGETS_START_SCAN_URL ,
2323 PROBELY_API_TARGETS_URL ,
2424)
2525
2626logger = logging .getLogger (__name__ )
2727
2828
2929def start_scan (target_id : str , extra_payload : dict = None ) -> dict :
30- scan_target_url = PROBELY_API_START_SCAN_URL .format (target_id = target_id )
30+ scan_target_url = PROBELY_API_TARGETS_START_SCAN_URL .format (target_id = target_id )
3131
3232 resp_status_code , resp_content = ProbelyAPIClient .post (
33- scan_target_url , extra_payload
33+ scan_target_url , payload = extra_payload
3434 )
3535
3636 if resp_status_code != 200 :
@@ -47,19 +47,20 @@ def start_scan(target_id: str, extra_payload: dict = None) -> dict:
4747def start_scans (target_ids : List [str ], extra_payload : dict = None ) -> List [dict ]:
4848 validate_resource_ids (PROBELY_API_TARGETS_URL , target_ids )
4949
50- url = PROBELY_API_BULK_START_SCANS_URL
50+ url = PROBELY_API_SCANS_BULK_START_URL
5151 extra_payload = extra_payload or {}
5252
5353 payload = {
5454 "targets" : [{"id" : target_id } for target_id in target_ids ],
5555 ** extra_payload ,
5656 }
5757
58- resp_status_code , resp_content = ProbelyAPIClient .post (url , payload )
58+ resp_status_code , resp_content = ProbelyAPIClient .post (url , payload = payload )
59+
60+ if resp_status_code == 400 :
61+ raise ProbelyBadRequest (resp_content )
5962
6063 if resp_status_code != 200 :
61- if resp_status_code == 400 :
62- raise ProbelyBadRequest (resp_content )
6364 raise ProbelyRequestFailed (resp_content )
6465
6566 scans = resp_content
@@ -72,8 +73,10 @@ def cancel_scans(scan_ids: List[str]) -> List[dict]:
7273 for scan_id in scan_ids :
7374 retrieve_scan (scan_id )
7475
76+ payload = {"scans" : [{"id" : scan_id } for scan_id in scan_ids ]}
77+
7578 resp_status_code , resp_content = ProbelyAPIClient .post (
76- scan_cancel_url , { "scans" : [{ "id" : scan_id } for scan_id in scan_ids ]}
79+ scan_cancel_url , payload = payload
7780 )
7881
7982 if resp_status_code != 200 :
@@ -88,24 +91,25 @@ def cancel_scans(scan_ids: List[str]) -> List[dict]:
8891
8992
9093def cancel_scan (scan_id : str ) -> dict :
91-
9294 scan = retrieve_scan (scan_id )
9395 target = scan .get ("target" , {})
9496
9597 scan_cancel_url = PROBELY_API_SCAN_CANCEL_URL .format (
9698 target_id = target .get ("id" ), scan_id = scan_id
9799 )
98100
99- resp_status_code , resp_content = ProbelyAPIClient ().post (
100- scan_cancel_url ,
101- {
102- "target_options" : {
103- "site" : target .get ("site" ),
104- "scanning_agent" : target .get ("scanning_agent" ),
105- },
106- "has_sequence_navigation" : scan .get ("has_sequence_navigation" ),
107- "user_data" : scan .get ("user_data" ),
101+ payload = {
102+ "target_options" : {
103+ "site" : target .get ("site" ),
104+ "scanning_agent" : target .get ("scanning_agent" ),
108105 },
106+ "has_sequence_navigation" : scan .get ("has_sequence_navigation" ),
107+ "user_data" : scan .get ("user_data" ),
108+ }
109+
110+ resp_status_code , resp_content = ProbelyAPIClient .post (
111+ scan_cancel_url ,
112+ payload = payload ,
109113 )
110114
111115 if resp_status_code != 200 :
@@ -122,16 +126,18 @@ def pause_scan(scan_id: str) -> dict:
122126 target_id = target .get ("id" ), scan_id = scan_id
123127 )
124128
129+ payload = {
130+ "target_options" : {
131+ "site" : target .get ("site" ),
132+ "scanning_agent" : target .get ("scanning_agent" ),
133+ },
134+ "has_sequence_navigation" : scan .get ("has_sequence_navigation" ),
135+ "user_data" : scan .get ("user_data" ),
136+ }
137+
125138 resp_status_code , resp_content = ProbelyAPIClient .post (
126139 scan_pause_url ,
127- {
128- "target_options" : {
129- "site" : target .get ("site" ),
130- "scanning_agent" : target .get ("scanning_agent" ),
131- },
132- "has_sequence_navigation" : scan .get ("has_sequence_navigation" ),
133- "user_data" : scan .get ("user_data" ),
134- },
140+ payload = payload ,
135141 )
136142
137143 if resp_status_code != 200 :
@@ -146,8 +152,11 @@ def pause_scans(scan_ids: List[str]) -> List[dict]:
146152 for scan_id in scan_ids :
147153 scan = retrieve_scan (scan_id )
148154
155+ payload = {"scans" : [{"id" : scan_id } for scan_id in scan_ids ]}
156+
149157 resp_status_code , resp_content = ProbelyAPIClient .post (
150- scan_pause_url , {"scans" : [{"id" : scan_id } for scan_id in scan_ids ]}
158+ scan_pause_url ,
159+ payload = payload ,
151160 )
152161
153162 if resp_status_code != 200 :
@@ -169,16 +178,18 @@ def resume_scan(scan_id: str) -> dict:
169178 target_id = target .get ("id" ), scan_id = scan_id
170179 )
171180
172- resp_status_code , resp_content = ProbelyAPIClient ().post (
173- scan_resume_url ,
174- {
175- "target_options" : {
176- "site" : target .get ("site" ),
177- "scanning_agent" : target .get ("scanning_agent" ),
178- },
179- "has_sequence_navigation" : scan .get ("has_sequence_navigation" ),
180- "user_data" : scan .get ("user_data" ),
181+ payload = {
182+ "target_options" : {
183+ "site" : target .get ("site" ),
184+ "scanning_agent" : target .get ("scanning_agent" ),
181185 },
186+ "has_sequence_navigation" : scan .get ("has_sequence_navigation" ),
187+ "user_data" : scan .get ("user_data" ),
188+ }
189+
190+ resp_status_code , resp_content = ProbelyAPIClient .post (
191+ scan_resume_url ,
192+ payload = payload ,
182193 )
183194
184195 if resp_status_code != 200 :
@@ -198,7 +209,9 @@ def resume_scans(scan_ids: List[str], ignore_blackout_period=False) -> List[Dict
198209 "overrides" : {"ignore_blackout_period" : ignore_blackout_period },
199210 }
200211
201- resp_status_code , resp_content = ProbelyAPIClient .post (scan_resume_url , payload )
212+ resp_status_code , resp_content = ProbelyAPIClient .post (
213+ scan_resume_url , payload = payload
214+ )
202215
203216 if resp_status_code != 200 :
204217 raise ProbelyRequestFailed (resp_content , resp_status_code )
0 commit comments