Code Duplication    Length = 83-83 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 1 location

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

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