python-gvm 27.10.1__py3-none-any.whl → 27.11.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gvm/__version__.py CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  # THIS IS AN AUTOGENERATED FILE. DO NOT TOUCH!
4
4
 
5
- __version__ = "27.10.1"
5
+ __version__ = "27.11.0"
@@ -4,6 +4,7 @@
4
4
 
5
5
  import logging
6
6
  import socket as socketlib
7
+ import ssl
7
8
  from abc import ABC, abstractmethod
8
9
  from time import time
9
10
  from typing import Protocol, runtime_checkable
@@ -16,6 +17,14 @@ DEFAULT_TIMEOUT = 60 # in seconds
16
17
 
17
18
  logger = logging.getLogger(__name__)
18
19
 
20
+ # Errors raised by a socket if the remote server has closed the connection.
21
+ # The SSL errors are raised by TLS sockets and aren't ConnectionErrors.
22
+ REMOTE_CLOSED_ERRORS = (
23
+ ConnectionError,
24
+ ssl.SSLEOFError,
25
+ ssl.SSLZeroReturnError,
26
+ )
27
+
19
28
 
20
29
  @runtime_checkable
21
30
  class GvmConnection(Protocol):
@@ -82,11 +91,22 @@ class AbstractGvmConnection(ABC):
82
91
 
83
92
  Args:
84
93
  data: Data to be send to the server as bytes.
94
+
95
+ Raises:
96
+ GvmError: If the socket is not connected or the remote server
97
+ has closed the connection. In the latter case the connection
98
+ needs to be re-established via :py:meth:`connect`.
85
99
  """
86
100
  if self._socket is None:
87
101
  raise GvmError("Socket is not connected")
88
102
 
89
- self._socket.sendall(data)
103
+ try:
104
+ self._socket.sendall(data)
105
+ except REMOTE_CLOSED_ERRORS as e:
106
+ # Connection was closed by server, e.g. after an error response
107
+ raise GvmError(
108
+ f"Remote closed the connection. Error was {e}"
109
+ ) from e
90
110
 
91
111
  def read(self) -> bytes:
92
112
  """Read data from the remote server
@@ -98,7 +118,13 @@ class AbstractGvmConnection(ABC):
98
118
  time() + self._timeout if self._timeout is not None else None
99
119
  )
100
120
 
101
- data = self._read()
121
+ try:
122
+ data = self._read()
123
+ except REMOTE_CLOSED_ERRORS as e:
124
+ # Connection was reset by server
125
+ raise GvmError(
126
+ f"Remote closed the connection. Error was {e}"
127
+ ) from e
102
128
 
103
129
  if not data:
104
130
  # Connection was closed by server
@@ -11,6 +11,10 @@ from ...utils import SupportsStr
11
11
  from .._protocol import T
12
12
  from ._gmp227 import GMPv227
