Code Duplication    Length = 83-83 lines in 2 locations

gvm/protocols/gmpv9/gmpv9.py 1 location

@@ 372-454 (lines=83) @@
369
            function=self.create_config.__name__,
370
        )
371
372
    def create_permission(
373
        self,
374
        name: str,
375
        subject_id: str,
376
        subject_type: PermissionSubjectType,
377
        *,
378
        resource_id: Optional[str] = None,
379
        resource_type: Optional[EntityType] = None,
380
        comment: Optional[str] = None,
381
    ) -> Any:
382
        """Create a new permission
383
384
        Arguments:
385
            name: Name of the new permission
386
            subject_id: UUID of subject to whom the permission is granted
387
            subject_type: Type of the subject user, group or role
388
            comment: Comment for the permission
389
            resource_id: UUID of entity to which the permission applies
390
            resource_type: Type of the resource. For Super permissions user,
391
                group or role
392
393
        Returns:
394
            The response. See :py:meth:`send_command` for details.
395
        """
396
        if not name:
397
            raise RequiredArgument(
398
                function=self.create_permission.__name__, argument='name'
399
            )
400
401
        if not subject_id:
402
            raise RequiredArgument(
403
                function=self.create_permission.__name__, argument='subject_id'
404
            )
405
406
        if not isinstance(subject_type, PermissionSubjectType):
407
            raise InvalidArgumentType(
408
                function=self.create_permission.__name__,
409
                argument='subject_type',
410
                arg_type=PermissionSubjectType.__name__,
411
            )
412
413
        cmd = XmlCommand("create_permission")
414
        cmd.add_element("name", name)
415
416
        _xmlsubject = cmd.add_element("subject", attrs={"id": subject_id})
417
        _xmlsubject.add_element("type", subject_type.value)
418
419
        if comment:
420
            cmd.add_element("comment", comment)
421
422
        if resource_id or resource_type:
423
            if not resource_id:
424
                raise RequiredArgument(
425
                    function=self.create_permission.__name__,
426
                    argument='resource_id',
427
                )
428
429
            if not resource_type:
430
                raise RequiredArgument(
431
                    function=self.create_permission.__name__,
432
                    argument='resource_type',
433
                )
434
435
            if not isinstance(resource_type, self.types.EntityType):
436
                raise InvalidArgumentType(
437
                    function=self.create_permission.__name__,
438
                    argument='resource_type',
439
                    arg_type=self.types.EntityType.__name__,
440
                )
441
442
            _xmlresource = cmd.add_element(
443
                "resource", attrs={"id": resource_id}
444
            )
445
446
            _actual_resource_type = resource_type
447
            if resource_type.value == EntityType.AUDIT.value:
448
                _actual_resource_type = EntityType.TASK
449
            elif resource_type.value == EntityType.POLICY.value:
450
                _actual_resource_type = EntityType.SCAN_CONFIG
451
452
            _xmlresource.add_element("type", _actual_resource_type.value)
453
454
        return self._send_xml_command(cmd)
455
456
    def create_policy(
457
        self, name: str, *, policy_id: str = None, comment: Optional[str] = None

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 493-575 (lines=83) @@
490
            function=self.create_config.__name__,
491
        )
492
493
    def create_permission(
494
        self,
495
        name: str,
496
        subject_id: str,
497
        subject_type: PermissionSubjectType,
498
        *,
499
        resource_id: Optional[str] = None,
500
        resource_type: Optional[EntityType] = None,
501
        comment: Optional[str] = None,
502
    ) -> Any:
503
        """Create a new permission
504
505
        Arguments:
506
            name: Name of the new permission
507
            subject_id: UUID of subject to whom the permission is granted
508
            subject_type: Type of the subject user, group or role
509
            comment: Comment for the permission
510
            resource_id: UUID of entity to which the permission applies
511
            resource_type: Type of the resource. For Super permissions user,
512
                group or role
513
514
        Returns:
515
            The response. See :py:meth:`send_command` for details.
516
        """
517
        if not name:
518
            raise RequiredArgument(
519
                function=self.create_permission.__name__, argument='name'
520
            )
521
522
        if not subject_id:
523
            raise RequiredArgument(
524
                function=self.create_permission.__name__, argument='subject_id'
525
            )
526
527
        if not isinstance(subject_type, PermissionSubjectType):
528
            raise InvalidArgumentType(
529
                function=self.create_permission.__name__,
530
                argument='subject_type',
531
                arg_type=PermissionSubjectType.__name__,
532
            )
533
534
        cmd = XmlCommand("create_permission")
535
        cmd.add_element("name", name)
536
537
        _xmlsubject = cmd.add_element("subject", attrs={"id": subject_id})
538
        _xmlsubject.add_element("type", subject_type.value)
539
540
        if comment:
541
            cmd.add_element("comment", comment)
542
543
        if resource_id or resource_type:
544
            if not resource_id:
545
                raise RequiredArgument(
546
                    function=self.create_permission.__name__,
547
                    argument='resource_id',
548
                )
549
550
            if not resource_type:
551
                raise RequiredArgument(
552
                    function=self.create_permission.__name__,
553
                    argument='resource_type',
554
                )
555
556
            if not isinstance(resource_type, self.types.EntityType):
557
                raise InvalidArgumentType(
558
                    function=self.create_permission.__name__,
559
                    argument='resource_type',
560
                    arg_type=self.types.EntityType.__name__,
561
                )
562
563
            _xmlresource = cmd.add_element(
564
                "resource", attrs={"id": resource_id}
565
            )
566
567
            _actual_resource_type = resource_type
568
            if resource_type.value == EntityType.AUDIT.value:
569
                _actual_resource_type = EntityType.TASK
570
            elif resource_type.value == EntityType.POLICY.value:
571
                _actual_resource_type = EntityType.SCAN_CONFIG
572
573
            _xmlresource.add_element("type", _actual_resource_type.value)
574
575
        return self._send_xml_command(cmd)
576
577
    def create_policy(
578
        self, name: str, *, policy_id: str = None, comment: Optional[str] = None