Code Duplication    Length = 85-85 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 1366-1450 (lines=85) @@
1363
            auto_add_new_families=auto_add_new_families,
1364
        )
1365
1366
    def modify_tag(
1367
        self,
1368
        tag_id: str,
1369
        *,
1370
        comment: Optional[str] = None,
1371
        name: Optional[str] = None,
1372
        value=None,
1373
        active=None,
1374
        resource_action: Optional[str] = None,
1375
        resource_type: Optional[EntityType] = None,
1376
        resource_filter: Optional[str] = None,
1377
        resource_ids: Optional[List[str]] = None,
1378
    ) -> Any:
1379
        """Modifies an existing tag.
1380
1381
        Arguments:
1382
            tag_id: UUID of the tag.
1383
            comment: Comment to add to the tag.
1384
            name: Name of the tag.
1385
            value: Value of the tag.
1386
            active: Whether the tag is active.
1387
            resource_action: Whether to add or remove resources instead of
1388
                overwriting. One of '', 'add', 'set' or 'remove'.
1389
            resource_type: Type of the resources to which to attach the tag.
1390
                Required if resource_filter is set.
1391
            resource_filter: Filter term to select resources the tag is to be
1392
                attached to.
1393
            resource_ids: IDs of the resources to which to attach the tag.
1394
1395
        Returns:
1396
            The response. See :py:meth:`send_command` for details.
1397
        """
1398
        if not tag_id:
1399
            raise RequiredArgument(
1400
                function=self.modify_tag.__name__, argument='tag_id'
1401
            )
1402
1403
        cmd = XmlCommand("modify_tag")
1404
        cmd.set_attribute("tag_id", str(tag_id))
1405
1406
        if comment:
1407
            cmd.add_element("comment", comment)
1408
1409
        if name:
1410
            cmd.add_element("name", name)
1411
1412
        if value:
1413
            cmd.add_element("value", value)
1414
1415
        if active is not None:
1416
            cmd.add_element("active", _to_bool(active))
1417
1418
        if resource_action or resource_filter or resource_ids or resource_type:
1419
            if resource_filter and not resource_type:
1420
                raise RequiredArgument(
1421
                    function=self.modify_tag.__name__, argument='resource_type'
1422
                )
1423
1424
            _xmlresources = cmd.add_element("resources")
1425
            if resource_action is not None:
1426
                _xmlresources.set_attribute("action", resource_action)
1427
1428
            if resource_filter is not None:
1429
                _xmlresources.set_attribute("filter", resource_filter)
1430
1431
            for resource_id in resource_ids or []:
1432
                _xmlresources.add_element(
1433
                    "resource", attrs={"id": str(resource_id)}
1434
                )
1435
1436
            if resource_type is not None:
1437
                if not isinstance(resource_type, self.types.EntityType):
1438
                    raise InvalidArgumentType(
1439
                        function=self.modify_tag.__name__,
1440
                        argument="resource_type",
1441
                        arg_type=EntityType.__name__,
1442
                    )
1443
                _actual_resource_type = resource_type
1444
                if resource_type.value == EntityType.AUDIT.value:
1445
                    _actual_resource_type = EntityType.TASK
1446
                elif resource_type.value == EntityType.POLICY.value:
1447
                    _actual_resource_type = EntityType.SCAN_CONFIG
1448
                _xmlresources.add_element("type", _actual_resource_type.value)
1449
1450
        return self._send_xml_command(cmd)
1451
1452
    def modify_tls_certificate(
1453
        self,

gvm/protocols/gmpv9/gmpv9.py 1 location

@@ 1239-1323 (lines=85) @@
1236
            auto_add_new_families=auto_add_new_families,
1237
        )
1238
1239
    def modify_tag(
1240
        self,
1241
        tag_id: str,
1242
        *,
1243
        comment: Optional[str] = None,
1244
        name: Optional[str] = None,
1245
        value=None,
1246
        active=None,
1247
        resource_action: Optional[str] = None,
1248
        resource_type: Optional[EntityType] = None,
1249
        resource_filter: Optional[str] = None,
1250
        resource_ids: Optional[List[str]] = None,
1251
    ) -> Any:
1252
        """Modifies an existing tag.
1253
1254
        Arguments:
1255
            tag_id: UUID of the tag.
1256
            comment: Comment to add to the tag.
1257
            name: Name of the tag.
1258
            value: Value of the tag.
1259
            active: Whether the tag is active.
1260
            resource_action: Whether to add or remove resources instead of
1261
                overwriting. One of '', 'add', 'set' or 'remove'.
1262
            resource_type: Type of the resources to which to attach the tag.
1263
                Required if resource_filter is set.
1264
            resource_filter: Filter term to select resources the tag is to be
1265
                attached to.
1266
            resource_ids: IDs of the resources to which to attach the tag.
1267
1268
        Returns:
1269
            The response. See :py:meth:`send_command` for details.
1270
        """
1271
        if not tag_id:
1272
            raise RequiredArgument(
1273
                function=self.modify_tag.__name__, argument='tag_id'
1274
            )
1275
1276
        cmd = XmlCommand("modify_tag")
1277
        cmd.set_attribute("tag_id", str(tag_id))
1278
1279
        if comment:
1280
            cmd.add_element("comment", comment)
1281
1282
        if name:
1283
            cmd.add_element("name", name)
1284
1285
        if value:
1286
            cmd.add_element("value", value)
1287
1288
        if active is not None:
1289
            cmd.add_element("active", _to_bool(active))
1290
1291
        if resource_action or resource_filter or resource_ids or resource_type:
1292
            if resource_filter and not resource_type:
1293
                raise RequiredArgument(
1294
                    function=self.modify_tag.__name__, argument='resource_type'
1295
                )
1296
1297
            _xmlresources = cmd.add_element("resources")
1298
            if resource_action is not None:
1299
                _xmlresources.set_attribute("action", resource_action)
1300
1301
            if resource_filter is not None:
1302
                _xmlresources.set_attribute("filter", resource_filter)
1303
1304
            for resource_id in resource_ids or []:
1305
                _xmlresources.add_element(
1306
                    "resource", attrs={"id": str(resource_id)}
1307
                )
1308
1309
            if resource_type is not None:
1310
                if not isinstance(resource_type, self.types.EntityType):
1311
                    raise InvalidArgumentType(
1312
                        function=self.modify_tag.__name__,
1313
                        argument="resource_type",
1314
                        arg_type=EntityType.__name__,
1315
                    )
1316
                _actual_resource_type = resource_type
1317
                if resource_type.value == EntityType.AUDIT.value:
1318
                    _actual_resource_type = EntityType.TASK
1319
                elif resource_type.value == EntityType.POLICY.value:
1320
                    _actual_resource_type = EntityType.SCAN_CONFIG
1321
                _xmlresources.add_element("type", _actual_resource_type.value)
1322
1323
        return self._send_xml_command(cmd)
1324
1325
    def modify_tls_certificate(
1326
        self,