Skip to content

Commit a1fef2e

Browse files
committed
had to remove inhertiance due to argument type change in create_credential
1 parent 2c14d8e commit a1fef2e

File tree

2 files changed

+115
-4
lines changed

2 files changed

+115
-4
lines changed

gvm/protocols/gmp/requests/next/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from gvm.protocols.gmp.requests.next._agent_groups import AgentGroups
66
from gvm.protocols.gmp.requests.next._agent_installers import AgentInstallers
77
from gvm.protocols.gmp.requests.next._agents import Agents
8+
from gvm.protocols.gmp.requests.next._credential_stores import CredentialStores
89
from gvm.protocols.gmp.requests.next._credentials import (
910
Credentials,
1011
CredentialType,
1112
)
12-
from gvm.protocols.gmp.requests.next._credential_stores import CredentialStores
1313
from gvm.protocols.gmp.requests.next._oci_image_targets import OCIImageTargets
1414
from gvm.protocols.gmp.requests.next._tasks import Tasks
1515

gvm/protocols/gmp/requests/next/_credentials.py

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
from gvm.xml import XmlCommand
1212

1313
from .._entity_id import EntityID
14-
1514
from ..v224._credentials import (
16-
Credentials as CredentialsV224,
15+
CredentialFormat,
1716
SnmpAuthAlgorithm,
1817
SnmpPrivacyAlgorithm,
1918
)
@@ -39,7 +38,24 @@ class CredentialType(Enum):
3938
CREDENTIAL_STORE_PASSWORD_ONLY = "cs_pw"
4039

4140

42-
class Credentials(CredentialsV224):
41+
class Credentials:
42+
@classmethod
43+
def clone_credential(cls, credential_id: EntityID) -> Request:
44+
"""Clone a credential
45+
46+
Args:
47+
credential_id: The ID of the credential to clone
48+
"""
49+
if not credential_id:
50+
raise RequiredArgument(
51+
function=cls.clone_credential.__name__,
52+
argument="credential_id",
53+
)
54+
55+
cmd = XmlCommand("create_credential")
56+
cmd.add_element("copy", str(credential_id))
57+
return cmd
58+
4359
@classmethod
4460
def create_credential(
4561
cls,
@@ -360,6 +376,101 @@ def create_credential(
360376

361377
return cmd
362378

379+
@classmethod
380+
def delete_credential(
381+
cls, credential_id: EntityID, *, ultimate: Optional[bool] = False
382+
) -> Request:
383+
"""Delete a credential
384+
385+
Args:
386+
credential_id: The ID of the credential to delete
387+
ultimate: Whether to remove entirely, or to the trashcan.
388+
"""
389+
if not credential_id:
390+
raise RequiredArgument(
391+
function=cls.delete_credential.__name__,
392+
argument="credential_id",
393+
)
394+
395+
cmd = XmlCommand("delete_credential")
396+
cmd.set_attribute("credential_id", str(credential_id))
397+
cmd.set_attribute("ultimate", to_bool(ultimate))
398+
return cmd
399+
400+
@staticmethod
401+
def get_credentials(
402+
*,
403+
filter_string: Optional[str] = None,
404+
filter_id: Optional[EntityID] = None,
405+
scanners: Optional[bool] = None,
406+
trash: Optional[bool] = None,
407+
targets: Optional[bool] = None,
408+
) -> Request:
409+
"""Request a list of credentials
410+
411+
Arguments:
412+
filter_string: Filter term to use for the query
413+
filter_id: UUID of an existing filter to use for the query
414+
scanners: Whether to include a list of scanners using the
415+
credentials
416+
trash: Whether to get the trashcan credentials instead
417+
targets: Whether to include a list of targets using the credentials
418+
"""
419+
cmd = XmlCommand("get_credentials")
420+
421+
cmd.add_filter(filter_string, filter_id)
422+
423+
if scanners is not None:
424+
cmd.set_attribute("scanners", to_bool(scanners))
425+
426+
if trash is not None:
427+
cmd.set_attribute("trash", to_bool(trash))
428+
429+
if targets is not None:
430+
cmd.set_attribute("targets", to_bool(targets))
431+
432+
return cmd
433+
434+
@classmethod
435+
def get_credential(
436+
cls,
437+
credential_id: EntityID,
438+
*,
439+
scanners: Optional[bool] = None,
440+
targets: Optional[bool] = None,
441+
credential_format: Optional[Union[CredentialFormat, str]] = None,
442+
) -> Request:
443+
"""Request a single credential
444+
445+
Arguments:
446+
credential_id: UUID of an existing credential
447+
scanners: Whether to include a list of scanners using the
448+
credentials
449+
targets: Whether to include a list of targets using the credentials
450+
credential_format: One of "key", "rpm", "deb", "exe" or "pem"
451+
"""
452+
if not credential_id:
453+
raise RequiredArgument(
454+
function=cls.get_credential.__name__, argument="credential_id"
455+
)
456+
457+
cmd = XmlCommand("get_credentials")
458+
cmd.set_attribute("credential_id", str(credential_id))
459+
460+
if credential_format:
461+
if not isinstance(credential_format, CredentialFormat):
462+
credential_format = CredentialFormat(credential_format)
463+
464+
cmd.set_attribute("format", credential_format.value)
465+
466+
if scanners is not None:
467+
cmd.set_attribute("scanners", to_bool(scanners))
468+
469+
if targets is not None:
470+
cmd.set_attribute("targets", to_bool(targets))
471+
472+
return cmd
473+
363474
@classmethod
364475
def modify_credential(
365476
cls,

0 commit comments

Comments
 (0)