13
13
  from .requests.next import (
14
+ ActiveDirectory,
15
+ ActiveDirectoryObjectType,
16
+ ActiveDirectorySearchScope,
17
+ ActiveDirectoryTlsMode,
14
18
  AgentGroups,
15
19
  AgentInstallerInstructionLanguageType,
16
20
  AgentInstallerInstructions,
@@ -35,6 +39,7 @@ from .requests.next import (
35
39
  ReportVulnerabilities,
36
40
  ScanReports,
37
41
  Targets,
42
+ TargetSource,
38
43
  Tasks,
39
44
  Timezones,
40
45
  WebApplicationTargets,
@@ -128,6 +133,9 @@ class GMPNext(GMPv227[T]):
128
133
  authorized: Whether the agent is authorized.
129
134
  update_to_latest: Whether the agent is allowed to update to latest automatically.
130
135
  config: Nested config for Agent Controller.
136
+ Optional file_search.excluded_paths contains a sequence of
137
+ path strings. Use an empty sequence to clear excluded paths.
138
+ Paths are sent as provided.
131
139
  comment: Optional comment for the change.
132
140
  """
133
141
  return self._send_request_and_transform_response(
@@ -161,6 +169,9 @@ class GMPNext(GMPv227[T]):
161
169
  Args:
162
170
  agent_control_id: The agent control UUID.
163
171
  config: Nested config for Agent Controller.
172
+ Optional agent_defaults.file_search.excluded_paths contains
173
+ a sequence of path strings. Use an empty sequence to clear
174
+ excluded paths. Paths are sent as provided.
164
175
  """
165
176
  return self._send_request_and_transform_response(
166
177
  Agents.modify_agent_control_scan_config(
@@ -218,6 +229,7 @@ class GMPNext(GMPv227[T]):
218
229
  agent_ids: list[str],
219
230
  scheduler_cron_time: str,
220
231
  *,
232
+ max_delay_seconds: int | None = None,
221
233
  comment: str | None = None,
222
234
  ) -> T:
223
235
  """Create a new agent group.
@@ -226,6 +238,7 @@ class GMPNext(GMPv227[T]):
226
238
  name: Name of the new agent group.
227
239
  agent_ids: List of agent UUIDs to include in the group (required).
228
240
  scheduler_cron_time: Scheduler cron to use.
241
+ max_delay_seconds: Max delay seconds to use.
229
242
  comment: Optional comment for the group.
230
243
 
231
244
  Raises:
@@ -237,6 +250,7 @@ class GMPNext(GMPv227[T]):
237
250
  comment=comment,
238
251
  agent_ids=agent_ids,
239
252
  scheduler_cron_time=scheduler_cron_time,
253
+ max_delay_seconds=max_delay_seconds,
240
254
  )
241
255
  )
242
256
 
@@ -248,6 +262,7 @@ class GMPNext(GMPv227[T]):
248
262
  name: str | None = None,
249
263
  comment: str | None = None,
250
264
  agent_ids: list[str] | None = None,
265
+ max_delay_seconds: int | None = None,
251
266
  ) -> T:
252
267
  """Modify an existing agent group.
253
268
 
@@ -257,6 +272,7 @@ class GMPNext(GMPv227[T]):
257
272
  scheduler_cron_time: Scheduler cron to use.
258
273
  comment: Optional comment for the group.
259
274
  agent_ids: Optional list of agent UUIDs to set for the group.
275
+ max_delay_seconds: Optional maximum delay for agent groups.
260
276
 
261
277
  Raises:
262
278
  RequiredArgument: If agent_group_id is not provided.
@@ -268,6 +284,7 @@ class GMPNext(GMPv227[T]):
268
284
  comment=comment,
269
285
  agent_ids=agent_ids,
270
286
  scheduler_cron_time=scheduler_cron_time,
287
+ max_delay_seconds=max_delay_seconds,
271
288
  )
272
289
  )
273
290
 
@@ -317,6 +334,7 @@ class GMPNext(GMPv227[T]):
317
334
  agent_id: EntityID,
318
335
  days: int = 0,
319
336
  encryption: bool = True,
337
+ anonymized: bool = False,
320
338
  ) -> T:
