@@ -248,6 +248,97 @@ def create_container_task(
248248 """
249249 return cls .create_import_task (name = name , comment = comment )
250250
251+ @classmethod
252+ def create_web_application_task (
253+ cls ,
254+ name : str ,
255+ web_application_target_id : EntityID ,
256+ scanner_id : EntityID ,
257+ * ,
258+ comment : str | None = None ,
259+ alterable : bool | None = None ,
260+ schedule_id : EntityID | None = None ,
261+ alert_ids : Sequence [EntityID ] | None = None ,
262+ schedule_periods : int | None = None ,
263+ observers : Sequence [str ] | None = None ,
264+ preferences : Mapping [str , SupportsStr ] | None = None ,
265+ ) -> Request :
266+ """Create a new scan task using a web application target.
267+
268+ Args:
269+ name: Name of the new task.
270+ web_application_target_id: UUID of the web application target to be scanned.
271+ scanner_id: UUID of scanner to use for scanning the web application.
272+ comment: Optional comment for the task.
273+ alterable: Whether the task should be alterable.
274+ alert_ids: List of UUIDs for alerts to be applied to the task.
275+ schedule_id: UUID of a schedule when the task should be run.
276+ schedule_periods: Limit to number of scheduled runs, 0 for unlimited.
277+ observers: List of usernames or IDs allowed to observe the task.
278+ preferences: Scanner preferences as name/value pairs.
279+ """
280+ if not name :
281+ raise RequiredArgument (
282+ function = cls .create_web_application_task .__name__ ,
283+ argument = "name" ,
284+ )
285+
286+ if not web_application_target_id :
287+ raise RequiredArgument (
288+ function = cls .create_web_application_task .__name__ ,
289+ argument = "web_application_target_id" ,
290+ )
291+
292+ if not scanner_id :
293+ raise RequiredArgument (
294+ function = cls .create_web_application_task .__name__ ,
295+ argument = "scanner_id" ,
296+ )
297+
298+ cmd = XmlCommand ("create_task" )
299+ cmd .add_element ("name" , name )
300+ cmd .add_element ("usage_type" , "scan" )
301+ cmd .add_element (
302+ "web_application_target" ,
303+ attrs = {"id" : str (web_application_target_id )},
304+ )
305+ cmd .add_element ("scanner" , attrs = {"id" : str (scanner_id )})
306+
307+ if comment :
308+ cmd .add_element ("comment" , comment )
309+
310+ if alterable is not None :
311+ cmd .add_element ("alterable" , to_bool (alterable ))
312+
313+ if alert_ids :
314+ for alert in alert_ids :
315+ cmd .add_element ("alert" , attrs = {"id" : str (alert )})
316+
317+ if schedule_id :
318+ cmd .add_element ("schedule" , attrs = {"id" : str (schedule_id )})
319+
320+ if schedule_periods is not None :
321+ if (
322+ not isinstance (schedule_periods , Integral )
323+ or schedule_periods < 0
324+ ):
325+ raise InvalidArgument (
326+ "schedule_periods must be an integer greater or equal than 0"
327+ )
328+ cmd .add_element ("schedule_periods" , str (schedule_periods ))
329+
330+ if observers :
331+ cmd .add_element ("observers" , to_comma_list (observers ))
332+
333+ if preferences is not None :
334+ xml_prefs = cmd .add_element ("preferences" )
335+ for pref_name , pref_value in preferences .items ():
336+ xml_pref = xml_prefs .add_element ("preference" )
337+ xml_pref .add_element ("scanner_name" , pref_name )
338+ xml_pref .add_element ("value" , str (pref_value ))
339+
340+ return cmd
341+
251342 @classmethod
252343 def create_task (
253344 cls ,
@@ -453,6 +544,7 @@ def modify_task(
453544 scanner_id : EntityID | None = None ,
454545 agent_group_id : EntityID | None = None ,
455546 oci_image_target_id : EntityID | None = None ,
547+ web_application_target_id : EntityID | None = None ,
456548 alterable : bool | None = None ,
457549 hosts_ordering : HostsOrdering | None = None ,
458550 schedule_id : EntityID | None = None ,
@@ -472,6 +564,7 @@ def modify_task(
472564 scanner_id: UUID of scanner to use for scanning the target
473565 agent_group_id: UUID of agent group to use for scanning
474566 oci_image_target_id: UUID of the OCI Image target to be scanned.
567+ web_application_target_id: UUID of the web application target to be scanned.
475568 comment: The comment on the task.
476569 alert_ids: List of UUIDs for alerts to be applied to the task
477570 hosts_ordering: The order hosts are scanned in
@@ -507,6 +600,30 @@ def modify_task(
507600 cmd = XmlCommand ("modify_task" )
508601 cmd .set_attribute ("task_id" , str (task_id ))
509602
603+ if (
604+ sum (
605+ entity_id is not None
606+ for entity_id in (
607+ target_id ,
608+ agent_group_id ,
609+ oci_image_target_id ,
610+ web_application_target_id ,
611+ )
612+ )
613+ > 1
614+ ):
615+ raise InvalidArgument (
616+ function = cls .modify_task .__name__ ,
617+ argument = (
618+ "target_id/agent_group_id/oci_image_target_id/"
619+ "web_application_target_id"
620+ ),
621+ message = (
622+ "Only one of target_id, agent_group_id, oci_image_target_id "
623+ "or web_application_target_id can be modified at a time"
624+ ),
625+ )
626+
510627 if name :
511628 cmd .add_element ("name" , name )
512629
@@ -526,6 +643,11 @@ def modify_task(
526643 cmd .add_element (
527644 "oci_image_target" , attrs = {"id" : str (oci_image_target_id )}
528645 )
646+ if web_application_target_id :
647+ cmd .add_element (
648+ "web_application_target" ,
649+ attrs = {"id" : str (web_application_target_id )},
650+ )
529651
530652 if alterable is not None :
531653 cmd .add_element ("alterable" , to_bool (alterable ))
0 commit comments