321
339
  """Request a support bundle for an agent.
322
340
 
@@ -325,6 +343,7 @@ class GMPNext(GMPv227[T]):
325
343
  days: Number of days of logs to include. If None, zero is sent so the
326
344
  Agent Controller uses its configured default.
327
345
  encryption: Whether an encrypted or plain support bundle is requested.
346
+ anonymized: Whether an anonymized support bundle is requested.
328
347
 
329
348
  Raises:
330
349
  RequiredArgument: If agent_id is missing.
@@ -335,6 +354,212 @@ class GMPNext(GMPv227[T]):
335
354
  agent_id,
336
355
  days=days,
337
356
  encryption=encryption,
357
+ anonymized=anonymized,
358
+ )
359
+ )
360
+
361
+ def get_agent_inventory_token(self) -> T:
362
+ """Request a short-lived agent inventory token.
363
+
364
+ The token is used to authenticate requests to the agent-control API
365
+ using Authorization: Bearer <token>.
366
+
367
+ The authenticated user must have the get_agents permission.
368
+ """
369
+ return self._send_request_and_transform_response(
370
+ Agents.get_agent_inventory_token()
371
+ )
372
+
373
+ def create_active_directory_credential(
374
+ self,
375
+ name: str,
376
+ *,
377
+ host: str,
378
+ bind_dn: str,
379
+ base_dn: str,
380
+ bind_password: str,
381
+ tls_mode: ActiveDirectoryTlsMode | str,
382
+ comment: str | None = None,
383
+ port: int | None = None,
384
+ ca_certificate: str | None = None,
385
+ ) -> T:
386
+ """Create an Active Directory credential.
387
+
388
+ Requires AD integration to be enabled in gvmd.
389
+
390
+ Args:
391
+ name: Name of the credential.
392
+ host: Active Directory server hostname or IP address.
393
+ bind_dn: Distinguished name used to bind to the directory.
394
+ base_dn: Base distinguished name for directory searches.
395
+ bind_password: Password used to bind to the directory.
396
+ tls_mode: TLS mode, either "ldaps" or "starttls".
397
+ comment: Optional comment for the credential.
398
+ port: Server port (1 to 65535). Omit to use the connector default.
399
+ ca_certificate: Optional CA certificate in PEM format.
400
+ """
401
+ return self._send_request_and_transform_response(
402
+ Credentials.create_active_directory_credential(
403
+ name=name,
404
+ host=host,
405
+ bind_dn=bind_dn,
406
+ base_dn=base_dn,
407
+ bind_password=bind_password,
408
+ tls_mode=tls_mode,
409
+ comment=comment,
410
+ port=port,
411
+ ca_certificate=ca_certificate,
412
+ )
413
+ )
414
+
415
+ def modify_active_directory_credential(
416
+ self,
417
+ credential_id: EntityID,
418
+ *,
419
+ name: str | None = None,
420
+ comment: str | None = None,
421
+ host: str | None = None,
422
+ bind_dn: str | None = None,
423
+ base_dn: str | None = None,
424
+ bind_password: str | None = None,
425
+ tls_mode: ActiveDirectoryTlsMode | str | None = None,
426
+ port: int | str | None = None,
427
+ ca_certificate: str | None = None,
428
+ ) -> T:
429
+ """Modify an Active Directory credential.
430
+
431
+ Requires AD integration to be enabled in gvmd. Fields set to None
432
+ are left unchanged.
433
+
434
+ Args:
435
+ credential_id: UUID of the credential to modify.
436
+ name: New name of the credential.
437
+ comment: New comment. An empty string clears the comment.
438
+ host: Active Directory server hostname or IP address.
439
+ bind_dn: Distinguished name used to bind to the directory.
440
+ base_dn: Base distinguished name for directory searches.
441
+ bind_password: Password used to bind to the directory.
442
+ tls_mode: TLS mode, either "ldaps" or "starttls".
443
+ port: Server port (1 to 65535), or an empty string to restore
444
+ the connector default. Nonempty strings are not accepted.
445
+ ca_certificate: CA certificate in PEM format. An empty string
446
+ clears the certificate.
447
+ """
448
+ return self._send_request_and_transform_response(
449
+ Credentials.modify_active_directory_credential(
450
+ credential_id=credential_id,
451
+ name=name,
452
+ comment=comment,
453
+ host=host,
454
+ bind_dn=bind_dn,
455
+ base_dn=base_dn,
456
+ bind_password=bind_password,
457
+ tls_mode=tls_mode,
458
+ port=port,
459
+ ca_certificate=ca_certificate,
460
+ )
461
+ )
462
+
463
+ def verify_active_directory_credential(
464
+ self,
465
+ *,
466
+ credential_id: EntityID | None = None,
467
+ host: str | None = None,
468
+ bind_dn: str | None = None,
469
+ bind_password: str | None = None,
470
+ base_dn: str | None = None,
471
+ tls_mode: ActiveDirectoryTlsMode | str | None = None,
472
+ port: int | None = None,
473
+ ca_certificate: str | None = None,
474
+ ) -> T:
475
+ """Verify a saved AD credential or supplied AD connection settings.
476
+
477
+ Requires AD integration to be enabled in gvmd. Provide either
478
+ credential_id alone or the required inline connection fields.
479
+
480
+ Args:
481
+ credential_id: UUID of a saved AD credential.
482
+ host: AD server hostname or IP address.
483
+ bind_dn: Distinguished name used to bind to the directory.
484
+ bind_password: Password used for the bind.
485
+ base_dn: Base distinguished name for directory searches.
486
+ tls_mode: TLS mode, either "ldaps" or "starttls".
487
+ port: Optional server port, from 1 to 65535.
488
+ ca_certificate: Optional CA certificate in PEM format.
489
+ """
490
+ return self._send_request_and_transform_response(
491
+ Credentials.verify_active_directory_credential(
492
+ credential_id=credential_id,
493
+ host=host,
494
+ bind_dn=bind_dn,
495
+ bind_password=bind_password,
496
+ base_dn=base_dn,
497
+ tls_mode=tls_mode,
498
+ port=port,
499
+ ca_certificate=ca_certificate,
500
+ )
501
+ )
502
+
503
+ def get_active_directory_objects(
504
+ self,
505
+ credential_id: EntityID,
506
+ *,
507
+ base_dn: str | None = None,
508
+ group_dn: str | None = None,
509
+ scope: ActiveDirectorySearchScope | str | None = None,
510
+ object_types: Sequence[ActiveDirectoryObjectType | str] | None = None,
511
+ max_results: int | None = None,
512
+ include_disabled_computers: bool | None = None,
513
+ targets: bool | None = None,
514
+ tasks: bool | None = None,
515
+ details: bool | None = None,
516
+ ) -> T:
517
+ """Search Active Directory using a saved AD credential.
518
+
519
+ Requires AD integration to be enabled in gvmd and a saved AD
520
+ credential. Options set to None are omitted from the request so that
521
+ gvmd applies its defaults.
522
+
523
+ The response includes per-type counts for the fetched subset and an
524
+ objects truncated attribute indicating whether more objects were
525
+ available.
526
+
527
+ Args:
528
+ credential_id: UUID of a saved AD credential.
529
+ base_dn: Nonempty search base within the credential's base DN.
530
+ Defaults to the credential's base DN.
531
+ group_dn: Nonempty DN selecting explicit direct group members
532
+ within the search base and scope. Must be within the
533
+ credential's base DN.
534
+ scope: Search scope, either "base", "onelevel", or "subtree".
535
+ Defaults to "onelevel", searching immediately below base_dn. Use
536
+ "subtree" to search at all directory depths.
537
+ object_types: Nonempty selection of "ou", "container", "computer",
538
+ or "group". Defaults to "ou", "computer", and "group".
539
+ Duplicates are ignored, preserving first-occurrence order.
540
+ max_results: Maximum number of objects to fetch after LDAP
541
+ filtering. Must be a positive integer within the server's
542
+ configured limit. Omit to use that limit.
543
+ include_disabled_computers: Include disabled computers. Defaults
544
+ to True.
545
+ targets: Include matching targets for computers. Defaults to False.
546
+ tasks: Include tasks and readable configurations for matching
547
+ targets. Requires targets=True. Defaults to False.
548
+ details: Include computer OS version and service principal names.
549
+ Defaults to False.
550
+ """
551
+ return self._send_request_and_transform_response(
552
+ ActiveDirectory.get_active_directory_objects(
553
+ credential_id=credential_id,
554
+ base_dn=base_dn,
555
+ group_dn=group_dn,
556
+ scope=scope,
557
+ object_types=object_types,
558
+ max_results=max_results,
559
+ include_disabled_computers=include_disabled_computers,
560
+ targets=targets,
561
+ tasks=tasks,
562
+ details=details,
338
563
  )
339
564
  )
340
565
 
@@ -1503,6 +1728,7 @@ class GMPNext(GMPv227[T]):
1503
1728
  *,
1504
1729
  asset_hosts_filter: str | None = None,
1505
1730
  hosts: list[str] | None = None,
1731
+ source: TargetSource | str | None = None,
1506
1732
  comment: str | None = None,
1507
1733
  exclude_hosts: list[str] | None = None,
1508
1734
  ssh_credential_id: EntityID | None = None,
@@ -1523,6 +1749,7 @@ class GMPNext(GMPv227[T]):
1523
1749
  name: Name of the target
1524
1750
  asset_hosts_filter: Filter to select target host from assets hosts
1525
1751
  hosts: List of hosts addresses to scan
1752
+ source: Target source. Omit to default to manual.
1526
1753
  exclude_hosts: List of hosts addresses to exclude from scan
1527
1754
  comment: Comment for the target
1528
1755
  ssh_credential_id: UUID of a ssh credential to use on target
@@ -1544,6 +1771,7 @@ class GMPNext(GMPv227[T]):
1544
1771
  name,
1545
1772
  asset_hosts_filter=asset_hosts_filter,
1546
1773
  hosts=hosts,
1774
+ source=source,
1547
1775
  comment=comment,
1548
1776
  exclude_hosts=exclude_hosts,
1549
1777
  ssh_credential_id=ssh_credential_id,
@@ -1567,6 +1795,7 @@ class GMPNext(GMPv227[T]):
1567
1795
  name: str | None = None,
1568
1796
  comment: str | None = None,
1569
1797
  hosts: list[str] | None = None,
1798
+ source: TargetSource | str | None = None,
1570
1799
  exclude_hosts: list[str] | None = None,
1571
1800
  ssh_credential_id: EntityID | None = None,
1572
1801
  ssh_credential_port: str | int | None = None,
@@ -1586,6 +1815,7 @@ class GMPNext(GMPv227[T]):
1586
1815
  comment: Comment on target.
1587
1816
  name: Name of target.
1588
1817
  hosts: List of target hosts.
1818
+ source: Target source. Omit to keep the current source.
1589
1819
  exclude_hosts: A list of hosts to exclude.
1590
1820
  ssh_credential_id: UUID of SSH credential to use on target.
1591
1821
  ssh_credential_port: The port to use for ssh credential
@@ -1606,6 +1836,7 @@ class GMPNext(GMPv227[T]):
1606
1836
  name=name,
1607
1837
  comment=comment,
1608
1838
  hosts=hosts,
1839
+ source=source,
1609
1840
  exclude_hosts=exclude_hosts,
1610
1841
  ssh_credential_id=ssh_credential_id,
1611
1842
  ssh_credential_port=ssh_credential_port,
@@ -2,6 +2,11 @@
2
2
  #
3
3
  # SPDX-License-Identifier: GPL-3.0-or-later
4
4
 
5
+ from gvm.protocols.gmp.requests.next._active_directory import (
6
+ ActiveDirectory,
7
+ ActiveDirectoryObjectType,
8
+ ActiveDirectorySearchScope,
9
+ )
5
10
  from gvm.protocols.gmp.requests.next._agent_groups import AgentGroups
6
11
  from gvm.protocols.gmp.requests.next._agent_installer_instructions import (
7
12
  AgentInstallerInstructionLanguageType,
@@ -11,8 +16,10 @@ from gvm.protocols.gmp.requests.next._agents import Agents
11
16
  from gvm.protocols.gmp.requests.next._audit_report import AuditReport
12
17
  from gvm.protocols.gmp.requests.next._credential_stores import CredentialStores
13
18
  from gvm.protocols.gmp.requests.next._credentials import (
19
+ ActiveDirectoryTlsMode,
14
20
  Credentials,
15
21
  CredentialStoreCredentialType,
22
+ CredentialType,
16
23
  )
17
24
  from gvm.protocols.gmp.requests.next._features import (
18
25
  Features,
@@ -52,7 +59,11 @@ from gvm.protocols.gmp.requests.next._report_vulnerabilities import (
52
59
  ReportVulnerabilities,
53
60
  )
54
61
  from gvm.protocols.gmp.requests.next._scan_report import ScanReports
55
- from gvm.protocols.gmp.requests.next._targets import AliveTest, Targets
62
+ from gvm.protocols.gmp.requests.next._targets import (
63
+ AliveTest,
64
+ Targets,
65
+ TargetSource,
66
+ )
56
67
  from gvm.protocols.gmp.requests.next._tasks import Tasks
57
68
  from gvm.protocols.gmp.requests.next._timezones import (
58
69
  Timezones,
@@ -76,7 +87,6 @@ from ..v227 import (
76
87
  CertBundAdvisories,
77
88
  Cpes,
78
89
  CredentialFormat,
79
- CredentialType,
80
90
  Cves,
81
91
  DfnCertAdvisories,
82
92
  EntityType,
@@ -130,6 +140,10 @@ from ..v227 import (
130
140
  )
131
141
 
132
142
  __all__ = (
143
+ "ActiveDirectory",
144
+ "ActiveDirectoryObjectType",
145
+ "ActiveDirectorySearchScope",
146
+ "ActiveDirectoryTlsMode",
133
147
  "AgentGroups",
134
148
  "AgentInstallerInstructionLanguageType",
135
149
  "AgentInstallerInstructions",
@@ -210,6 +224,7 @@ __all__ = (
210
224
  "SystemReports",
211
225
  "TLSCertificates",
212
226
  "Tags",
227
+ "TargetSource",
213
228
  "Targets",
214
229
  "Tasks",
215
230
  "TicketStatus",
@@ -0,0 +1,177 @@
1
+ # SPDX-FileCopyrightText: 2026 Greenbone AG
2
+ #
3
+ # SPDX-License-Identifier: GPL-3.0-or-later
4
+
5
+ from collections.abc import Sequence
6
+
7
+ from gvm._enum import Enum
8
+ from gvm.errors import InvalidArgument, RequiredArgument
9
+ from gvm.protocols.core import Request
10
+ from gvm.utils import to_bool
11
+ from gvm.xml import XmlCommand
12
+
13
+ from .._entity_id import EntityID
14
+
15
+
16
+ class ActiveDirectorySearchScope(Enum):
17
+ """Enum for Active Directory search scopes"""
18
+
19
+ BASE = "base"
20
+ ONELEVEL = "onelevel"
21
+ SUBTREE = "subtree"
22
+
23
+
24
+ class ActiveDirectoryObjectType(Enum):
25
+ """Enum for Active Directory object types"""
26
+
27
+ OU = "ou"
28
+ CONTAINER = "container"
29
+ COMPUTER = "computer"
30
+ GROUP = "group"
31
+
32
+
33
+ class ActiveDirectory:
34
+ @classmethod
35
+ def get_active_directory_objects(
36
+ cls,
37
+ credential_id: EntityID,
38
+ *,
39
+ base_dn: str | None = None,
40
+ group_dn: str | None = None,
41
+ scope: ActiveDirectorySearchScope | str | None = None,
42
+ object_types: Sequence[ActiveDirectoryObjectType | str] | None = None,
43
+ max_results: int | None = None,
44
+ include_disabled_computers: bool | None = None,
45
+ targets: bool | None = None,
46
+ tasks: bool | None = None,
47
+ details: bool | None = None,
48
+ ) -> Request:
49
+ """Search Active Directory using a saved AD credential.
50
+
51
+ Requires AD integration to be enabled in gvmd and a saved AD
52
+ credential. Options set to None are omitted from the request so that
53
+ gvmd applies its defaults.
54
+
55
+ Args:
56
+ credential_id: UUID of a saved AD credential.
57
+ base_dn: Nonempty search base within the credential's base DN.
58
+ Defaults to the credential's base DN.
59
+ group_dn: Nonempty DN selecting explicit direct group members
60
+ within the search base and scope. Must be within the
61
+ credential's base DN.
62
+ scope: Search scope, either "base", "onelevel", or "subtree".
63
+ Defaults to "onelevel", searching immediately below base_dn. Use
64
+ "subtree" to search at all directory depths.
65
+ object_types: Nonempty selection of "ou", "container", "computer",
66
+ or "group". Defaults to "ou", "computer", and "group".
67
+ Duplicates are ignored, preserving first-occurrence order.
68
+ max_results: Maximum number of objects to fetch after LDAP
69
+ filtering. Must be a positive integer within the server's
70
+ configured limit. Omit to use that limit.
71
+ include_disabled_computers: Include disabled computers. Defaults
72
+ to True.
73
+ targets: Include matching targets for computers. Defaults to False.
74
+ tasks: Include tasks and readable configurations for matching
75
+ targets. Requires targets=True. Defaults to False.
76
+ details: Include computer OS version and service principal names.
77
+ Defaults to False.
78
+ """
79
+ if not credential_id:
80
+ raise RequiredArgument(
81
+ function=cls.get_active_directory_objects.__name__,
82
+ argument="credential_id",
83
+ )
84
+ if base_dn is not None and not base_dn:
85
+ raise RequiredArgument(
86
+ function=cls.get_active_directory_objects.__name__,
87
+ argument="base_dn",
88
+ )
89
+ if group_dn is not None and not group_dn:
90
+ raise RequiredArgument(
91
+ function=cls.get_active_directory_objects.__name__,
92
+ argument="group_dn",
93
+ )
94
+ if scope is not None and not scope:
95
+ raise RequiredArgument(
96
+ function=cls.get_active_directory_objects.__name__,
97
+ argument="scope",
98
+ )
99
+ if scope is not None and not isinstance(
100
+ scope, ActiveDirectorySearchScope
101
+ ):
102
+ try:
103
+ scope = ActiveDirectorySearchScope(scope)
104
+ except InvalidArgument as error:
105
+ raise InvalidArgument(
106
+ str(error),
107
+ function=cls.get_active_directory_objects.__name__,
108
+ argument="scope",
109
+ ) from None
110
+ if object_types is not None and (
111
+ isinstance(object_types, str)
112
+ or not object_types
113
+ or any(not object_type for object_type in object_types)
114
+ ):
115
+ raise InvalidArgument(
116
+ function=cls.get_active_directory_objects.__name__,
117
+ argument="object_types",
118
+ )
119
+ try:
120
+ normalized_object_types = (
121
+ list(
122
+ dict.fromkeys(
123
+ ActiveDirectoryObjectType(t) for t in object_types
124
+ )
125
+ )
126
+ if object_types is not None
127
+ else None
128
+ )
129
+ except InvalidArgument as error:
130
+ raise InvalidArgument(
131
+ str(error),
132
+ function=cls.get_active_directory_objects.__name__,
133
+ argument="object_types",
134
+ ) from None
135
+ if max_results is not None and (
136
+ isinstance(max_results, bool)
137
+ or not isinstance(max_results, int)
138
+ or max_results < 1
139
+ ):
140
+ raise InvalidArgument(
141
+ function=cls.get_active_directory_objects.__name__,
142
+ argument="max_results",
143
+ )
144
+ if tasks and not targets:
145
+ raise InvalidArgument(
146
+ function=cls.get_active_directory_objects.__name__,
147
+ argument="tasks",
148
+ )
149
+
150
+ cmd = XmlCommand("get_active_directory_objects")
151
+ cmd.set_attribute("credential_id", str(credential_id))
152
+ if scope is not None:
153
+ cmd.set_attribute("scope", scope.value)
154
+ if max_results is not None:
155
+ cmd.set_attribute("max_results", str(max_results))
156
+ if include_disabled_computers is not None:
157
+ cmd.set_attribute(
158
+ "include_disabled_computers",
159
+ to_bool(include_disabled_computers),
160
+ )
161
+ if targets is not None:
162
+ cmd.set_attribute("targets", to_bool(targets))
163
+ if tasks is not None:
164
+ cmd.set_attribute("tasks", to_bool(tasks))
165
+ if details is not None:
166
+ cmd.set_attribute("details", to_bool(details))
167
+
168
+ if base_dn is not None:
169
+ cmd.add_element("base_dn", base_dn)
170
+ if group_dn is not None:
171
+ cmd.add_element("group_dn", group_dn)
172
+ if normalized_object_types is not None:
173
+ types_element = cmd.add_element("object_types")
174
+ for object_type in normalized_object_types:
175
+ types_element.add_element("object_type", object_type.value)
176
+
177
+ return cmd