diff --git a/plugins/azure/fix_plugin_azure/azure_client.py b/plugins/azure/fix_plugin_azure/azure_client.py index c0294a3c51..428536e081 100644 --- a/plugins/azure/fix_plugin_azure/azure_client.py +++ b/plugins/azure/fix_plugin_azure/azure_client.py @@ -68,7 +68,10 @@ class AzureResourceSpec: query_parameters: List[str] = [] access_path: Optional[str] = None expect_array: bool = False - expected_error_codes: List[str] = field(factory=list) + expected_error_codes: Dict[str, Optional[str]] = field(factory=dict) + """ + A dictionary that maps specific error codes (str) to corresponding hints (Optional[str]) to provide additional context or troubleshooting information when an error occurs. + """ def request(self, client: "MicrosoftResourceManagementClient", **kwargs: Any) -> HttpRequest: ser = Serializer() @@ -118,7 +121,10 @@ class RestApiSpec: parameters: Optional[Dict[str, str]] = None access_path: Optional[str] = None expect_array: bool = False - expected_error_codes: List[str] = field(factory=list) + expected_error_codes: Dict[str, Optional[str]] = field(factory=dict) + """ + A dictionary that maps specific error codes (str) to corresponding hints (Optional[str]) to provide additional context or troubleshooting information when an error occurs. + """ def __attrs_post_init__(self) -> None: if self.scope == "": @@ -317,13 +323,15 @@ def _list_with_retry(self, spec: MicrosoftRestSpec, **kwargs: Any) -> Optional[L return None except HttpResponseError as e: if error := e.error: + code = error.code or "Unknown" if error.code == "NoRegisteredProviderFound": return None # API not available in this region elif error.code in spec.expected_error_codes: + if hint := spec.expected_error_codes.get(code): + self.accumulator.add_error(False, code, spec.service, spec.action, str(hint)) return None elif error.code == "BadRequest" and spec.service == "metric": raise MetricRequestError from e - code = error.code or "Unknown" self.accumulator.add_error(False, code, spec.service, spec.action, str(e), self.location) log.warning(f"[Azure] Client Error: status={e.status_code}, error={e.error}, message={e}, spec={spec}") return None diff --git a/plugins/azure/fix_plugin_azure/collector.py b/plugins/azure/fix_plugin_azure/collector.py index 384094b151..ac03d9e37c 100644 --- a/plugins/azure/fix_plugin_azure/collector.py +++ b/plugins/azure/fix_plugin_azure/collector.py @@ -17,9 +17,9 @@ MicrosoftResource, ) from fix_plugin_azure.resource.compute import ( - AzureVirtualMachineSize, - AzureDiskType, - AzureDiskTypePricing, + AzureComputeVirtualMachineSize, + AzureComputeDiskType, + AzureComputeDiskTypePricing, resources as compute_resources, ) from fix_plugin_azure.resource.containerservice import resources as aks_resources @@ -32,7 +32,7 @@ from fix_plugin_azure.resource.monitor import resources as monitor_resources from fix_plugin_azure.resource.mysql import AzureMysqlServerType, resources as mysql_resources from fix_plugin_azure.resource.network import ( - AzureExpressRoutePortsLocation, + AzureNetworkExpressRoutePortsLocation, AzureNetworkVirtualApplianceSku, AzureNetworkUsage, resources as network_resources, @@ -256,10 +256,10 @@ def remove_usage_zero_value() -> None: remove_nodes.append(node) self._delete_nodes(remove_nodes) - rm_nodes(AzureVirtualMachineSize, AzureLocation) - rm_nodes(AzureExpressRoutePortsLocation, AzureSubscription) + rm_nodes(AzureComputeVirtualMachineSize, AzureLocation) + rm_nodes(AzureNetworkExpressRoutePortsLocation, AzureSubscription) rm_nodes(AzureNetworkVirtualApplianceSku, AzureSubscription) - rm_nodes(AzureDiskType, AzureSubscription) + rm_nodes(AzureComputeDiskType, AzureSubscription) rm_nodes(AzureMachineLearningVirtualMachineSize, AzureLocation) rm_nodes(AzureStorageSku, AzureLocation) rm_nodes(AzureMysqlServerType, AzureSubscription) @@ -269,9 +269,9 @@ def remove_usage_zero_value() -> None: remove_usage_zero_value() def after_collect(self) -> None: - # Filter unnecessary nodes such as AzureDiskTypePricing + # Filter unnecessary nodes such as AzureComputeDiskTypePricing nodes_to_remove = [] - node_types = (AzureDiskTypePricing,) + node_types = (AzureComputeDiskTypePricing,) for node in self.graph.nodes: if not isinstance(node, node_types): diff --git a/plugins/azure/fix_plugin_azure/resource/authorization.py b/plugins/azure/fix_plugin_azure/resource/authorization.py index 54b247f443..1ed0cc4378 100644 --- a/plugins/azure/fix_plugin_azure/resource/authorization.py +++ b/plugins/azure/fix_plugin_azure/resource/authorization.py @@ -59,8 +59,8 @@ class AzurePrincipal: @define(eq=False, slots=False) -class AzureDenyAssignment(MicrosoftResource): - kind: ClassVar[str] = "azure_deny_assignment" +class AzureAuthorizationDenyAssignment(MicrosoftResource): + kind: ClassVar[str] = "azure_authorization_deny_assignment" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="authorization", version="2022-04-01", @@ -109,8 +109,8 @@ class AzureDenyAssignment(MicrosoftResource): @define(eq=False, slots=False) -class AzureRoleAssignment(MicrosoftResource): - kind: ClassVar[str] = "azure_role_assignment" +class AzureAuthorizationRoleAssignment(MicrosoftResource): + kind: ClassVar[str] = "azure_authorization_role_assignment" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="authorization", version="2022-04-01", @@ -130,9 +130,16 @@ class AzureRoleAssignment(MicrosoftResource): "Resource": "azure_resource", } reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_role_definition", *(p.kind for p in MicrosoftGraphPrincipalTypes)]}, + "successors": { + "default": ["azure_authorization_role_definition", *(p.kind for p in MicrosoftGraphPrincipalTypes)] + }, "predecessors": { - "default": ["azure_role_definition", "azure_subscription", "azure_resource_group", "azure_resource"] + "default": [ + "azure_authorization_role_definition", + "azure_subscription", + "azure_resource_group", + "azure_resource", + ] }, } mapping: ClassVar[Dict[str, Bender]] = { @@ -171,7 +178,7 @@ class AzureRoleAssignment(MicrosoftResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: # role definition if rid := self.role_definition_id: - builder.add_edge(self, clazz=AzureRoleDefinition, id=rid) + builder.add_edge(self, clazz=AzureAuthorizationRoleDefinition, id=rid) # scope if scope := self.scope: @@ -206,8 +213,8 @@ class AzurePermission: @define(eq=False, slots=False) -class AzureRoleDefinition(MicrosoftResource, BaseRole): - kind: ClassVar[str] = "azure_role_definition" +class AzureAuthorizationRoleDefinition(MicrosoftResource, BaseRole): + kind: ClassVar[str] = "azure_authorization_role_definition" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="authorization", version="2022-04-01", @@ -242,8 +249,8 @@ class AzureRoleDefinition(MicrosoftResource, BaseRole): @define(eq=False, slots=False) -class AzureManagementLock(MicrosoftResource): - kind: ClassVar[str] = "azure_management_lock" +class AzureAuthorizationManagementLock(MicrosoftResource): + kind: ClassVar[str] = "azure_authorization_management_lock" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="resources", version="2020-05-01", @@ -275,8 +282,8 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: resources: List[Type[MicrosoftResource]] = [ - AzureDenyAssignment, - AzureManagementLock, - AzureRoleAssignment, - AzureRoleDefinition, + AzureAuthorizationDenyAssignment, + AzureAuthorizationManagementLock, + AzureAuthorizationRoleAssignment, + AzureAuthorizationRoleDefinition, ] diff --git a/plugins/azure/fix_plugin_azure/resource/base.py b/plugins/azure/fix_plugin_azure/resource/base.py index 10bb029a49..93554ff99c 100644 --- a/plugins/azure/fix_plugin_azure/resource/base.py +++ b/plugins/azure/fix_plugin_azure/resource/base.py @@ -376,7 +376,7 @@ def collect_resources_in_group() -> None: self._resource_ids_in_group = [r["id"] for r in graph_builder.client.list(resources_api_spec)] def collect_network_gateways() -> None: - from fix_plugin_azure.resource.network import AzureVirtualNetworkGateway + from fix_plugin_azure.resource.network import AzureNetworkVirtualNetworkGateway api_spec = AzureResourceSpec( service="network", @@ -388,10 +388,10 @@ def collect_network_gateways() -> None: expect_array=True, ) items = graph_builder.client.list(api_spec) - AzureVirtualNetworkGateway.collect(items, graph_builder) + AzureNetworkVirtualNetworkGateway.collect(items, graph_builder) def collect_local_network_gateway() -> None: - from fix_plugin_azure.resource.network import AzureLocalNetworkGateway + from fix_plugin_azure.resource.network import AzureNetworkLocalNetworkGateway api_spec = AzureResourceSpec( service="network", @@ -403,10 +403,10 @@ def collect_local_network_gateway() -> None: expect_array=True, ) items = graph_builder.client.list(api_spec) - AzureLocalNetworkGateway.collect(items, graph_builder) + AzureNetworkLocalNetworkGateway.collect(items, graph_builder) def collect_network_gateway_connections() -> None: - from fix_plugin_azure.resource.network import AzureVirtualNetworkGatewayConnection + from fix_plugin_azure.resource.network import AzureNetworkVirtualNetworkGatewayConnection api_spec = AzureResourceSpec( service="network", @@ -418,7 +418,7 @@ def collect_network_gateway_connections() -> None: expect_array=True, ) items = graph_builder.client.list(api_spec) - AzureVirtualNetworkGatewayConnection.collect(items, graph_builder) + AzureNetworkVirtualNetworkGatewayConnection.collect(items, graph_builder) graph_builder.submit_work(service_name, collect_resources_in_group) graph_builder.submit_work(service_name, collect_network_gateways) @@ -453,7 +453,7 @@ class AzureBaseUsage: current_value: Optional[int] = field(default=None, metadata={"description": "The current value of the usage."}) limit: Optional[int] = field(default=None, metadata={"description": "The limit of usage."}) unit: Optional[str] = field(default=None, metadata={"description": "An enum describing the unit of measurement."}) - _expected_error_codes: ClassVar[List[str]] = ["SubscriptionHasNoUsages"] + _expected_error_codes: ClassVar[Dict[str, Optional[str]]] = {"SubscriptionHasNoUsages": None} @define(eq=False, slots=False) diff --git a/plugins/azure/fix_plugin_azure/resource/compute.py b/plugins/azure/fix_plugin_azure/resource/compute.py index 02d477f45a..b7928e186f 100644 --- a/plugins/azure/fix_plugin_azure/resource/compute.py +++ b/plugins/azure/fix_plugin_azure/resource/compute.py @@ -20,9 +20,9 @@ from fix_plugin_azure.resource.metrics import AzureMetricData, AzureMetricQuery, update_resource_metrics from fix_plugin_azure.resource.network import ( AzureNetworkSecurityGroup, - AzureSubnet, + AzureNetworkSubnet, AzureNetworkInterface, - AzureLoadBalancer, + AzureNetworkLoadBalancer, ) from fix_plugin_azure.utils import MetricNormalization, rgetvalue from fixlib.baseresources import ( @@ -65,8 +65,8 @@ class AzureInstanceViewStatus: @define(eq=False, slots=False) -class AzureAvailabilitySet(MicrosoftResource): - kind: ClassVar[str] = "azure_availability_set" +class AzureComputeAvailabilitySet(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_availability_set" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-03-01", @@ -77,7 +77,7 @@ class AzureAvailabilitySet(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_proximity_placement_group", "azure_virtual_machine_base"]}, + "successors": {"default": ["azure_compute_proximity_placement_group", "azure_compute_virtual_machine_base"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -100,16 +100,16 @@ class AzureAvailabilitySet(MicrosoftResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if placement_group_id := self.proximity_placement_group: builder.add_edge( - self, edge_type=EdgeType.default, clazz=AzureProximityPlacementGroup, id=placement_group_id + self, edge_type=EdgeType.default, clazz=AzureComputeProximityPlacementGroup, id=placement_group_id ) if virtual_machines := self.virtual_machines_availability: for vm_id in virtual_machines: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualMachineBase, id=vm_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureComputeVirtualMachineBase, id=vm_id) @define(eq=False, slots=False) -class AzureCapacityReservationGroupInstanceView: - kind: ClassVar[str] = "azure_capacity_reservation_group_instance_view" +class AzureComputeCapacityReservationGroupInstanceView: + kind: ClassVar[str] = "azure_compute_capacity_reservation_group_instance_view" mapping: ClassVar[Dict[str, Bender]] = { "capacity_reservations": S("capacityReservations", default=[]) >> ForallBend(S("name")) } @@ -117,8 +117,8 @@ class AzureCapacityReservationGroupInstanceView: @define(eq=False, slots=False) -class AzureCapacityReservationGroup(MicrosoftResource): - kind: ClassVar[str] = "azure_capacity_reservation_group" +class AzureComputeCapacityReservationGroup(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_capacity_reservation_group" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-03-01", @@ -129,7 +129,7 @@ class AzureCapacityReservationGroup(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_virtual_machine_base"]}, + "successors": {"default": ["azure_compute_virtual_machine_base"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -137,19 +137,19 @@ class AzureCapacityReservationGroup(MicrosoftResource): "name": S("name"), "capacity_reservations": S("properties") >> S("capacityReservations", default=[]) >> ForallBend(S("id")), "reservation_group_instance_view": S("properties", "instanceView") - >> Bend(AzureCapacityReservationGroupInstanceView.mapping), + >> Bend(AzureComputeCapacityReservationGroupInstanceView.mapping), "virtual_machines_associated": S("properties") >> S("virtualMachinesAssociated", default=[]) >> ForallBend(S("id")), } capacity_reservations: Optional[List[str]] = field(default=None, metadata={'description': 'A list of all capacity reservation resource ids that belong to capacity reservation group.'}) # fmt: skip - reservation_group_instance_view: Optional[AzureCapacityReservationGroupInstanceView] = field(default=None, metadata={'description': ''}) # fmt: skip + reservation_group_instance_view: Optional[AzureComputeCapacityReservationGroupInstanceView] = field(default=None, metadata={'description': ''}) # fmt: skip virtual_machines_associated: Optional[List[str]] = field(default=None, metadata={'description': 'A list of references to all virtual machines associated to the capacity reservation group.'}) # fmt: skip def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if virtual_machines := self.virtual_machines_associated: for vm_id in virtual_machines: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualMachineBase, id=vm_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureComputeVirtualMachineBase, id=vm_id) @define(eq=False, slots=False) @@ -290,8 +290,8 @@ class AzureCloudServiceExtensionProfile: @define(eq=False, slots=False) -class AzureCloudService(MicrosoftResource): - kind: ClassVar[str] = "azure_cloud_service" +class AzureComputeCloudService(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_cloud_service" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2022-09-04", @@ -342,8 +342,8 @@ class AzureDedicatedHostGroupInstanceView: @define(eq=False, slots=False) -class AzureDedicatedHostGroup(MicrosoftResource): - kind: ClassVar[str] = "azure_dedicated_host_group" +class AzureComputeDedicatedHostGroup(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_dedicated_host_group" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-03-01", @@ -705,8 +705,8 @@ class AzurePricingOffers: @define(eq=False, slots=False) -class AzureDiskTypePricing(MicrosoftResource): - kind: ClassVar[str] = "azure_disk_type_pricing" +class AzureComputeDiskTypePricing(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_disk_type_pricing" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="", @@ -727,9 +727,9 @@ class AzureDiskTypePricing(MicrosoftResource): @define(eq=False, slots=False) -class AzureDiskType(MicrosoftResource, BaseVolumeType): - kind: ClassVar[str] = "azure_disk_type" - # Collect via AzureDisk() +class AzureComputeDiskType(MicrosoftResource, BaseVolumeType): + kind: ClassVar[str] = "azure_compute_disk_type" + # Collect via AzureComputeDisk() mapping: ClassVar[Dict[str, Bender]] = { "id": S("skuName"), "name": S("skuName"), @@ -772,7 +772,7 @@ def after_collect(self, builder: GraphBuilder, source: Json) -> None: if location and volume_type in ("UltraSSD_LRS", "PremiumV2_LRS"): # Fetch price for Ultra SSD and Premium SSD V2 - pricing_node = builder.nodes(AzureDiskTypePricing)[0] + pricing_node = builder.nodes(AzureComputeDiskTypePricing)[0] offers = pricing_node.offers grad_offers = pricing_node.graduated_offers @@ -845,7 +845,7 @@ def build_custom_disk_size( location: str, disk_type: str, disk_size: int, disk_iops: int, disk_throughput: int ) -> Json: if disk_type == "UltraSSD_LRS": - nearest_ultra_disk_size = AzureDisk._get_nearest_size(disk_size, ultra_disk_sku_info) + nearest_ultra_disk_size = AzureComputeDisk._get_nearest_size(disk_size, ultra_disk_sku_info) ultra_disk_config = ultra_disk_sku_info.get(nearest_ultra_disk_size, {}) ulta_ssd_object = { "size": disk_size, @@ -873,7 +873,7 @@ def create_unique_disk_sizes(collected_disks: List[MicrosoftResourceType], build disk_sizes: List[Json] = [] seen_hashes = set() # Set to keep track of unique hashes for disk in collected_disks: - if not isinstance(disk, AzureDisk): + if not isinstance(disk, AzureComputeDisk): continue if ( (volume_type := disk.volume_type) @@ -885,12 +885,14 @@ def create_unique_disk_sizes(collected_disks: List[MicrosoftResourceType], build if volume_type not in ["UltraSSD_LRS", "PremiumV2_LRS"]: continue - generic_size = AzureDiskType.build_custom_disk_size(location, volume_type, size, iops, throughput) + generic_size = AzureComputeDiskType.build_custom_disk_size( + location, volume_type, size, iops, throughput + ) hash_value = hash(tuple(generic_size.items())) if hash_value not in seen_hashes: disk_sizes.append(generic_size) seen_hashes.add(hash_value) - AzureDiskType.collect(disk_sizes, builder) + AzureComputeDiskType.collect(disk_sizes, builder) VolumeStatusMapping = { @@ -906,8 +908,8 @@ def create_unique_disk_sizes(collected_disks: List[MicrosoftResourceType], build @define(eq=False, slots=False) -class AzureDisk(MicrosoftResource, BaseVolume): - kind: ClassVar[str] = "azure_disk" +class AzureComputeDisk(MicrosoftResource, BaseVolume): + kind: ClassVar[str] = "azure_compute_disk" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-01-02", @@ -918,8 +920,7 @@ class AzureDisk(MicrosoftResource, BaseVolume): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_disk_access"]}, - "successors": {"default": ["azure_disk_encryption_set", "azure_disk_type"]}, + "successors": {"default": ["azure_compute_disk_encryption_set", "azure_compute_disk_type"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -1018,7 +1019,7 @@ def collect_resources( items = builder.client.list(spec, **kwargs) collected = cls.collect(items, builder) # Create additional custom disk sizes for disks with Ultra SSD or Premium SSD v2 types - AzureDiskType.create_unique_disk_sizes(collected, builder) + AzureComputeDiskType.create_unique_disk_sizes(collected, builder) if builder.config.collect_usage_metrics: try: cls.collect_usage_metrics(builder, collected) @@ -1031,7 +1032,7 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: if location := self.location: def collect_disk_types() -> None: - log.debug(f"[Azure:{graph_builder.account.id}] Collecting AzureDiskType") + log.debug(f"[Azure:{graph_builder.account.id}] Collecting AzureComputeDiskType") product_names = { "Standard SSD Managed Disks", "Premium SSD Managed Disks", @@ -1051,7 +1052,7 @@ def collect_disk_types() -> None: items = graph_builder.client.list(api_spec) sku_items.extend(items) - AzureDiskType.collect(sku_items, graph_builder) + AzureComputeDiskType.collect(sku_items, graph_builder) graph_builder.submit_work(service_name, collect_disk_types) @@ -1136,7 +1137,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: builder.add_edge( self, edge_type=EdgeType.default, - clazz=AzureDiskType, + clazz=AzureComputeDiskType, location=location, volume_type=volume_type, tier=tier, @@ -1147,22 +1148,20 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: builder.add_edge( self, edge_type=EdgeType.default, - clazz=AzureDiskType, + clazz=AzureComputeDiskType, location=location, volume_type=volume_type, volume_size=size, volume_throughput=throughput, volume_iops=iops, ) - if disk_id := self.id: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureDiskAccess, id=disk_id) if (disk_encryption := self.disk_encryption) and (disk_en_set_id := disk_encryption.disk_encryption_set_id): - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureDiskEncryptionSet, id=disk_en_set_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureComputeDiskEncryptionSet, id=disk_en_set_id) @define(eq=False, slots=False) -class AzureDiskAccess(MicrosoftResource): - kind: ClassVar[str] = "azure_disk_access" +class AzureComputeDiskAccess(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_disk_access" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-01-02", @@ -1246,8 +1245,8 @@ class AzureApiError: @define(eq=False, slots=False) -class AzureDiskEncryptionSet(MicrosoftResource): - kind: ClassVar[str] = "azure_disk_encryption_set" +class AzureComputeDiskEncryptionSet(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_disk_encryption_set" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-01-02", @@ -1344,8 +1343,8 @@ class AzureSharingStatus: @define(eq=False, slots=False) -class AzureGallery(MicrosoftResource): - kind: ClassVar[str] = "azure_gallery" +class AzureComputeGallery(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_gallery" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2022-03-03", @@ -1416,8 +1415,8 @@ class AzureImageStorageProfile: @define(eq=False, slots=False) -class AzureImage(MicrosoftResource): - kind: ClassVar[str] = "azure_image" +class AzureComputeImage(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_image" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-03-01", @@ -1460,8 +1459,8 @@ class AzureVmSizes: @define(eq=False, slots=False) -class AzureProximityPlacementGroup(MicrosoftResource): - kind: ClassVar[str] = "azure_proximity_placement_group" +class AzureComputeProximityPlacementGroup(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_proximity_placement_group" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-03-01", @@ -1472,7 +1471,7 @@ class AzureProximityPlacementGroup(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_virtual_machine_scale_set"]}, + "successors": {"default": ["azure_compute_virtual_machine_scale_set"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -1499,7 +1498,9 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vmsss := self.virtual_machine_scale_sets: for vmss in vmsss: if vmss_id := vmss.id: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualMachineScaleSet, id=vmss_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureComputeVirtualMachineScaleSet, id=vmss_id + ) @define(eq=False, slots=False) @@ -1975,8 +1976,8 @@ class AzureRestorePoint(AzureProxyResource): @define(eq=False, slots=False) -class AzureRestorePointCollection(MicrosoftResource): - kind: ClassVar[str] = "azure_restore_point_collection" +class AzureComputeRestorePointCollection(MicrosoftResource): + kind: ClassVar[str] = "azure_compute_restore_point_collection" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-03-01", @@ -1987,7 +1988,7 @@ class AzureRestorePointCollection(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_virtual_machine_base"]}, + "successors": {"default": ["azure_compute_virtual_machine_base"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -2007,7 +2008,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if (restore_point_collection_source := self.restore_point_collection_resource) and ( vm_id := restore_point_collection_source.id ): - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualMachineBase, id=vm_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureComputeVirtualMachineBase, id=vm_id) @define(eq=False, slots=False) @@ -2027,8 +2028,8 @@ class AzureCopyCompletionError: @define(eq=False, slots=False) -class AzureVirtualMachineSnapshot(MicrosoftResource, BaseSnapshot): - kind: ClassVar[str] = "azure_virtual_machine_snapshot" +class AzureComputeVirtualMachineSnapshot(MicrosoftResource, BaseSnapshot): + kind: ClassVar[str] = "azure_compute_virtual_machine_snapshot" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-01-02", @@ -2039,7 +2040,7 @@ class AzureVirtualMachineSnapshot(MicrosoftResource, BaseSnapshot): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_disk"]}, + "predecessors": {"default": ["azure_compute_disk", "azure_compute_disk_access"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -2107,12 +2108,16 @@ class AzureVirtualMachineSnapshot(MicrosoftResource, BaseSnapshot): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if (disk_data := self.creation_data) and (disk_id := disk_data.source_resource_id): - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureDisk, id=disk_id) + builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureComputeDisk, id=disk_id) + if disk_access_id := self.disk_access_id: + builder.add_edge( + self, edge_type=EdgeType.default, reverse=True, clazz=AzureComputeDiskAccess, id=disk_access_id + ) @define(eq=False, slots=False) -class AzureSshPublicKeyResource(MicrosoftResource, BaseKeyPair): - kind: ClassVar[str] = "azure_ssh_public_key_resource" +class AzureComputeSshPublicKey(MicrosoftResource, BaseKeyPair): + kind: ClassVar[str] = "azure_compute_ssh_public_key" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-03-01", @@ -2747,19 +2752,24 @@ class AzureVirtualMachineIdentity: @define(eq=False, slots=False) -class AzureVirtualMachineBase(MicrosoftResource, BaseInstance): - kind: ClassVar[str] = "azure_virtual_machine_base" +class AzureComputeVirtualMachineBase(MicrosoftResource, BaseInstance): + kind: ClassVar[str] = "azure_compute_virtual_machine_base" reference_kinds: ClassVar[ModelReference] = { "predecessors": { "default": [ - "azure_proximity_placement_group", + "azure_compute_proximity_placement_group", "azure_network_security_group", - "azure_subnet", - "azure_load_balancer", + "azure_network_subnet", + "azure_network_load_balancer", ] }, "successors": { - "default": ["azure_image", "azure_disk", "azure_network_interface", "azure_virtual_machine_size"] + "default": [ + "azure_compute_image", + "azure_compute_disk", + "azure_network_interface", + "azure_compute_virtual_machine_size", + ] }, } mapping: ClassVar[Dict[str, Bender]] = { @@ -2883,7 +2893,7 @@ def collect_vm_sizes() -> None: # Set location for further connect_in_graph method for item in items: item["location"] = location - AzureVirtualMachineSize.collect(items, graph_builder) + AzureComputeVirtualMachineSize.collect(items, graph_builder) graph_builder.submit_work(service_name, collect_vm_sizes) @@ -2973,7 +2983,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureProximityPlacementGroup, + clazz=AzureComputeProximityPlacementGroup, id=placement_group_id, ) @@ -2982,7 +2992,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: and (image_ref := sp.image_reference) and (image_reference_id := image_ref.id) ): - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureImage, id=image_reference_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureComputeImage, id=image_reference_id) if ( (sp := self.virtual_machine_storage_profile) @@ -2990,7 +3000,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: and (managed := disk.managed_disk) and (managed_disk_id := managed.id) ): - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureDisk, id=managed_disk_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureComputeDisk, id=managed_disk_id) if (vm_network_profile := self.virtual_machine_network_profile) and ( ni_cofigurations := vm_network_profile.network_interface_configurations @@ -3004,14 +3014,18 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for ip_configuration in ip_configurations: if subnet_id := ip_configuration.subnet: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id ) if lbbap_ids := ip_configuration.load_balancer_backend_address_pools: for lbbap_id in lbbap_ids: # take only id of load balancer lbbap_id = "/".join(lbbap_id.split("/")[:-2]) builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureLoadBalancer, id=lbbap_id + self, + edge_type=EdgeType.default, + reverse=True, + clazz=AzureNetworkLoadBalancer, + id=lbbap_id, ) if (vm_network_profile := self.virtual_machine_network_profile) and ( @@ -3022,13 +3036,17 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkInterface, id=ni_id) if (vms_type := self.instance_type) and (vm_location := self.location): builder.add_edge( - self, edge_type=EdgeType.default, clazz=AzureVirtualMachineSize, name=vms_type, location=vm_location + self, + edge_type=EdgeType.default, + clazz=AzureComputeVirtualMachineSize, + name=vms_type, + location=vm_location, ) @define(eq=False, slots=False) -class AzureVirtualMachine(AzureVirtualMachineBase): - kind: ClassVar[str] = "azure_virtual_machine" +class AzureComputeVirtualMachine(AzureComputeVirtualMachineBase): + kind: ClassVar[str] = "azure_compute_virtual_machine" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-03-01", @@ -3477,8 +3495,8 @@ class AzureVirtualMachineScaleSetIdentity: @define(eq=False, slots=False) -class AzureVirtualMachineScaleSet(MicrosoftResource, BaseAutoScalingGroup): - kind: ClassVar[str] = "azure_virtual_machine_scale_set" +class AzureComputeVirtualMachineScaleSet(MicrosoftResource, BaseAutoScalingGroup): + kind: ClassVar[str] = "azure_compute_virtual_machine_scale_set" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="compute", version="2023-03-01", @@ -3489,8 +3507,8 @@ class AzureVirtualMachineScaleSet(MicrosoftResource, BaseAutoScalingGroup): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_load_balancer", "azure_subnet"]}, - "successors": {"default": ["azure_virtual_machine_scale_set_instance"]}, + "predecessors": {"default": ["azure_network_load_balancer", "azure_network_subnet"]}, + "successors": {"default": ["azure_compute_virtual_machine_scale_set_instance"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -3562,11 +3580,14 @@ def collect_vmss_instances() -> None: items = graph_builder.client.list(api_spec) vmss_instance_ids = [str(item.get("id")) for item in items if item.get("id") is not None] - AzureVirtualMachineScaleSetInstance.collect(items, graph_builder) + AzureComputeVirtualMachineScaleSetInstance.collect(items, graph_builder) for vmss_instance_id in vmss_instance_ids: graph_builder.add_edge( - self, edge_type=EdgeType.default, clazz=AzureVirtualMachineScaleSetInstance, id=vmss_instance_id + self, + edge_type=EdgeType.default, + clazz=AzureComputeVirtualMachineScaleSetInstance, + id=vmss_instance_id, ) graph_builder.submit_work(service_name, collect_vmss_instances) @@ -3587,7 +3608,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureLoadBalancer, + clazz=AzureNetworkLoadBalancer, id=bap_id, ) if subnet_id := ip_config.subnet: @@ -3595,14 +3616,14 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureSubnet, + clazz=AzureNetworkSubnet, id=subnet_id, ) @define(eq=False, slots=False) -class AzureVirtualMachineSize(MicrosoftResource, BaseInstanceType): - kind: ClassVar[str] = "azure_virtual_machine_size" +class AzureComputeVirtualMachineSize(MicrosoftResource, BaseInstanceType): + kind: ClassVar[str] = "azure_compute_virtual_machine_size" mapping: ClassVar[Dict[str, Bender]] = { "id": S("name"), "tags": S("tags", default={}), @@ -3643,29 +3664,30 @@ def after_collect(self, builder: GraphBuilder, source: Json) -> None: @define(eq=False, slots=False) -class AzureVirtualMachineScaleSetInstance(AzureVirtualMachineBase): - # note: instances are collected as part of collecting AzureVirtualMachineScaleSets +class AzureComputeVirtualMachineScaleSetInstance(AzureComputeVirtualMachineBase): + # note: instances are collected as part of collecting AzureComputeVirtualMachineScaleSet - kind: ClassVar[str] = "azure_virtual_machine_scale_set_instance" + kind: ClassVar[str] = "azure_compute_virtual_machine_scale_set_instance" resources: List[Type[MicrosoftResource]] = [ - AzureAvailabilitySet, - AzureCapacityReservationGroup, - AzureCloudService, - AzureDedicatedHostGroup, - AzureDiskTypePricing, - AzureDisk, - AzureDiskType, - AzureDiskAccess, - AzureDiskEncryptionSet, - AzureGallery, - AzureImage, - AzureProximityPlacementGroup, - AzureRestorePointCollection, - AzureVirtualMachineSnapshot, - AzureSshPublicKeyResource, - AzureVirtualMachine, - AzureVirtualMachineScaleSet, - AzureVirtualMachineSize, + AzureComputeAvailabilitySet, + AzureComputeCapacityReservationGroup, + AzureComputeCloudService, + AzureComputeDedicatedHostGroup, + AzureComputeDiskTypePricing, + AzureComputeDisk, + AzureComputeDiskType, + AzureComputeDiskAccess, + AzureComputeDiskEncryptionSet, + AzureComputeGallery, + AzureComputeImage, + AzureComputeProximityPlacementGroup, + AzureComputeRestorePointCollection, + AzureComputeVirtualMachineSnapshot, + AzureComputeSshPublicKey, + AzureComputeVirtualMachine, + AzureComputeVirtualMachineScaleSet, + AzureComputeVirtualMachineScaleSetInstance, + AzureComputeVirtualMachineSize, ] diff --git a/plugins/azure/fix_plugin_azure/resource/containerservice.py b/plugins/azure/fix_plugin_azure/resource/containerservice.py index bae867c451..7bbd235d39 100644 --- a/plugins/azure/fix_plugin_azure/resource/containerservice.py +++ b/plugins/azure/fix_plugin_azure/resource/containerservice.py @@ -63,8 +63,8 @@ class AzureFleetHubProfile: @define(eq=False, slots=False) -class AzureFleet(MicrosoftResource): - kind: ClassVar[str] = "azure_fleet" +class AzureContainerServiceFleet(MicrosoftResource): + kind: ClassVar[str] = "azure_container_service_fleet" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="containerservice", version="2023-08-15-preview", @@ -75,7 +75,7 @@ class AzureFleet(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_managed_cluster"]}, + "successors": {"default": ["azure_container_service_managed_cluster"]}, } mapping: ClassVar[Dict[str, Bender]] = AzureTrackedResource.mapping | { "id": S("id"), @@ -121,7 +121,9 @@ def collect_fleets() -> None: def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if cluster_ids := self._cluster_resource_ids: for cluster_id in cluster_ids: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureManagedCluster, id=cluster_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureContainerServiceManagedCluster, id=cluster_id + ) @define(eq=False, slots=False) @@ -570,8 +572,8 @@ class AzureManagedClusterSecurityProfileDefender: @define(eq=False, slots=False) -class AzureAzureKeyVaultKms: - kind: ClassVar[str] = "azure_azure_key_vault_kms" +class AzureKeyVaultKms: + kind: ClassVar[str] = "azure_key_vault_kms" mapping: ClassVar[Dict[str, Bender]] = { "enabled": S("enabled"), "key_id": S("keyId"), @@ -596,12 +598,12 @@ class AzureManagedClusterSecurityProfileImageCleaner: class AzureManagedClusterSecurityProfile: kind: ClassVar[str] = "azure_managed_cluster_security_profile" mapping: ClassVar[Dict[str, Bender]] = { - "azure_key_vault_kms": S("azureKeyVaultKms") >> Bend(AzureAzureKeyVaultKms.mapping), + "azure_key_vault_kms": S("azureKeyVaultKms") >> Bend(AzureKeyVaultKms.mapping), "defender": S("defender") >> Bend(AzureManagedClusterSecurityProfileDefender.mapping), "image_cleaner": S("imageCleaner") >> Bend(AzureManagedClusterSecurityProfileImageCleaner.mapping), "workload_identity": S("workloadIdentity", "enabled"), } - azure_key_vault_kms: Optional[AzureAzureKeyVaultKms] = field(default=None, metadata={'description': 'Azure Key Vault key management service settings for the security profile.'}) # fmt: skip + azure_key_vault_kms: Optional[AzureKeyVaultKms] = field(default=None, metadata={'description': 'Azure Key Vault key management service settings for the security profile.'}) # fmt: skip defender: Optional[AzureManagedClusterSecurityProfileDefender] = field(default=None, metadata={'description': 'Microsoft Defender settings for the security profile.'}) # fmt: skip image_cleaner: Optional[AzureManagedClusterSecurityProfileImageCleaner] = field(default=None, metadata={'description': 'Image Cleaner removes unused images from nodes, freeing up disk space and helping to reduce attack surface area. Here are settings for the security profile.'}) # fmt: skip workload_identity: Optional[bool] = field(default=None, metadata={'description': 'Workload identity settings for the security profile.'}) # fmt: skip @@ -617,7 +619,7 @@ class AzureManagedClusterStorageProfile: "snapshot_controller": S("snapshotController", "enabled"), } blob_csi_driver: Optional[bool] = field(default=None, metadata={'description': 'AzureBlob CSI Driver settings for the storage profile.'}) # fmt: skip - disk_csi_driver: Optional[bool] = field(default=None, metadata={'description': 'AzureDisk CSI Driver settings for the storage profile.'}) # fmt: skip + disk_csi_driver: Optional[bool] = field(default=None, metadata={'description': 'AzureComputeDisk CSI Driver settings for the storage profile.'}) # fmt: skip file_csi_driver: Optional[bool] = field(default=None, metadata={'description': 'AzureFile CSI Driver settings for the storage profile.'}) # fmt: skip snapshot_controller: Optional[bool] = field(default=None, metadata={'description': 'Snapshot Controller settings for the storage profile.'}) # fmt: skip @@ -741,8 +743,8 @@ class AzureServiceMeshProfile: @define(eq=False, slots=False) -class AzureManagedCluster(MicrosoftResource, BaseManagedKubernetesClusterProvider): - kind: ClassVar[str] = "azure_managed_cluster" +class AzureContainerServiceManagedCluster(MicrosoftResource, BaseManagedKubernetesClusterProvider): + kind: ClassVar[str] = "azure_container_service_managed_cluster" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="containerservice", version="2023-08-01", @@ -753,7 +755,7 @@ class AzureManagedCluster(MicrosoftResource, BaseManagedKubernetesClusterProvide expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_disk_encryption_set", "azure_virtual_machine_scale_set"]}, + "successors": {"default": ["azure_compute_disk_encryption_set", "azure_compute_virtual_machine_scale_set"]}, } mapping: ClassVar[Dict[str, Bender]] = AzureTrackedResource.mapping | { "id": S("id"), @@ -857,10 +859,10 @@ class AzureManagedCluster(MicrosoftResource, BaseManagedKubernetesClusterProvide workload_auto_scaler_profile: Optional[AzureManagedClusterWorkloadAutoScalerProfile] = field(default=None, metadata={'description': 'Workload Auto-scaler profile for the managed cluster.'}) # fmt: skip def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: - from fix_plugin_azure.resource.compute import AzureDiskEncryptionSet, AzureVirtualMachineScaleSet + from fix_plugin_azure.resource.compute import AzureComputeDiskEncryptionSet, AzureComputeVirtualMachineScaleSet if disk_id := self.disk_encryption_set_id: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureDiskEncryptionSet, id=disk_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureComputeDiskEncryptionSet, id=disk_id) if agent_pool_profiles := self.agent_pool_profiles: vmss_agent_pool_names_and_ids = self._get_poolnames_and_vmss_ids(builder) @@ -869,22 +871,22 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: pool_name, vmss_id = info if agent_pool_profile_name == pool_name: builder.add_edge( - self, edge_type=EdgeType.default, clazz=AzureVirtualMachineScaleSet, id=vmss_id + self, edge_type=EdgeType.default, clazz=AzureComputeVirtualMachineScaleSet, id=vmss_id ) def _get_poolnames_and_vmss_ids(self, builder: GraphBuilder) -> List[Tuple[str, str]]: - from fix_plugin_azure.resource.compute import AzureVirtualMachineScaleSet + from fix_plugin_azure.resource.compute import AzureComputeVirtualMachineScaleSet return [ (poolname, vmss_id) - for vmss in builder.nodes(clazz=AzureVirtualMachineScaleSet) + for vmss in builder.nodes(clazz=AzureComputeVirtualMachineScaleSet) if (poolname := vmss.tags.get("aks-managed-poolName")) and (vmss_id := vmss.id) ] @define(eq=False, slots=False) -class AzureManagedClusterSnapshot(MicrosoftResource, BaseSnapshot): - kind: ClassVar[str] = "azure_managed_cluster_snapshot" +class AzureContainerServiceManagedClusterSnapshot(MicrosoftResource, BaseSnapshot): + kind: ClassVar[str] = "azure_container_service_managed_cluster_snapshot" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="containerservice", version="2023-08-01", @@ -895,7 +897,7 @@ class AzureManagedClusterSnapshot(MicrosoftResource, BaseSnapshot): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_managed_cluster"]}, + "predecessors": {"default": ["azure_container_service_managed_cluster"]}, } mapping: ClassVar[Dict[str, Bender]] = AzureTrackedResource.mapping | { "id": S("id"), @@ -925,17 +927,23 @@ class AzureManagedClusterSnapshot(MicrosoftResource, BaseSnapshot): location: Optional[str] = field(default=None, metadata={"description": "Resource location."}) def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: - from fix_plugin_azure.resource.compute import AzureVirtualMachineSize + from fix_plugin_azure.resource.compute import AzureComputeVirtualMachineSize if (snapshot_vm_size := self.vm_size) and (location := self.location): - vm_sizes = builder.nodes(clazz=AzureVirtualMachineSize, name=snapshot_vm_size, location=location) + vm_sizes = builder.nodes(clazz=AzureComputeVirtualMachineSize, name=snapshot_vm_size, location=location) for vm_size in vm_sizes: if size := vm_size.os_disk_size_in_mb: self.volume_size = size // 1024 if agent_pool_id := self.creation_data_source_id: cluster_id = "/".join((agent_pool_id.split("/")[:-2])) - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureManagedCluster, id=cluster_id) + builder.add_edge( + self, edge_type=EdgeType.default, reverse=True, clazz=AzureContainerServiceManagedCluster, id=cluster_id + ) -resources: List[Type[MicrosoftResource]] = [AzureManagedCluster, AzureFleet, AzureManagedClusterSnapshot] +resources: List[Type[MicrosoftResource]] = [ + AzureContainerServiceManagedCluster, + AzureContainerServiceFleet, + AzureContainerServiceManagedClusterSnapshot, +] diff --git a/plugins/azure/fix_plugin_azure/resource/cosmosdb.py b/plugins/azure/fix_plugin_azure/resource/cosmosdb.py index e6c1ac94a6..d294399c49 100644 --- a/plugins/azure/fix_plugin_azure/resource/cosmosdb.py +++ b/plugins/azure/fix_plugin_azure/resource/cosmosdb.py @@ -18,9 +18,10 @@ MicrosoftResource, AzurePrivateEndpointConnection, ) +from fix_plugin_azure.resource.keyvault import AzureKeyVaultKey from fix_plugin_azure.resource.microsoft_graph import MicrosoftGraphServicePrincipal, MicrosoftGraphUser from fix_plugin_azure.resource.mysql import AzureServerDataEncryption -from fix_plugin_azure.resource.network import AzureSubnet +from fix_plugin_azure.resource.network import AzureNetworkSubnet from fix_plugin_azure.utils import from_str_to_typed from fixlib.baseresources import BaseDatabase, DatabaseInstanceStatus, EdgeType, ModelReference from fixlib.graph import BySearchCriteria @@ -404,7 +405,7 @@ class AzureCosmosDBCassandraCluster(MicrosoftResource): }, "predecessors": { "default": [ - "azure_subnet", + "azure_network_subnet", ] }, } @@ -467,7 +468,6 @@ def _collect_items( account_id: str, resource_type: str, class_instance: MicrosoftResource, - expected_errors: Optional[List[str]] = None, ) -> None: path = f"{account_id}/{resource_type}" api_spec = AzureResourceSpec( @@ -478,7 +478,6 @@ def _collect_items( query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=expected_errors or [], ) items = graph_builder.client.list(api_spec) if not items: @@ -490,11 +489,11 @@ def _collect_items( def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: if account_id := self.id: resources_to_collect = [ - ("status", AzureCosmosDBCassandraClusterPublicStatus, None), - ("dataCenters", AzureCosmosDBCassandraClusterDataCenter, None), + ("status", AzureCosmosDBCassandraClusterPublicStatus), + ("dataCenters", AzureCosmosDBCassandraClusterDataCenter), ] - for resource_type, resource_class, expected_errors in resources_to_collect: + for resource_type, resource_class in resources_to_collect: graph_builder.submit_work( service_name, self._collect_items, @@ -502,7 +501,6 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: account_id, resource_type, resource_class, - expected_errors, ) def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: @@ -518,7 +516,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureSubnet, + clazz=AzureNetworkSubnet, id=subnet_id, ) @@ -553,7 +551,7 @@ class AzureCosmosDBCassandraClusterDataCenter(MicrosoftResource): reference_kinds: ClassVar[ModelReference] = { "predecessors": { "default": [ - "azure_subnet", + "azure_network_subnet", ] }, } @@ -601,7 +599,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureSubnet, + clazz=AzureNetworkSubnet, id=subnet_id, ) @@ -764,6 +762,9 @@ class AzureDatabaseAccountKeysMetadata: secondary_readonly_master_key: Optional[datetime] = field(default=None, metadata={'description': 'The metadata related to an access key for a given database account.'}) # fmt: skip +mongo_cosmosdb_error_message = "Mongo User and Role Definitions are not enabled in your Azure Cosmos DB MongoDB account and can not be collected. In Cosmos DB MongoDB account under “Settings -> Features”, turn on the “Role-based access control (RBAC)” option." + + @define(eq=False, slots=False) class AzureCosmosDBAccount(MicrosoftResource, BaseDatabase): kind: ClassVar[str] = "azure_cosmos_db_account" @@ -780,7 +781,6 @@ class AzureCosmosDBAccount(MicrosoftResource, BaseDatabase): "successors": { "default": [ "azure_cosmos_db_cassandra_keyspace", - "azure_cosmos_db_account_read_only_keys", "azure_cosmos_db_gremlin_database", "azure_cosmos_db_mongo_db_database", "azure_cosmos_db_mongo_db_role_definition", @@ -796,7 +796,7 @@ class AzureCosmosDBAccount(MicrosoftResource, BaseDatabase): MicrosoftGraphUser.kind, ] }, - "predecessors": {"default": ["azure_cosmos_db_location", "azure_subnet"]}, + "predecessors": {"default": ["azure_cosmos_db_location", "azure_network_subnet", AzureKeyVaultKey.kind]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -914,37 +914,23 @@ def _collect_items( account_id: str, resource_type: str, class_instance: MicrosoftResource, - expected_errors: Optional[List[str]] = None, + expected_errors: Optional[Dict[str, Optional[str]]] = None, ) -> None: path = f"{account_id}/{resource_type}" - if issubclass(AzureCosmosDBAccountReadOnlyKeys, class_instance): # type: ignore - api_spec = AzureResourceSpec( - service="cosmos-db", - version="2024-05-15", - path=path, - path_parameters=[], - query_parameters=["api-version"], - access_path=None, - expect_array=False, - expected_error_codes=expected_errors or [], - ) - else: - api_spec = AzureResourceSpec( - service="cosmos-db", - version="2024-05-15", - path=path, - path_parameters=[], - query_parameters=["api-version"], - access_path="value", - expect_array=True, - expected_error_codes=expected_errors or [], - ) + api_spec = AzureResourceSpec( + service="cosmos-db", + version="2024-05-15", + path=path, + path_parameters=[], + query_parameters=["api-version"], + access_path="value", + expect_array=True, + expected_error_codes=expected_errors or {}, + ) items = graph_builder.client.list(api_spec) if not items: return - if issubclass(AzureCosmosDBAccountReadOnlyKeys, class_instance): # type: ignore - collected = class_instance.collect_keys(account_id, items, graph_builder) # type: ignore - elif issubclass(AzureCosmosDBAccountUsage, class_instance): # type: ignore + if issubclass(AzureCosmosDBAccountUsage, class_instance): # type: ignore collected = class_instance.collect_usages(account_id, items, graph_builder) # type: ignore else: collected = class_instance.collect(items, graph_builder) @@ -953,11 +939,10 @@ def _collect_items( def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: if account_id := self.id: - resources_to_collect = [ - ("readonlykeys", AzureCosmosDBAccountReadOnlyKeys, None), + resources_to_collect: List = [ # type: ignore ("notebookWorkspaces", AzureCosmosDBNotebookWorkspace, None), ("privateLinkResources", AzureCosmosDBPrivateLink, None), - ("usages", AzureCosmosDBAccountUsage, ["SubscriptionHasNoUsages"]), + ("usages", AzureCosmosDBAccountUsage, {"SubscriptionHasNoUsages": None}), ] # For fetching SQL resources required filtering by API type if database_api_type := self.database_api_type: @@ -971,31 +956,35 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: ] ) elif api_type == "Cassandra": - resources_to_collect.extend( - [ - ("cassandraKeyspaces", AzureCosmosDBCassandraKeyspace, None), - ] - ) + resources_to_collect.append(("cassandraKeyspaces", AzureCosmosDBCassandraKeyspace, None)) elif api_type == "MongoDB": resources_to_collect.extend( [ ("mongodbDatabases", AzureCosmosDBMongoDBDatabase, None), - ("mongodbRoleDefinitions", AzureCosmosDBMongoDBRoleDefinition, None), - ("mongodbUserDefinitions", AzureCosmosDBMongoDBUserDefinition, None), + ( + "mongodbRoleDefinitions", + AzureCosmosDBMongoDBRoleDefinition, + { + "BadRequest": mongo_cosmosdb_error_message.format( + provider_link=self._metadata.get("provider_link") + ) + }, + ), + ( + "mongodbUserDefinitions", + AzureCosmosDBMongoDBUserDefinition, + { + "BadRequest": mongo_cosmosdb_error_message.format( + provider_link=self._metadata.get("provider_link") + ) + }, + ), ] ) elif api_type == "Table": - resources_to_collect.extend( - [ - ("tables", AzureCosmosDBTable, None), - ] - ) + resources_to_collect.append(("tables", AzureCosmosDBTable, None)) elif api_type == "Gremlin": - resources_to_collect.extend( - [ - ("gremlinDatabases", AzureCosmosDBGremlinDatabase, None), - ] - ) + resources_to_collect.append(("gremlinDatabases", AzureCosmosDBGremlinDatabase, None)) for resource_type, resource_class, expected_errors in resources_to_collect: graph_builder.submit_work( service_name, @@ -1024,9 +1013,17 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureSubnet, + clazz=AzureNetworkSubnet, id=subnet_id, ) + if key_vault_key_uri := self.key_vault_key_uri: + builder.add_edge( + self, + edge_type=EdgeType.default, + reverse=True, + clazz=AzureKeyVaultKey, + key_uri=key_vault_key_uri, + ) # principal: collected via ms graph -> create a deferred edge if ai := self.account_identity: @@ -1046,33 +1043,6 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: ) -@define(eq=False, slots=False) -class AzureCosmosDBAccountReadOnlyKeys(MicrosoftResource): - kind: ClassVar[str] = "azure_cosmos_db_account_read_only_keys" - # Collect via AzureCosmosDBAccount() - mapping: ClassVar[Dict[str, Bender]] = { - "id": S("id"), - "primary_readonly_master_key": S("primaryReadonlyMasterKey"), - "secondary_readonly_master_key": S("secondaryReadonlyMasterKey"), - } - primary_readonly_master_key: Optional[str] = field(default=None, metadata={'description': 'Base 64 encoded value of the primary read-only key.'}) # fmt: skip - secondary_readonly_master_key: Optional[str] = field(default=None, metadata={'description': 'Base 64 encoded value of the secondary read-only key.'}) # fmt: skip - - @classmethod - def collect_keys( - cls, account_id: str, raw: List[Json], builder: GraphBuilder - ) -> List[AzureCosmosDBAccountReadOnlyKeys]: - result = [] - for js in raw: - # map from api - if instance := cls.from_api(js, builder): - # Set account id to resource name and id - instance.name = instance.id = account_id - if (added := builder.add_node(instance, js)) is not None: - result.append(added) - return result - - @define(eq=False, slots=False) class AzureResourceRestoreParameters(AzureRestoreParametersBase): kind: ClassVar[str] = "azure_resource_restore_parameters" @@ -1563,7 +1533,6 @@ def _collect_items( account_id: str, resource_type: str, class_instance: MicrosoftResource, - expected_errors: Optional[List[str]] = None, ) -> None: path = f"{account_id}/{resource_type}" api_spec = AzureResourceSpec( @@ -1574,7 +1543,6 @@ def _collect_items( query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=expected_errors or [], ) items = graph_builder.client.list(api_spec) if not items: @@ -1590,21 +1558,21 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: if api_type := self.api_type: api_type = api_type.split(",")[0] if api_type == "Sql": - resources_to_collect.append(("restorableSqlDatabases", AzureCosmosDBRestorableSqlDatabase, None)) + resources_to_collect.append(("restorableSqlDatabases", AzureCosmosDBRestorableSqlDatabase)) elif api_type == "MongoDB": resources_to_collect.append( - ("restorableMongodbDatabases", AzureCosmosDBRestorableMongoDBDatabase, None), # type: ignore + ("restorableMongodbDatabases", AzureCosmosDBRestorableMongoDBDatabase), # type: ignore ) elif api_type == "Table": resources_to_collect.append( - ("restorableTables", AzureCosmosDBRestorableTable, None), # type: ignore + ("restorableTables", AzureCosmosDBRestorableTable), # type: ignore ) elif api_type == "Gremlin": resources_to_collect.append( - ("restorableGremlinDatabases", AzureCosmosDBRestorableGremlinDatabase, None), # type: ignore + ("restorableGremlinDatabases", AzureCosmosDBRestorableGremlinDatabase), # type: ignore ) - for resource_type, resource_class, expected_errors in resources_to_collect: + for resource_type, resource_class in resources_to_collect: graph_builder.submit_work( service_name, self._collect_items, @@ -1612,7 +1580,6 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: account_id, resource_type, resource_class, - expected_errors, ) def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: @@ -1779,7 +1746,7 @@ def _collect_items( database_id: str, resource_type: str, class_instance: MicrosoftResource, - expected_errors: Optional[List[str]] = None, + expected_errors: Optional[Dict[str, Optional[str]]] = None, ) -> None: path = f"{database_id}/{resource_type}" api_spec = AzureResourceSpec( @@ -1790,7 +1757,7 @@ def _collect_items( query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=expected_errors or [], + expected_error_codes=expected_errors or {}, ) items = graph_builder.client.list(api_spec) if not items: @@ -1804,7 +1771,7 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: resources_to_collect = [ ("containers", AzureCosmosDBSqlDatabaseContainer, None), ("clientEncryptionKeys", AzureCosmosDBSqlDatabaseClientEncryptionKey, None), - ("throughputSettings/default", AzureCosmosDBSqlThroughputSetting, ["BadRequest"]), + ("throughputSettings/default", AzureCosmosDBSqlThroughputSetting, {"BadRequest": None}), ] for resource_type, resource_class, expected_errors in resources_to_collect: @@ -2425,7 +2392,7 @@ def _collect_items( account_id: str, resource_type: str, class_instance: MicrosoftResource, - expected_errors: Optional[List[str]] = None, + expected_errors: Optional[Dict[str, Optional[str]]] = None, ) -> None: path = f"{account_id}/{resource_type}" api_spec = AzureResourceSpec( @@ -2436,7 +2403,7 @@ def _collect_items( query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=expected_errors or [], + expected_error_codes=expected_errors or {}, ) items = graph_builder.client.list(api_spec) if not items: @@ -2459,7 +2426,7 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: if account_id := self.id: resources_to_collect = [ ("servers", AzureCosmosDBPostgresqlClusterServer, None), - ("configurations", AzureCosmosDBPostgresqlClusterConfiguration, ["internal_server_error"]), + ("configurations", AzureCosmosDBPostgresqlClusterConfiguration, {"internal_server_error": None}), ("privateEndpointConnections", AzureCosmosDBPostgresqlClusterPrivateEndpointConnection, None), ("privateLinkResources", AzureCosmosDBPostgresqlClusterPrivateLink, None), ("roles", AzureCosmosDBPostgresqlClusterRole, None), @@ -2555,7 +2522,7 @@ def collect_server_configs() -> None: query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=["internal_server_error"], + expected_error_codes={"internal_server_error": None}, ) items = graph_builder.client.list(api_spec) if not items: @@ -2705,7 +2672,6 @@ class AzureCosmosDBPostgresqlClusterRole(MicrosoftResource, AzureProxyResource): AzureCosmosDBCassandraCluster, AzureCosmosDBCassandraClusterDataCenter, AzureCosmosDBAccount, - AzureCosmosDBAccountReadOnlyKeys, AzureCosmosDBGremlinDatabase, AzureCosmosDBGremlinGraph, AzureCosmosDBMongoDBCollection, diff --git a/plugins/azure/fix_plugin_azure/resource/keyvault.py b/plugins/azure/fix_plugin_azure/resource/keyvault.py index 71e2188ee9..3355e89898 100644 --- a/plugins/azure/fix_plugin_azure/resource/keyvault.py +++ b/plugins/azure/fix_plugin_azure/resource/keyvault.py @@ -181,8 +181,8 @@ class AzureKeyReleasePolicy: @define(eq=False, slots=False) -class AzureSecret(MicrosoftResource): - kind: ClassVar[str] = "azure_secret" +class AzureKeyVaultSecret(MicrosoftResource): + kind: ClassVar[str] = "azure_key_vault_secret" # collected via AzureKeyVault mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -204,8 +204,8 @@ class AzureSecret(MicrosoftResource): @define(eq=False, slots=False) -class AzureManagedHsm(MicrosoftResource): - kind: ClassVar[str] = "azure_managed_hsm" +class AzureKeyVaultManagedHsm(MicrosoftResource): + kind: ClassVar[str] = "azure_key_vault_managed_hsm" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="keyvault", version="2023-07-01", @@ -264,8 +264,8 @@ class AzureManagedHsm(MicrosoftResource): @define(eq=False, slots=False) -class AzureKey(MicrosoftResource): - kind: ClassVar[str] = "azure_key" +class AzureKeyVaultKey(MicrosoftResource): + kind: ClassVar[str] = "azure_key_vault_key" # collected via AzureKeyVault mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -307,7 +307,9 @@ class AzureKeyVault(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": [AzureKey.kind, AzureMonitorDiagnosticSettings.kind]}, + "successors": { + "default": [AzureKeyVaultKey.kind, AzureMonitorDiagnosticSettings.kind, AzureKeyVaultManagedHsm.kind] + }, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -369,13 +371,18 @@ def collect_dependant(cls: Type[MicrosoftResource], name: str) -> None: graph_builder.add_node(dep) graph_builder.add_edge(self, node=dep) - graph_builder.submit_work(service_name, collect_dependant, AzureKey, "keys") - graph_builder.submit_work(service_name, collect_dependant, AzureSecret, "secrets") + graph_builder.submit_work(service_name, collect_dependant, AzureKeyVaultKey, "keys") + graph_builder.submit_work(service_name, collect_dependant, AzureKeyVaultSecret, "secrets") AzureMonitorDiagnosticSettings.fetch_diagnostics(graph_builder, self) + def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: + if hsm_pool_resource_id := self.hsm_pool_resource_id: + builder.add_edge(self, clazz=AzureKeyVaultManagedHsm, id=hsm_pool_resource_id) + resources: List[Type[MicrosoftResource]] = [ - AzureManagedHsm, + AzureKeyVaultManagedHsm, AzureKeyVault, - AzureKey, + AzureKeyVaultSecret, + AzureKeyVaultKey, ] diff --git a/plugins/azure/fix_plugin_azure/resource/machinelearning.py b/plugins/azure/fix_plugin_azure/resource/machinelearning.py index e885d3c9cb..5582e5f02e 100644 --- a/plugins/azure/fix_plugin_azure/resource/machinelearning.py +++ b/plugins/azure/fix_plugin_azure/resource/machinelearning.py @@ -18,11 +18,11 @@ AzureBaseUsage, AzurePrivateLinkServiceConnectionState, ) -from fix_plugin_azure.resource.compute import AzureVirtualMachineBase -from fix_plugin_azure.resource.containerservice import AzureManagedCluster +from fix_plugin_azure.resource.compute import AzureComputeVirtualMachineBase +from fix_plugin_azure.resource.containerservice import AzureContainerServiceManagedCluster from fix_plugin_azure.resource.keyvault import AzureKeyVault from fix_plugin_azure.resource.microsoft_graph import MicrosoftGraphServicePrincipal, MicrosoftGraphUser -from fix_plugin_azure.resource.network import AzureSubnet, AzureVirtualNetwork +from fix_plugin_azure.resource.network import AzureNetworkSubnet, AzureNetworkVirtualNetwork from fix_plugin_azure.resource.storage import AzureStorageAccount from fix_plugin_azure.resource.web import AzureWebApp from fixlib.baseresources import BaseInstanceType, ModelReference @@ -443,6 +443,9 @@ class AzureMachineLearningCompute(MicrosoftResource): "azure_machine_learning_compute_node", MicrosoftGraphServicePrincipal.kind, MicrosoftGraphUser.kind, + AzureComputeVirtualMachineBase.kind, + AzureContainerServiceManagedCluster.kind, + AzureWebApp.kind, ] }, } @@ -549,7 +552,9 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: ) if compute_resource_id := self.resource_id: builder.add_edge( - self, clazz=(AzureVirtualMachineBase, AzureManagedCluster, AzureWebApp), id=compute_resource_id + self, + clazz=(AzureComputeVirtualMachineBase, AzureContainerServiceManagedCluster, AzureWebApp), + id=compute_resource_id, ) @@ -1946,7 +1951,7 @@ def _collect_items( registry_id: str, resource_type: str, class_instance: MicrosoftResource, - expected_errors: Optional[List[str]] = None, + expected_errors: Optional[Dict[str, Optional[str]]] = None, ) -> None: path = f"{registry_id}/{resource_type}" api_spec = AzureResourceSpec( @@ -1957,7 +1962,7 @@ def _collect_items( query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=expected_errors or [], + expected_error_codes=expected_errors or {}, ) items = graph_builder.client.list(api_spec) if not items: @@ -1969,7 +1974,7 @@ def _collect_items( def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: if registry_id := self.id: resources_to_collect = [ - ("codes", AzureMachineLearningRegistryCodeContainer, ["UserError"]), + ("codes", AzureMachineLearningRegistryCodeContainer, {"UserError": None}), ("components", AzureMachineLearningRegistryComponentContainer, None), ("data", AzureMachineLearningRegistryDataContainer, None), ("environments", AzureMachineLearningRegistryEnvironmentContainer, None), @@ -2017,7 +2022,7 @@ class AzureMachineLearningQuota(MicrosoftResource): query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=["InternalServerError", "ServiceError"], + expected_error_codes={"InternalServerError": None, "ServiceError": None}, ) mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -2143,7 +2148,11 @@ class AzureMachineLearningUsage(MicrosoftResource, AzureBaseUsage): query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=AzureBaseUsage._expected_error_codes + ["InternalServerError", "ServiceError"], + expected_error_codes={ + **AzureBaseUsage._expected_error_codes, + "InternalServerError": None, + "ServiceError": None, + }, ) mapping: ClassVar[Dict[str, Bender]] = AzureBaseUsage.mapping | { "id": S("id"), @@ -2401,9 +2410,9 @@ class AzureMachineLearningWorkspace(MicrosoftResource): "predecessors": { "default": [ AzureKeyVault.kind, - AzureVirtualNetwork.kind, + AzureNetworkVirtualNetwork.kind, AzureStorageAccount.kind, - AzureSubnet.kind, + AzureNetworkSubnet.kind, ] }, } @@ -2495,7 +2504,7 @@ def _collect_items( workspace_id: str, resource_type: str, class_instance: MicrosoftResource, - expected_errors: Optional[List[str]] = None, + expected_errors: Optional[Dict[str, Optional[str]]] = None, ) -> None: path = f"{workspace_id}/{resource_type}" api_spec = AzureResourceSpec( @@ -2506,7 +2515,7 @@ def _collect_items( query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=expected_errors or [], + expected_error_codes=expected_errors or {}, ) items = graph_builder.client.list(api_spec) if not items: @@ -2530,12 +2539,12 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: ("schedules", AzureMachineLearningSchedule, None), ("serverlessEndpoints", AzureMachineLearningServerlessEndpoint, None), ("connections", AzureMachineLearningWorkspaceConnection, None), - ("codes", AzureMachineLearningWorkspaceCodeContainer, ["UserError"]), + ("codes", AzureMachineLearningWorkspaceCodeContainer, {"UserError": None}), ("components", AzureMachineLearningWorkspaceComponentContainer, None), ("data", AzureMachineLearningWorkspaceDataContainer, None), ("environments", AzureMachineLearningWorkspaceEnvironmentContainer, None), - ("featuresets", AzureMachineLearningFeaturesetContainer, ["UserError"]), - ("featurestoreEntities", AzureMachineLearningFeaturestoreEntityContainer, ["UserError"]), + ("featuresets", AzureMachineLearningFeaturesetContainer, {"UserError": None}), + ("featurestoreEntities", AzureMachineLearningFeaturestoreEntityContainer, {"UserError": None}), ("models", AzureMachineLearningWorkspaceModelContainer, None), ] @@ -2554,13 +2563,13 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if key_vault_id := self.key_vault: builder.add_edge(self, clazz=AzureKeyVault, reverse=True, id=key_vault_id) if (network := self.managed_network) and (network_id := network.network_id): - builder.add_edge(self, clazz=AzureVirtualNetwork, reverse=True, id=network_id) + builder.add_edge(self, clazz=AzureNetworkVirtualNetwork, reverse=True, id=network_id) if storage_id := self.storage_account: builder.add_edge(self, clazz=AzureStorageAccount, reverse=True, id=storage_id) if (compute_settings := self.serverless_compute_settings) and ( subnet_id := compute_settings.serverless_compute_custom_subnet ): - builder.add_edge(self, clazz=AzureSubnet, reverse=True, id=subnet_id) + builder.add_edge(self, clazz=AzureNetworkSubnet, reverse=True, id=subnet_id) # principal: collected via ms graph -> create a deferred edge if ai := self.identity: diff --git a/plugins/azure/fix_plugin_azure/resource/monitor.py b/plugins/azure/fix_plugin_azure/resource/monitor.py index 95785a23c1..7e873bf2df 100644 --- a/plugins/azure/fix_plugin_azure/resource/monitor.py +++ b/plugins/azure/fix_plugin_azure/resource/monitor.py @@ -291,8 +291,8 @@ class AzureMonitorActionGroupRef: @define(eq=False, slots=False) -class AzureActivityLogAlert(MicrosoftResource): - kind: ClassVar[str] = "azure_activity_log_alert" +class AzureMonitorActivityLogAlert(MicrosoftResource): + kind: ClassVar[str] = "azure_monitor_activity_log_alert" reference_kinds: ClassVar[ModelReference] = { "predecessors": {"default": [AzureMonitorActionGroup.kind]}, } @@ -1361,7 +1361,7 @@ def execute() -> None: resources: List[Type[MicrosoftResource]] = [ AzureMonitorActionGroup, - AzureActivityLogAlert, + AzureMonitorActivityLogAlert, AzureMonitorAlertRule, AzureMonitorDataCollectionRule, AzureMonitorLogProfile, diff --git a/plugins/azure/fix_plugin_azure/resource/mysql.py b/plugins/azure/fix_plugin_azure/resource/mysql.py index de174813da..6922833c69 100644 --- a/plugins/azure/fix_plugin_azure/resource/mysql.py +++ b/plugins/azure/fix_plugin_azure/resource/mysql.py @@ -623,7 +623,7 @@ def _collect_items( resource_type: str, class_instance: MicrosoftResource, api_version: str, - expected_errors: Optional[List[str]] = None, + expected_errors: Optional[Dict[str, Optional[str]]] = None, ) -> None: path = f"{server_id}/{resource_type}" api_spec = AzureResourceSpec( @@ -634,7 +634,7 @@ def _collect_items( query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=expected_errors or [], + expected_error_codes=expected_errors or {}, ) items = graph_builder.client.list(api_spec) if not items: diff --git a/plugins/azure/fix_plugin_azure/resource/network.py b/plugins/azure/fix_plugin_azure/resource/network.py index f535af587b..889c1a2469 100644 --- a/plugins/azure/fix_plugin_azure/resource/network.py +++ b/plugins/azure/fix_plugin_azure/resource/network.py @@ -15,7 +15,7 @@ MicrosoftResource, AzurePrivateEndpointConnection, ) -from fix_plugin_azure.resource.containerservice import AzureManagedCluster +from fix_plugin_azure.resource.containerservice import AzureContainerServiceManagedCluster from fix_plugin_azure.resource.storage import AzureStorageAccount from fix_plugin_azure.utils import rgetattr from fixlib.baseresources import ( @@ -954,8 +954,8 @@ class AzureApplicationGatewayGlobalConfiguration: @define(eq=False, slots=False) -class AzureApplicationGateway(MicrosoftResource, BaseGateway): - kind: ClassVar[str] = "azure_application_gateway" +class AzureNetworkApplicationGateway(MicrosoftResource, BaseGateway): + kind: ClassVar[str] = "azure_network_application_gateway" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -966,8 +966,8 @@ class AzureApplicationGateway(MicrosoftResource, BaseGateway): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_subnet"]}, - "successors": {"default": ["azure_web_application_firewall_policy"]}, + "predecessors": {"default": ["azure_network_subnet"]}, + "successors": {"default": ["azure_network_web_application_firewall_policy"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -1071,7 +1071,7 @@ class AzureApplicationGateway(MicrosoftResource, BaseGateway): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if firewall_policy := self.firewall_policy: builder.add_edge( - self, edge_type=EdgeType.default, clazz=AzureWebApplicationFirewallPolicy, id=firewall_policy + self, edge_type=EdgeType.default, clazz=AzureNetworkWebApplicationFirewallPolicy, id=firewall_policy ) if pl_configurations := self.private_link_configurations: for pl_configuration in pl_configurations: @@ -1079,7 +1079,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for ip_configuration in ip_configurations: if subnet_id := ip_configuration.subnet: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id ) @@ -1114,8 +1114,8 @@ class AzureApplicationGatewayFirewallRuleGroup: @define(eq=False, slots=False) -class AzureApplicationGatewayFirewallRuleSet(MicrosoftResource): - kind: ClassVar[str] = "azure_application_gateway_firewall_rule_set" +class AzureNetworkApplicationGatewayFirewallRuleSet(MicrosoftResource): + kind: ClassVar[str] = "azure_network_application_gateway_firewall_rule_set" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -1228,7 +1228,9 @@ class AzureFirewallNatRuleCollection(AzureSubResource): "provisioning_state": S("properties", "provisioningState"), "rules": S("properties", "rules") >> ForallBend(AzureFirewallNatRule.mapping), } - action: Optional[str] = field(default=None, metadata={"description": "AzureFirewall NAT Rule Collection Action."}) + action: Optional[str] = field( + default=None, metadata={"description": "AzureNetworkFirewall NAT Rule Collection Action."} + ) etag: Optional[str] = field(default=None, metadata={'description': 'A unique read-only string that changes whenever the resource is updated.'}) # fmt: skip name: Optional[str] = field(default=None, metadata={'description': 'The name of the resource that is unique within the Azure firewall. This name can be used to access the resource.'}) # fmt: skip priority: Optional[int] = field(default=None, metadata={'description': 'Priority of the NAT rule collection resource.'}) # fmt: skip @@ -1340,8 +1342,8 @@ class AzureFirewallSku: @define(eq=False, slots=False) -class AzureFirewall(MicrosoftResource, BaseFirewall): - kind: ClassVar[str] = "azure_firewall" +class AzureNetworkFirewall(MicrosoftResource, BaseFirewall): + kind: ClassVar[str] = "azure_network_firewall" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -1352,8 +1354,8 @@ class AzureFirewall(MicrosoftResource, BaseFirewall): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_subnet"]}, - "successors": {"default": ["azure_firewall_policy", "azure_virtual_hub"]}, + "predecessors": {"default": ["azure_network_subnet"]}, + "successors": {"default": ["azure_network_firewall_policy", "azure_network_virtual_hub"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -1396,13 +1398,15 @@ class AzureFirewall(MicrosoftResource, BaseFirewall): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if policy_id := self.firewall_policy: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureFirewallPolicy, id=policy_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkFirewallPolicy, id=policy_id) if ip_confs := self.firewall_ip_configurations: for ip_conf in ip_confs: if subnet_id := ip_conf.subnet: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id) + builder.add_edge( + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id + ) if vh_id := self.virtual_hub: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualHub, id=vh_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkVirtualHub, id=vh_id) @define(eq=False, slots=False) @@ -1434,8 +1438,8 @@ class AzureIpRules: @define(eq=False, slots=False) -class AzureBastionHost(MicrosoftResource): - kind: ClassVar[str] = "azure_bastion_host" +class AzureNetworkBastionHost(MicrosoftResource): + kind: ClassVar[str] = "azure_network_bastion_host" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -1446,8 +1450,8 @@ class AzureBastionHost(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_virtual_network", "azure_subnet"]}, - "successors": {"default": ["azure_public_ip_address"]}, + "predecessors": {"default": ["azure_network_virtual_network", "azure_network_subnet"]}, + "successors": {"default": ["azure_network_public_ip_address"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -1485,18 +1489,22 @@ class AzureBastionHost(MicrosoftResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vn_id := self.virtual_network: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkVirtualNetwork, id=vn_id) if ip_configurations := self.bastion_host_ip_configurations: for ip_configuration in ip_configurations: if subnet_id := ip_configuration.subnet: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id) + builder.add_edge( + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id + ) if p_ip_address_id := ip_configuration.public_ip_address: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzurePublicIPAddress, id=p_ip_address_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureNetworkPublicIPAddress, id=p_ip_address_id + ) @define(eq=False, slots=False) -class AzureCustomIpPrefix(MicrosoftResource): - kind: ClassVar[str] = "azure_custom_ip_prefix" +class AzureNetworkCustomIpPrefix(MicrosoftResource): + kind: ClassVar[str] = "azure_network_custom_ip_prefix" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -1546,8 +1554,8 @@ class AzureCustomIpPrefix(MicrosoftResource): @define(eq=False, slots=False) -class AzureDdosProtectionPlan(MicrosoftResource): - kind: ClassVar[str] = "azure_ddos_protection_plan" +class AzureNetworkDdosProtectionPlan(MicrosoftResource): + kind: ClassVar[str] = "azure_network_ddos_protection_plan" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -1558,7 +1566,7 @@ class AzureDdosProtectionPlan(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_public_ip_address", "azure_virtual_network"]}, + "successors": {"default": ["azure_network_public_ip_address", "azure_network_virtual_network"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -1577,10 +1585,12 @@ class AzureDdosProtectionPlan(MicrosoftResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vns := self.virtual_networks: for vn_id in vns: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkVirtualNetwork, id=vn_id) if p_ip_addresses := self.public_ip_addresses: for p_ip_address_id in p_ip_addresses: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzurePublicIPAddress, id=p_ip_address_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureNetworkPublicIPAddress, id=p_ip_address_id + ) @define(eq=False, slots=False) @@ -1660,7 +1670,7 @@ class AzureSecurityRule(AzureSubResource): } access: Optional[str] = field(default=None, metadata={'description': 'Whether network traffic is allowed or denied.'}) # fmt: skip description: Optional[str] = field(default=None, metadata={'description': 'A description for this rule. Restricted to 140 chars.'}) # fmt: skip - destination_address_prefix: Optional[str] = field(default=None, metadata={'description': 'The destination address prefix. CIDR or destination IP range. Asterisk * can also be used to match all source IPs. Default tags such as VirtualNetwork , AzureLoadBalancer and Internet can also be used.'}) # fmt: skip + destination_address_prefix: Optional[str] = field(default=None, metadata={'description': 'The destination address prefix. CIDR or destination IP range. Asterisk * can also be used to match all source IPs. Default tags such as VirtualNetwork , AzureNetworkLoadBalancer and Internet can also be used.'}) # fmt: skip destination_address_prefixes: Optional[List[str]] = field(default=None, metadata={'description': 'The destination address prefixes. CIDR or destination IP ranges.'}) # fmt: skip destination_application_security_groups: Optional[List[AzureApplicationSecurityGroup]] = field(default=None, metadata={'description': 'The application security group specified as destination.'}) # fmt: skip destination_port_ranges: Optional[List[AzurePortRange]] = field(default=None, metadata={'description': 'The destination port ranges.'}) # fmt: skip @@ -1670,7 +1680,7 @@ class AzureSecurityRule(AzureSubResource): priority: Optional[int] = field(default=None, metadata={'description': 'The priority of the rule. The value can be between 100 and 4096. The priority number must be unique for each rule in the collection. The lower the priority number, the higher the priority of the rule.'}) # fmt: skip protocol: Optional[str] = field(default=None, metadata={"description": "Network protocol this rule applies to."}) provisioning_state: Optional[str] = field(default=None, metadata={'description': 'The current provisioning state.'}) # fmt: skip - source_address_prefix: Optional[str] = field(default=None, metadata={'description': 'The CIDR or source IP range. Asterisk * can also be used to match all source IPs. Default tags such as VirtualNetwork , AzureLoadBalancer and Internet can also be used. If this is an ingress rule, specifies where network traffic originates from.'}) # fmt: skip + source_address_prefix: Optional[str] = field(default=None, metadata={'description': 'The CIDR or source IP range. Asterisk * can also be used to match all source IPs. Default tags such as VirtualNetwork , AzureNetworkLoadBalancer and Internet can also be used. If this is an ingress rule, specifies where network traffic originates from.'}) # fmt: skip source_address_prefixes: Optional[List[str]] = field(default=None, metadata={'description': 'The CIDR or source IP ranges.'}) # fmt: skip source_application_security_groups: Optional[List[AzureApplicationSecurityGroup]] = field(default=None, metadata={'description': 'The application security group specified as source.'}) # fmt: skip source_port_ranges: Optional[List[AzurePortRange]] = field( @@ -1723,8 +1733,8 @@ class AzureTrafficAnalyticsProperties: @define(eq=False, slots=False) -class AzureFlowLog(MicrosoftResource): - kind: ClassVar[str] = "azure_flow_log" +class AzureNetworkFlowLog(MicrosoftResource): + kind: ClassVar[str] = "azure_network_flow_log" # Collect via AzureNetworkWatcher() reference_kinds: ClassVar[ModelReference] = { "predecessors": {"default": ["azure_storage_account"]}, @@ -1776,7 +1786,7 @@ class AzureNetworkSecurityGroup(MicrosoftResource, BaseSecurityGroup): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_flow_log"]}, + "successors": {"default": ["azure_network_flow_log"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -1799,7 +1809,7 @@ class AzureNetworkSecurityGroup(MicrosoftResource, BaseSecurityGroup): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if flow_log_ids := self.flow_log_ids: for flow_log_id in flow_log_ids: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureFlowLog, id=flow_log_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkFlowLog, id=flow_log_id) @define(eq=False, slots=False) @@ -1841,8 +1851,8 @@ class AzureRoute(AzureSubResource): @define(eq=False, slots=False) -class AzureRouteTable(MicrosoftResource, BaseRoutingTable): - kind: ClassVar[str] = "azure_route_table" +class AzureNetworkRouteTable(MicrosoftResource, BaseRoutingTable): + kind: ClassVar[str] = "azure_network_route_table" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-09-01", @@ -1977,8 +1987,8 @@ class AzureIpTag: @define(eq=False, slots=False) -class AzureNatGateway(MicrosoftResource): - kind: ClassVar[str] = "azure_nat_gateway" +class AzureNetworkNatGateway(MicrosoftResource): + kind: ClassVar[str] = "azure_network_nat_gateway" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -2016,8 +2026,8 @@ class AzureNatGateway(MicrosoftResource): @define(eq=False, slots=False) -class AzurePublicIPAddress(MicrosoftResource, BaseIPAddress): - kind: ClassVar[str] = "azure_public_ip_address" +class AzureNetworkPublicIPAddress(MicrosoftResource, BaseIPAddress): + kind: ClassVar[str] = "azure_network_public_ip_address" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -2028,7 +2038,7 @@ class AzurePublicIPAddress(MicrosoftResource, BaseIPAddress): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_nat_gateway", "azure_public_ip_prefix"]}, + "predecessors": {"default": ["azure_network_nat_gateway", "azure_network_public_ip_prefix"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -2075,10 +2085,12 @@ class AzurePublicIPAddress(MicrosoftResource, BaseIPAddress): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if p_ip_prefix_id := self.public_ip_prefix: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzurePublicIPPrefix, id=p_ip_prefix_id + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkPublicIPPrefix, id=p_ip_prefix_id ) if nat_gateway_id := self._nat_gateway_id: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNatGateway, id=nat_gateway_id) + builder.add_edge( + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkNatGateway, id=nat_gateway_id + ) @define(eq=False, slots=False) @@ -2185,14 +2197,14 @@ class AzureDelegation(AzureSubResource): @define(eq=False, slots=False) -class AzureSubnet(MicrosoftResource, BaseSubnet): - kind: ClassVar[str] = "azure_subnet" +class AzureNetworkSubnet(MicrosoftResource, BaseSubnet): + kind: ClassVar[str] = "azure_network_subnet" reference_kinds: ClassVar[ModelReference] = { "successors": { "default": [ - "azure_nat_gateway", + "azure_network_nat_gateway", "azure_network_security_group", - "azure_route_table", + "azure_network_route_table", ] }, } @@ -2252,11 +2264,11 @@ class AzureSubnet(MicrosoftResource, BaseSubnet): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if nat_gateway_id := self._nat_gateway_id: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNatGateway, id=nat_gateway_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkNatGateway, id=nat_gateway_id) if nsg_id := self._network_security_group_id: builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkSecurityGroup, id=nsg_id) if route_table_id := self._route_table_id: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureRouteTable, id=route_table_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkRouteTable, id=route_table_id) @define(eq=False, slots=False) @@ -2299,8 +2311,8 @@ class AzureFrontendIPConfiguration(AzureSubResource): @define(eq=False, slots=False) -class AzureVirtualNetworkTap(MicrosoftResource): - kind: ClassVar[str] = "azure_virtual_network_tap" +class AzureNetworkVirtualNetworkTap(MicrosoftResource): + kind: ClassVar[str] = "azure_network_virtual_network_tap" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -2500,8 +2512,8 @@ class AzureResourceSet: @define(eq=False, slots=False) -class AzurePrivateLinkService(MicrosoftResource): - kind: ClassVar[str] = "azure_private_link_service" +class AzureNetworkPrivateLinkService(MicrosoftResource): + kind: ClassVar[str] = "azure_network_private_link_service" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -2562,12 +2574,12 @@ class AzureNetworkInterface(MicrosoftResource, BaseNetworkInterface): reference_kinds: ClassVar[ModelReference] = { "predecessors": { "default": [ - "azure_virtual_network_tap", + "azure_network_virtual_network_tap", "azure_network_security_group", - "azure_private_link_service", + "azure_network_private_link_service", ] }, - "successors": {"default": ["azure_dscp_configuration"]}, + "successors": {"default": ["azure_network_dscp_configuration"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -2631,32 +2643,36 @@ class AzureNetworkInterface(MicrosoftResource, BaseNetworkInterface): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if dscp_config_id := self.dscp_configuration: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureDscpConfiguration, id=dscp_config_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkDscpConfiguration, id=dscp_config_id) if tap_configs := self.tap_configurations: for tap_config in tap_configs: if vn_tap_id := tap_config.id: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureVirtualNetworkTap, id=vn_tap_id + self, + edge_type=EdgeType.default, + reverse=True, + clazz=AzureNetworkVirtualNetworkTap, + id=vn_tap_id, ) if nsg_id := self._network_security_group_id: builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSecurityGroup, id=nsg_id) if p_l_service_id := self._private_link_service_id: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzurePrivateLinkService, id=p_l_service_id + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkPrivateLinkService, id=p_l_service_id ) if interface_ip_configurations := self.interface_ip_configurations: for interface_ip_configuration in interface_ip_configurations: if public_ip_id := interface_ip_configuration._public_ip_id: - public_ip_addresses = builder.nodes(clazz=AzurePublicIPAddress, id=public_ip_id) + public_ip_addresses = builder.nodes(clazz=AzureNetworkPublicIPAddress, id=public_ip_id) for public_ip_address in public_ip_addresses: if ip_addr := public_ip_address.ip_address: self.public_ips.append(ip_addr) @define(eq=False, slots=False) -class AzureDscpConfiguration(MicrosoftResource): - kind: ClassVar[str] = "azure_dscp_configuration" +class AzureNetworkDscpConfiguration(MicrosoftResource): + kind: ClassVar[str] = "azure_network_dscp_configuration" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -2667,7 +2683,7 @@ class AzureDscpConfiguration(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_subnet"]}, + "predecessors": {"default": ["azure_network_subnet"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -2712,7 +2728,11 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for subnet_id in subnet_ids: if network_interface_id == ni_id: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id + self, + edge_type=EdgeType.default, + reverse=True, + clazz=AzureNetworkSubnet, + id=subnet_id, ) def _get_nic_id_and_subnet_ids(self, builder: GraphBuilder) -> List[Tuple[str, List[str]]]: @@ -2935,8 +2955,8 @@ class AzureExpressRouteCircuitServiceProviderProperties: @define(eq=False, slots=False) -class AzureExpressRouteCircuit(MicrosoftResource): - kind: ClassVar[str] = "azure_express_route_circuit" +class AzureNetworkExpressRouteCircuit(MicrosoftResource): + kind: ClassVar[str] = "azure_network_express_route_circuit" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -2947,7 +2967,7 @@ class AzureExpressRouteCircuit(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_express_route_port", "azure_express_route_ports_location"]}, + "successors": {"default": ["azure_network_express_route_port", "azure_network_express_route_ports_location"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -2993,7 +3013,7 @@ class AzureExpressRouteCircuit(MicrosoftResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if route_port_id := self.express_route_port: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureExpressRoutePort, id=route_port_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkExpressRoutePort, id=route_port_id) if (provider_properties := self.service_provider_properties) and ( location_name := provider_properties.peering_location ): @@ -3004,13 +3024,16 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: erplocation, erplocation_id = info if erplocation == location_name: builder.add_edge( - self, edge_type=EdgeType.default, clazz=AzureExpressRoutePortsLocation, id=erplocation_id + self, + edge_type=EdgeType.default, + clazz=AzureNetworkExpressRoutePortsLocation, + id=erplocation_id, ) def _get_aerpl_name_and_id(self, builder: GraphBuilder) -> List[Tuple[str, str]]: return [ (aerpl_name, aerpl_id) - for location in builder.nodes(clazz=AzureExpressRoutePortsLocation) + for location in builder.nodes(clazz=AzureNetworkExpressRoutePortsLocation) if (aerpl_name := location.name) and (aerpl_id := location.id) ] @@ -3059,8 +3082,8 @@ class AzureExpressRouteCrossConnectionPeering(AzureSubResource): @define(eq=False, slots=False) -class AzureExpressRouteCrossConnection(MicrosoftResource): - kind: ClassVar[str] = "azure_express_route_cross_connection" +class AzureNetworkExpressRouteCrossConnection(MicrosoftResource): + kind: ClassVar[str] = "azure_network_express_route_cross_connection" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -3203,8 +3226,8 @@ class AzureExpressRouteConnection(AzureSubResource): @define(eq=False, slots=False) -class AzureExpressRouteGateway(MicrosoftResource, BaseGateway): - kind: ClassVar[str] = "azure_express_route_gateway" +class AzureNetworkExpressRouteGateway(MicrosoftResource, BaseGateway): + kind: ClassVar[str] = "azure_network_express_route_gateway" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -3277,8 +3300,8 @@ class AzureExpressRouteLink(AzureSubResource): @define(eq=False, slots=False) -class AzureExpressRoutePort(MicrosoftResource): - kind: ClassVar[str] = "azure_express_route_port" +class AzureNetworkExpressRoutePort(MicrosoftResource): + kind: ClassVar[str] = "azure_network_express_route_port" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -3330,8 +3353,8 @@ class AzureExpressRoutePortsLocationBandwidths: @define(eq=False, slots=False) -class AzureExpressRoutePortsLocation(MicrosoftResource): - kind: ClassVar[str] = "azure_express_route_ports_location" +class AzureNetworkExpressRoutePortsLocation(MicrosoftResource): + kind: ClassVar[str] = "azure_network_express_route_ports_location" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -3514,8 +3537,8 @@ class AzureFirewallPolicyTransportSecurity: @define(eq=False, slots=False) -class AzureFirewallPolicy(MicrosoftResource, BasePolicy): - kind: ClassVar[str] = "azure_firewall_policy" +class AzureNetworkFirewallPolicy(MicrosoftResource, BasePolicy): + kind: ClassVar[str] = "azure_network_firewall_policy" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -3570,8 +3593,8 @@ class AzureFirewallPolicy(MicrosoftResource, BasePolicy): @define(eq=False, slots=False) -class AzureIpAllocation(MicrosoftResource): - kind: ClassVar[str] = "azure_ip_allocation" +class AzureNetworkIpAllocation(MicrosoftResource): + kind: ClassVar[str] = "azure_network_ip_allocation" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -3582,7 +3605,7 @@ class AzureIpAllocation(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_virtual_network", "azure_subnet"]}, + "predecessors": {"default": ["azure_network_virtual_network", "azure_network_subnet"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -3607,14 +3630,14 @@ class AzureIpAllocation(MicrosoftResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vn_id := self.virtual_network: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkVirtualNetwork, id=vn_id) if subnet_id := self.subnet: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id) @define(eq=False, slots=False) -class AzureIpGroup(MicrosoftResource): - kind: ClassVar[str] = "azure_ip_group" +class AzureNetworkIpGroup(MicrosoftResource): + kind: ClassVar[str] = "azure_network_ip_group" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -3625,7 +3648,7 @@ class AzureIpGroup(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_virtual_network"]}, + "predecessors": {"default": ["azure_network_virtual_network"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -3652,23 +3675,29 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for vn_address in vn_ips: if ip_address == vn_address: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureVirtualNetwork, id=vn_id + self, + edge_type=EdgeType.default, + reverse=True, + clazz=AzureNetworkVirtualNetwork, + id=vn_id, ) def _get_virtual_network_ips_and_ids(self, builder: GraphBuilder) -> List[Tuple[List[str], str]]: - get_virtual_network_ips: Callable[[AzureVirtualNetwork], List[str]] = lambda vn: ( + get_virtual_network_ips: Callable[[AzureNetworkVirtualNetwork], List[str]] = lambda vn: ( rgetattr(vn, "address_space.address_prefixes", None) or [] ) return [ - (get_virtual_network_ips(vn), vn_id) for vn in builder.nodes(clazz=AzureVirtualNetwork) if (vn_id := vn.id) + (get_virtual_network_ips(vn), vn_id) + for vn in builder.nodes(clazz=AzureNetworkVirtualNetwork) + if (vn_id := vn.id) ] @define(eq=False, slots=False) -class AzureLoadBalancerProbe(MicrosoftResource, BaseHealthCheck): - kind: ClassVar[str] = "azure_load_balancer_probe" - # Collect via AzureLoadBalancer +class AzureNetworkLoadBalancerProbe(MicrosoftResource, BaseHealthCheck): + kind: ClassVar[str] = "azure_network_load_balancer_probe" + # Collect via AzureNetworkLoadBalancer mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), "tags": S("tags", default={}), @@ -3890,8 +3919,8 @@ class AzureOutboundRule(AzureSubResource): @define(eq=False, slots=False) -class AzureLoadBalancer(MicrosoftResource, BaseLoadBalancer): - kind: ClassVar[str] = "azure_load_balancer" +class AzureNetworkLoadBalancer(MicrosoftResource, BaseLoadBalancer): + kind: ClassVar[str] = "azure_network_load_balancer" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -3902,8 +3931,14 @@ class AzureLoadBalancer(MicrosoftResource, BaseLoadBalancer): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_virtual_network", "azure_subnet", "azure_managed_cluster"]}, - "successors": {"default": ["azure_load_balancer_probe"]}, + "predecessors": { + "default": [ + "azure_network_virtual_network", + "azure_network_subnet", + "azure_container_service_managed_cluster", + ] + }, + "successors": {"default": ["azure_network_load_balancer_probe"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -3954,24 +3989,28 @@ def collect_lb_probes() -> None: ) items = graph_builder.client.list(api_spec) - lb_probes = AzureLoadBalancerProbe.collect(items, graph_builder) + lb_probes = AzureNetworkLoadBalancerProbe.collect(items, graph_builder) for lb_probe in lb_probes: - graph_builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureLoadBalancerProbe, id=lb_probe.id) + graph_builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureNetworkLoadBalancerProbe, id=lb_probe.id + ) graph_builder.submit_work(service_name, collect_lb_probes) def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vns := self.backends: for vn_id in vns: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge( + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkVirtualNetwork, id=vn_id + ) if baps := self.backend_address_pools: for bap in baps: if lbbas := bap.load_balancer_backend_addresses: for lbba in lbbas: if subnet_id := lbba.subnet: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id ) if ip_confs := self.lb_frontend_ip_configurations: p_ip_ids_and_cluster_ids = self._get_p_ip_ids_and_cluster_ids(builder) @@ -3981,15 +4020,15 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for ip_conf in ip_confs: if p_ip_address_id := ip_conf._public_ip_address_id: for info in p_ip_ids_and_cluster_ids: - ip_ids, clust_id = info + ip_ids, cluster_id = info for ip_id in ip_ids: if ip_id == p_ip_address_id: builder.add_edge( self, edge_type=EdgeType.default, reverse=True, - clazz=AzureManagedCluster, - id=clust_id, + clazz=AzureContainerServiceManagedCluster, + id=cluster_id, ) for ip_info in publ_ip_id_and_p_ip_address: pub_ip_id, ip_address = ip_info @@ -3999,21 +4038,21 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: def _get_publ_ip_id_and_p_ip_address(self, builder: GraphBuilder) -> List[Tuple[str, str]]: return [ (pub_ip_id, pub_ip_addr) - for ip in builder.nodes(clazz=AzurePublicIPAddress) + for ip in builder.nodes(clazz=AzureNetworkPublicIPAddress) if (ip.tags.get("k8s-azure-cluster-name") is not None) and (pub_ip_id := ip.id) and (pub_ip_addr := ip.ip_address) ] def _get_p_ip_ids_and_cluster_ids(self, builder: GraphBuilder) -> List[Tuple[List[str], str]]: - get_p_ip_ids: Callable[[AzureManagedCluster], List[str]] = lambda cluster: ( + get_p_ip_ids: Callable[[AzureContainerServiceManagedCluster], List[str]] = lambda cluster: ( rgetattr(cluster, "container_service_network_profile.load_balancer_profile.effective_outbound_i_ps", None) or [] ) return [ (get_p_ip_ids(cluster), cluster_id) - for cluster in builder.nodes(clazz=AzureManagedCluster) + for cluster in builder.nodes(clazz=AzureContainerServiceManagedCluster) if (cluster_id := cluster.id) ] @@ -4090,8 +4129,8 @@ class AzureNetworkProfile(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_subnet"]}, - "successors": {"default": ["azure_virtual_machine_base"]}, + "predecessors": {"default": ["azure_network_subnet"]}, + "successors": {"default": ["azure_compute_virtual_machine_base"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -4112,7 +4151,7 @@ class AzureNetworkProfile(MicrosoftResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: # Import placed inside the method due to circular import error resolution from fix_plugin_azure.resource.compute import ( - AzureVirtualMachineBase, + AzureComputeVirtualMachineBase, ) # pylint: disable=import-outside-toplevel if container_nic := self.container_network_interface_configurations: @@ -4123,7 +4162,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for ip_configuration in ip_configurations: if subnet_id := ip_configuration._subnet_id: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id ) if (ni_ids_and_vm_ids := ip_confs_and_vm_ids) and (c_ip_conf_id := ip_configuration.id): for info in ni_ids_and_vm_ids: @@ -4131,7 +4170,10 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for ip_conf_id in ip_conf_ids: if ip_conf_id == c_ip_conf_id: builder.add_edge( - self, edge_type=EdgeType.default, clazz=AzureVirtualMachineBase, id=vm_id + self, + edge_type=EdgeType.default, + clazz=AzureComputeVirtualMachineBase, + id=vm_id, ) def _get_ip_config_ids_and_vm_ids(self, builder: GraphBuilder) -> List[Tuple[List[str], str]]: @@ -4219,7 +4261,7 @@ class AzureNetworkVirtualAppliance(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_subnet"]}, + "predecessors": {"default": ["azure_network_subnet"]}, "successors": {"default": ["azure_network_virtual_appliance_sku"]}, } mapping: ClassVar[Dict[str, Bender]] = { @@ -4294,7 +4336,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureSubnet, + clazz=AzureNetworkSubnet, id=subnet_id, ) @@ -4368,8 +4410,8 @@ class AzureNetworkWatcher(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_virtual_network"]}, - "successors": {"default": ["azure_flow_log"]}, + "predecessors": {"default": ["azure_network_virtual_network"]}, + "successors": {"default": ["azure_network_flow_log"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -4390,13 +4432,13 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: vn_location, vn_id = info if vn_location == nw_location: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureVirtualNetwork, id=vn_id + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkVirtualNetwork, id=vn_id ) def _get_virtual_network_locations_and_ids(self, builder: GraphBuilder) -> List[Tuple[str, str]]: return [ (vn_location, vn_id) - for network in builder.nodes(clazz=AzureVirtualNetwork) + for network in builder.nodes(clazz=AzureNetworkVirtualNetwork) if (vn_location := network.location) and (vn_id := network.id) ] @@ -4416,7 +4458,7 @@ def collect_flow_logs() -> None: items = graph_builder.client.list(api_spec) if not items: return - collected = AzureFlowLog.collect(items, graph_builder) + collected = AzureNetworkFlowLog.collect(items, graph_builder) for resource in collected: graph_builder.add_edge(self, node=resource) @@ -4513,8 +4555,8 @@ class AzureVpnClientConnectionHealth: @define(eq=False, slots=False) -class AzureP2SVpnGateway(MicrosoftResource, BaseGateway): - kind: ClassVar[str] = "azure_p2_s_vpn_gateway" +class AzureNetworkP2SVpnGateway(MicrosoftResource, BaseGateway): + kind: ClassVar[str] = "azure_network_p2_s_vpn_gateway" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -4525,7 +4567,7 @@ class AzureP2SVpnGateway(MicrosoftResource, BaseGateway): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_virtual_hub"]}, + "successors": {"default": ["azure_network_virtual_hub"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -4553,12 +4595,12 @@ class AzureP2SVpnGateway(MicrosoftResource, BaseGateway): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vh_id := self.virtual_hub: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualHub, id=vh_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkVirtualHub, id=vh_id) @define(eq=False, slots=False) -class AzurePublicIPPrefix(MicrosoftResource): - kind: ClassVar[str] = "azure_public_ip_prefix" +class AzureNetworkPublicIPPrefix(MicrosoftResource): + kind: ClassVar[str] = "azure_network_public_ip_prefix" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -4621,8 +4663,8 @@ class AzureRouteFilterRule(AzureSubResource): @define(eq=False, slots=False) -class AzureRouteFilter(MicrosoftResource): - kind: ClassVar[str] = "azure_route_filter" +class AzureNetworkRouteFilter(MicrosoftResource): + kind: ClassVar[str] = "azure_network_route_filter" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -4648,8 +4690,8 @@ class AzureRouteFilter(MicrosoftResource): @define(eq=False, slots=False) -class AzureSecurityPartnerProvider(MicrosoftResource): - kind: ClassVar[str] = "azure_security_partner_provider" +class AzureNetworkSecurityPartnerProvider(MicrosoftResource): + kind: ClassVar[str] = "azure_network_security_partner_provider" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -4747,8 +4789,8 @@ class AzureVirtualHubRouteTableV2(AzureSubResource): @define(eq=False, slots=False) -class AzureVirtualHub(MicrosoftResource): - kind: ClassVar[str] = "azure_virtual_hub" +class AzureNetworkVirtualHub(MicrosoftResource): + kind: ClassVar[str] = "azure_network_virtual_hub" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -4760,9 +4802,13 @@ class AzureVirtualHub(MicrosoftResource): ) reference_kinds: ClassVar[ModelReference] = { "predecessors": { - "default": ["azure_express_route_gateway", "azure_virtual_wan_vpn_gateway", "azure_virtual_wan"] + "default": [ + "azure_network_express_route_gateway", + "azure_network_virtual_wan_vpn_gateway", + "azure_network_virtual_wan", + ] }, - "successors": {"default": ["azure_public_ip_address"]}, + "successors": {"default": ["azure_network_public_ip_address"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -4770,7 +4816,7 @@ class AzureVirtualHub(MicrosoftResource): "name": S("name"), "address_prefix": S("properties", "addressPrefix"), "allow_branch_to_branch_traffic": S("properties", "allowBranchToBranchTraffic"), - "azure_firewall": S("properties", "azureFirewall", "id"), + "azure_network_firewall": S("properties", "azureFirewall", "id"), "bgp_connections": S("properties") >> S("bgpConnections", default=[]) >> ForallBend(S("id")), "etag": S("etag"), "express_route_gateway": S("properties", "expressRouteGateway", "id"), @@ -4798,7 +4844,9 @@ class AzureVirtualHub(MicrosoftResource): } address_prefix: Optional[str] = field(default=None, metadata={'description': 'Address-prefix for this VirtualHub.'}) # fmt: skip allow_branch_to_branch_traffic: Optional[bool] = field(default=None, metadata={'description': 'Flag to control transit for VirtualRouter hub.'}) # fmt: skip - azure_firewall: Optional[str] = field(default=None, metadata={"description": "Reference to another subresource."}) + azure_network_firewall: Optional[str] = field( + default=None, metadata={"description": "Reference to another subresource."} + ) bgp_connections: Optional[List[str]] = field(default=None, metadata={'description': 'List of references to Bgp Connections.'}) # fmt: skip express_route_gateway: Optional[str] = field(default=None, metadata={'description': 'Reference to another subresource.'}) # fmt: skip hub_routing_preference: Optional[str] = field(default=None, metadata={'description': 'The hub routing preference gateway types'}) # fmt: skip @@ -4822,14 +4870,18 @@ class AzureVirtualHub(MicrosoftResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if er_gateway_id := self.express_route_gateway: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureExpressRouteGateway, id=er_gateway_id + self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkExpressRouteGateway, id=er_gateway_id ) if vpn_gateway_id := self.vpn_gateway: builder.add_edge( - self, edge_type=EdgeType.default, reverse=True, clazz=AzureVirtualWANVpnGateway, id=vpn_gateway_id + self, + edge_type=EdgeType.default, + reverse=True, + clazz=AzureNetworkVirtualWANVpnGateway, + id=vpn_gateway_id, ) if vw_id := self.virtual_wan: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureVirtualWAN, id=vw_id) + builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkVirtualWAN, id=vw_id) if ip_config_ids := self.ip_configuration_ids: ip_conf_ids_and_public_ip_ids = self._get_ip_conf_ids_and_public_ip_ids(builder) @@ -4841,7 +4893,10 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if ip_config_id == collected_ip_conf_id: for p_ip_address_id in p_ip_address_ids: builder.add_edge( - self, edge_type=EdgeType.default, clazz=AzurePublicIPAddress, id=p_ip_address_id + self, + edge_type=EdgeType.default, + clazz=AzureNetworkPublicIPAddress, + id=p_ip_address_id, ) def _get_ip_conf_ids_and_public_ip_ids(self, builder: GraphBuilder) -> List[Tuple[List[str], List[str]]]: @@ -4933,8 +4988,8 @@ class AzureVirtualNetworkPeering(AzureSubResource): @define(eq=False, slots=False) -class AzureVirtualNetwork(MicrosoftResource, BaseNetwork): - kind: ClassVar[str] = "azure_virtual_network" +class AzureNetworkVirtualNetwork(MicrosoftResource, BaseNetwork): + kind: ClassVar[str] = "azure_network_virtual_network" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -4945,7 +5000,7 @@ class AzureVirtualNetwork(MicrosoftResource, BaseNetwork): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_subnet"]}, + "successors": {"default": ["azure_network_subnet"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -4960,7 +5015,7 @@ class AzureVirtualNetwork(MicrosoftResource, BaseNetwork): "virtual_network_encryption": S("properties", "encryption") >> Bend(AzureVirtualNetworkEncryption.mapping), "etag": S("etag"), "extended_location": S("extendedLocation") >> Bend(AzureExtendedLocation.mapping), - "flow_logs": S("properties", "flowLogs") >> ForallBend(AzureFlowLog.mapping), + "flow_logs": S("properties", "flowLogs") >> ForallBend(AzureNetworkFlowLog.mapping), "flow_timeout_in_minutes": S("properties", "flowTimeoutInMinutes"), "ip_allocations": S("properties") >> S("ipAllocations", default=[]) >> ForallBend(S("id")), "provisioning_state": S("properties", "provisioningState"), @@ -4978,7 +5033,7 @@ class AzureVirtualNetwork(MicrosoftResource, BaseNetwork): enable_vm_protection: Optional[bool] = field(default=None, metadata={'description': 'Indicates if VM protection is enabled for all the subnets in the virtual network.'}) # fmt: skip virtual_network_encryption: Optional[AzureVirtualNetworkEncryption] = field(default=None, metadata={'description': 'Indicates if encryption is enabled on virtual network and if VM without encryption is allowed in encrypted VNet.'}) # fmt: skip extended_location: Optional[AzureExtendedLocation] = field(default=None, metadata={'description': 'ExtendedLocation complex type.'}) # fmt: skip - flow_logs: Optional[List[AzureFlowLog]] = field(default=None, metadata={'description': 'A collection of references to flow log resources.'}) # fmt: skip + flow_logs: Optional[List[AzureNetworkFlowLog]] = field(default=None, metadata={'description': 'A collection of references to flow log resources.'}) # fmt: skip flow_timeout_in_minutes: Optional[int] = field(default=None, metadata={'description': 'The FlowTimeout value (in minutes) for the Virtual Network'}) # fmt: skip ip_allocations: Optional[List[str]] = field(default=None, metadata={'description': 'Array of IpAllocation which reference this VNET.'}) # fmt: skip resource_guid: Optional[str] = field(default=None, metadata={'description': 'The resourceGuid property of the Virtual Network resource.'}) # fmt: skip @@ -4999,19 +5054,19 @@ def collect_subnets() -> None: ) items = graph_builder.client.list(api_spec) - AzureSubnet.collect(items, graph_builder) + AzureNetworkSubnet.collect(items, graph_builder) graph_builder.submit_work(service_name, collect_subnets) def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if subnets := self._subnet_ids: for subnet_id in subnets: - builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkSubnet, id=subnet_id) @define(eq=False, slots=False) -class AzureVirtualRouter(MicrosoftResource): - kind: ClassVar[str] = "azure_virtual_router" +class AzureNetworkVirtualRouter(MicrosoftResource): + kind: ClassVar[str] = "azure_network_virtual_router" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -5041,8 +5096,8 @@ class AzureVirtualRouter(MicrosoftResource): @define(eq=False, slots=False) -class AzureVirtualWAN(MicrosoftResource): - kind: ClassVar[str] = "azure_virtual_wan" +class AzureNetworkVirtualWAN(MicrosoftResource): + kind: ClassVar[str] = "azure_network_virtual_wan" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -5171,9 +5226,9 @@ class AzureVpnSiteLinkConnection(AzureSubResource): @define(eq=False, slots=False) -class AzureVirtualWANVpnConnection(MicrosoftResource, BaseTunnel): - kind: ClassVar[str] = "azure_virtual_wan_vpn_connection" - # Collect via AzureVirtualWANVpnGateway +class AzureNetworkVirtualWANVpnConnection(MicrosoftResource, BaseTunnel): + kind: ClassVar[str] = "azure_network_virtual_wan_vpn_connection" + # Collect via AzureNetworkVirtualWANVpnGateway mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), "connection_bandwidth": S("properties", "connectionBandwidth"), @@ -5304,8 +5359,8 @@ class AzureVpnGatewayNatRule(AzureSubResource): @define(eq=False, slots=False) -class AzureVirtualWANVpnGateway(MicrosoftResource, BaseGateway): - kind: ClassVar[str] = "azure_virtual_wan_vpn_gateway" +class AzureNetworkVirtualWANVpnGateway(MicrosoftResource, BaseGateway): + kind: ClassVar[str] = "azure_network_virtual_wan_vpn_gateway" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -5316,7 +5371,7 @@ class AzureVirtualWANVpnGateway(MicrosoftResource, BaseGateway): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "successors": {"default": ["azure_virtual_wan_vpn_connection"]}, + "successors": {"default": ["azure_network_virtual_wan_vpn_connection"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -5355,13 +5410,13 @@ def collect_vpn_connections() -> None: expect_array=True, ) items = graph_builder.client.list(api_spec) - vpn_connections = AzureVirtualWANVpnConnection.collect(items, graph_builder) + vpn_connections = AzureNetworkVirtualWANVpnConnection.collect(items, graph_builder) for vpn_connection in vpn_connections: graph_builder.add_edge( self, edge_type=EdgeType.default, - clazz=AzureVirtualWANVpnConnection, + clazz=AzureNetworkVirtualWANVpnConnection, id=vpn_connection.id, ) @@ -5427,8 +5482,8 @@ class AzureAadAuthenticationParameters: @define(eq=False, slots=False) -class AzureVpnServerConfiguration(MicrosoftResource): - kind: ClassVar[str] = "azure_vpn_server_configuration" +class AzureNetworkVpnServerConfiguration(MicrosoftResource): + kind: ClassVar[str] = "azure_network_vpn_server_configuration" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -5553,8 +5608,8 @@ class AzureO365PolicyProperties: @define(eq=False, slots=False) -class AzureVpnSite(MicrosoftResource, BasePeeringConnection): - kind: ClassVar[str] = "azure_vpn_site" +class AzureNetworkVpnSite(MicrosoftResource, BasePeeringConnection): + kind: ClassVar[str] = "azure_network_vpn_site" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -5565,7 +5620,7 @@ class AzureVpnSite(MicrosoftResource, BasePeeringConnection): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_virtual_wan"]}, + "predecessors": {"default": ["azure_network_virtual_wan"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -5595,7 +5650,7 @@ class AzureVpnSite(MicrosoftResource, BasePeeringConnection): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vw_id := self.virtual_wan: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureVirtualWAN, id=vw_id) + builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkVirtualWAN, id=vw_id) @define(eq=False, slots=False) @@ -5799,8 +5854,8 @@ class AzureManagedRulesDefinition: @define(eq=False, slots=False) -class AzureWebApplicationFirewallPolicy(MicrosoftResource): - kind: ClassVar[str] = "azure_web_application_firewall_policy" +class AzureNetworkWebApplicationFirewallPolicy(MicrosoftResource): + kind: ClassVar[str] = "azure_network_web_application_firewall_policy" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2023-05-01", @@ -6033,8 +6088,8 @@ class AzureVirtualNetworkGatewayNatRule(AzureSubResource): @define(eq=False, slots=False) -class AzureVirtualNetworkGateway(MicrosoftResource, BaseGateway): - kind: ClassVar[str] = "azure_virtual_network_gateway" +class AzureNetworkVirtualNetworkGateway(MicrosoftResource, BaseGateway): + kind: ClassVar[str] = "azure_network_virtual_network_gateway" # Collect via AzureResourceGroup mapping: ClassVar[Dict[str, Bender]] = { "active_active": S("properties", "activeActive"), @@ -6106,8 +6161,8 @@ class AzureVirtualNetworkGateway(MicrosoftResource, BaseGateway): @define(eq=False, slots=False) -class AzureLocalNetworkGateway(MicrosoftResource, BaseGateway): - kind: ClassVar[str] = "azure_local_network_gateway" +class AzureNetworkLocalNetworkGateway(MicrosoftResource, BaseGateway): + kind: ClassVar[str] = "azure_network_local_network_gateway" # Collect via AzureResourceGroup mapping: ClassVar[Dict[str, Bender]] = { "bgp_settings": S("properties", "bgpSettings") >> Bend(AzureBgpSettings.mapping), @@ -6150,11 +6205,11 @@ class AzureTunnelConnectionHealth: @define(eq=False, slots=False) -class AzureVirtualNetworkGatewayConnection(MicrosoftResource, BaseTunnel): - kind: ClassVar[str] = "azure_virtual_network_gateway_connection" +class AzureNetworkVirtualNetworkGatewayConnection(MicrosoftResource, BaseTunnel): + kind: ClassVar[str] = "azure_network_virtual_network_gateway_connection" # Collect via AzureResourceGroup reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_virtual_network_gateway", "azure_local_network_gateway"]}, + "predecessors": {"default": ["azure_network_virtual_network_gateway", "azure_network_local_network_gateway"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -6225,7 +6280,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureVirtualNetworkGateway, + clazz=AzureNetworkVirtualNetworkGateway, id=virtual_network_gateway1_id, ) if virtual_network_gateway2_id := self.virtual_network_gateway2_id: @@ -6233,7 +6288,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureVirtualNetworkGateway, + clazz=AzureNetworkVirtualNetworkGateway, id=virtual_network_gateway2_id, ) if local_network_gateway2_id := self.local_network_gateway2: @@ -6241,7 +6296,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, reverse=True, - clazz=AzureLocalNetworkGateway, + clazz=AzureNetworkLocalNetworkGateway, id=local_network_gateway2_id, ) @@ -6307,10 +6362,10 @@ class AzureCaaRecord: @define(eq=False, slots=False) -class AzureDNSRecordSet(MicrosoftResource, BaseDNSRecordSet): - kind: ClassVar[str] = "azure_dns_record_set" +class AzureNetworkDNSRecordSet(MicrosoftResource, BaseDNSRecordSet): + kind: ClassVar[str] = "azure_network_dns_record_set" reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_dns_zone"]}, + "predecessors": {"default": ["azure_network_dns_zone"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -6350,8 +6405,8 @@ class AzureDNSRecordSet(MicrosoftResource, BaseDNSRecordSet): @define(eq=False, slots=False) -class AzureDNSZone(MicrosoftResource, BaseDNSZone): - kind: ClassVar[str] = "azure_dns_zone" +class AzureNetworkDNSZone(MicrosoftResource, BaseDNSZone): + kind: ClassVar[str] = "azure_network_dns_zone" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="network", version="2018-05-01", @@ -6399,64 +6454,64 @@ def collect_record_sets() -> None: ) items = graph_builder.client.list(api_spec) - record_sets = AzureDNSRecordSet.collect(items, graph_builder) + record_sets = AzureNetworkDNSRecordSet.collect(items, graph_builder) for record_set in record_sets: dns_zone_id = "/".join(record_set.id.split("/")[:-2]) graph_builder.add_edge( - record_set, edge_type=EdgeType.default, reverse=True, clazz=AzureDNSZone, id=dns_zone_id + record_set, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkDNSZone, id=dns_zone_id ) graph_builder.submit_work(service_name, collect_record_sets) resources: List[Type[MicrosoftResource]] = [ - AzureApplicationGateway, - AzureApplicationGatewayFirewallRuleSet, - AzureFirewall, - AzureBastionHost, - AzureCustomIpPrefix, - AzureDdosProtectionPlan, - AzureDscpConfiguration, - AzureDNSZone, - AzureDNSRecordSet, - AzureExpressRouteCircuit, - # AzureExpressRouteCrossConnection, # API is listed but not available - AzureExpressRouteGateway, - AzureExpressRoutePort, - AzureExpressRoutePortsLocation, - AzureFirewallPolicy, - AzureIpAllocation, - AzureIpGroup, - AzureLoadBalancer, - AzureLoadBalancerProbe, - AzureNatGateway, + AzureNetworkApplicationGateway, + AzureNetworkApplicationGatewayFirewallRuleSet, + AzureNetworkFirewall, + AzureNetworkBastionHost, + AzureNetworkCustomIpPrefix, + AzureNetworkDdosProtectionPlan, + AzureNetworkDscpConfiguration, + AzureNetworkDNSZone, + AzureNetworkDNSRecordSet, + AzureNetworkExpressRouteCircuit, + # AzureNetworkExpressRouteCrossConnection, # API is listed but not available + AzureNetworkExpressRouteGateway, + AzureNetworkExpressRoutePort, + AzureNetworkExpressRoutePortsLocation, + AzureNetworkFirewallPolicy, + AzureNetworkIpAllocation, + AzureNetworkIpGroup, + AzureNetworkLoadBalancer, + AzureNetworkLoadBalancerProbe, + AzureNetworkNatGateway, AzureNetworkInterface, AzureNetworkProfile, AzureNetworkSecurityGroup, AzureNetworkVirtualAppliance, AzureNetworkVirtualApplianceSku, AzureNetworkWatcher, - AzureFlowLog, - AzureP2SVpnGateway, - AzurePrivateLinkService, - AzurePublicIPAddress, - AzurePublicIPPrefix, - AzureRouteFilter, - AzureSecurityPartnerProvider, - AzureSubnet, - AzureRouteTable, + AzureNetworkFlowLog, + AzureNetworkP2SVpnGateway, + AzureNetworkPrivateLinkService, + AzureNetworkPublicIPAddress, + AzureNetworkPublicIPPrefix, + AzureNetworkRouteFilter, + AzureNetworkSecurityPartnerProvider, + AzureNetworkSubnet, + AzureNetworkRouteTable, AzureNetworkUsage, - AzureVirtualHub, - AzureVirtualNetwork, - AzureVirtualNetworkTap, - AzureVirtualRouter, - AzureVirtualWAN, - AzureVirtualWANVpnGateway, - AzureVirtualWANVpnConnection, - AzureVpnServerConfiguration, - AzureVpnSite, - AzureVirtualNetworkGateway, - AzureLocalNetworkGateway, - AzureVirtualNetworkGatewayConnection, - AzureWebApplicationFirewallPolicy, + AzureNetworkVirtualHub, + AzureNetworkVirtualNetwork, + AzureNetworkVirtualNetworkTap, + AzureNetworkVirtualRouter, + AzureNetworkVirtualWAN, + AzureNetworkVirtualWANVpnGateway, + AzureNetworkVirtualWANVpnConnection, + AzureNetworkVpnServerConfiguration, + AzureNetworkVpnSite, + AzureNetworkVirtualNetworkGateway, + AzureNetworkLocalNetworkGateway, + AzureNetworkVirtualNetworkGatewayConnection, + AzureNetworkWebApplicationFirewallPolicy, ] diff --git a/plugins/azure/fix_plugin_azure/resource/postgresql.py b/plugins/azure/fix_plugin_azure/resource/postgresql.py index 980829bfb6..e0b21435d1 100644 --- a/plugins/azure/fix_plugin_azure/resource/postgresql.py +++ b/plugins/azure/fix_plugin_azure/resource/postgresql.py @@ -509,7 +509,7 @@ def _collect_items( server_id: str, resource_type: str, class_instance: MicrosoftResource, - expected_errors: Optional[List[str]] = None, + expected_errors: Optional[Dict[str, Optional[str]]] = None, ) -> None: path = f"{server_id}/{resource_type}" api_spec = AzureResourceSpec( @@ -520,7 +520,7 @@ def _collect_items( query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=expected_errors or [], + expected_error_codes=expected_errors or {}, ) items = graph_builder.client.list(api_spec) if not items: @@ -538,10 +538,18 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: ( "administrators", AzurePostgresqlServerADAdministrator, - ["InternalServerError", "DatabaseDoesNotExist"], + {"InternalServerError": None, "DatabaseDoesNotExist": None}, + ), + ( + "configurations", + AzurePostgresqlServerConfiguration, + {"InternalServerError": None, "DatabaseDoesNotExist": None}, + ), + ( + "databases", + AzurePostgresqlServerDatabase, + {"InternalServerError": None, "DatabaseDoesNotExist": None}, ), - ("configurations", AzurePostgresqlServerConfiguration, ["ServerStoppedError", "InternalServerError"]), - ("databases", AzurePostgresqlServerDatabase, ["ServerStoppedError", "InternalServerError"]), ("firewallRules", AzurePostgresqlServerFirewallRule, None), ("backups", AzurePostgresqlServerBackup, None), ] @@ -574,7 +582,7 @@ def collect_capabilities() -> None: query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=["InternalServerError"], + expected_error_codes={"InternalServerError": None}, ) items = graph_builder.client.list(api_spec) if not items: diff --git a/plugins/azure/fix_plugin_azure/resource/security.py b/plugins/azure/fix_plugin_azure/resource/security.py index 085027009f..c24ff27e8a 100644 --- a/plugins/azure/fix_plugin_azure/resource/security.py +++ b/plugins/azure/fix_plugin_azure/resource/security.py @@ -171,8 +171,8 @@ class AzureSecuritySetting(MicrosoftResource): @define(eq=False, slots=False) -class AzureAutoProvisioningSetting(MicrosoftResource): - kind: ClassVar[str] = "azure_auto_provisioning_setting" +class AzureSecurityAutoProvisioningSetting(MicrosoftResource): + kind: ClassVar[str] = "azure_security_auto_provisioning_setting" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="security", version="2017-08-01-preview", @@ -191,7 +191,7 @@ class AzureAutoProvisioningSetting(MicrosoftResource): resources: List[Type[MicrosoftResource]] = [ - AzureAutoProvisioningSetting, + AzureSecurityAutoProvisioningSetting, AzureSecurityAssessment, AzureSecurityPricing, AzureSecurityServerVulnerabilityAssessmentsSetting, diff --git a/plugins/azure/fix_plugin_azure/resource/sql_server.py b/plugins/azure/fix_plugin_azure/resource/sql_server.py index d3c55b75d4..456bb2b5f6 100644 --- a/plugins/azure/fix_plugin_azure/resource/sql_server.py +++ b/plugins/azure/fix_plugin_azure/resource/sql_server.py @@ -14,7 +14,7 @@ AzurePrivateEndpointConnection, ) from fix_plugin_azure.resource.microsoft_graph import MicrosoftGraphServicePrincipal, MicrosoftGraphUser -from fix_plugin_azure.resource.network import AzureSubnet +from fix_plugin_azure.resource.network import AzureNetworkSubnet from fixlib.baseresources import BaseDatabase, DatabaseInstanceStatus, EdgeType, ModelReference from fixlib.graph import BySearchCriteria from fixlib.json import value_in_path @@ -232,7 +232,7 @@ def _collect_items( database_id: str, resource_type: str, class_instance: MicrosoftResource, - expected_error_codes: Optional[List[str]] = None, + expected_error_codes: Optional[Dict[str, Optional[str]]] = None, ) -> None: path = f"{database_id}/{resource_type}" api_spec = AzureResourceSpec( @@ -243,7 +243,7 @@ def _collect_items( query_parameters=["api-version"], access_path="value", expect_array=True, - expected_error_codes=expected_error_codes or [], + expected_error_codes=expected_error_codes or {}, ) items = graph_builder.client.list(api_spec) collected = class_instance.collect(items, graph_builder) @@ -271,9 +271,9 @@ def fetch_data_encryption_status(sid: str) -> None: ( "advisors?$expand=recommendedAction", AzureSqlServerAdvisor, - ["DataWarehouseNotSupported", "DatabaseDoesNotExist"], + {"DataWarehouseNotSupported": None, "DatabaseDoesNotExist": None}, ), - ("workloadGroups", AzureSqlServerDatabaseWorkloadGroup, ["FeatureDisabledOnSelectedEdition"]), + ("workloadGroups", AzureSqlServerDatabaseWorkloadGroup, {"FeatureDisabledOnSelectedEdition": None}), ] for resource_type, resource_class, expected_error_codes in resources_to_collect: @@ -541,7 +541,7 @@ class AzureSqlServerManagedInstancePool(MicrosoftResource): expect_array=True, ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["azure_subnet"]}, + "predecessors": {"default": ["azure_network_subnet"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -563,7 +563,7 @@ class AzureSqlServerManagedInstancePool(MicrosoftResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if subnet_id := self.subnet_id: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id) @define(eq=False, slots=False) @@ -801,7 +801,7 @@ class AzureSqlServerManagedInstance(MicrosoftResource): "azure_sql_server_managed_instance_ad_administrator", ] }, - "predecessors": {"default": ["azure_sql_server_managed_instance_pool", "azure_subnet"]}, + "predecessors": {"default": ["azure_sql_server_managed_instance_pool", "azure_network_subnet"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -969,7 +969,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: id=instance_pool_id, ) if subnet_id := self.subnet_id: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id) # principal: collected via ms graph -> create a deferred edge if mii := self.managed_instance_identity: @@ -1003,7 +1003,7 @@ class AzureSqlServerVirtualCluster(MicrosoftResource): ) reference_kinds: ClassVar[ModelReference] = { "successors": {"default": ["azure_sql_server_managed_instance"]}, - "predecessors": {"default": ["azure_subnet"]}, + "predecessors": {"default": ["azure_network_subnet"]}, } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), @@ -1030,7 +1030,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: self, edge_type=EdgeType.default, clazz=AzureSqlServerManagedInstance, id=managed_instance_id ) if subnet_id := self.subnet_id: - builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, reverse=True, clazz=AzureNetworkSubnet, id=subnet_id) @define(eq=False, slots=False) diff --git a/plugins/azure/fix_plugin_azure/resource/storage.py b/plugins/azure/fix_plugin_azure/resource/storage.py index 2aae9aeb67..6e8b0d0852 100644 --- a/plugins/azure/fix_plugin_azure/resource/storage.py +++ b/plugins/azure/fix_plugin_azure/resource/storage.py @@ -131,8 +131,8 @@ class AzureImmutableStorageWithVersioning: @define(eq=False, slots=False) -class AzureBlobContainer(MicrosoftResource, BaseBucket): - kind: ClassVar[str] = "azure_blob_container" +class AzureStorageBlobContainer(MicrosoftResource, BaseBucket): + kind: ClassVar[str] = "azure_storage_blob_container" mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), "tags": S("tags", default={}), @@ -238,8 +238,8 @@ class AzureSignedIdentifier: @define(eq=False, slots=False) -class AzureFileShare(MicrosoftResource, BaseNetworkShare): - kind: ClassVar[str] = "azure_file_share" +class AzureStorageFileShare(MicrosoftResource, BaseNetworkShare): + kind: ClassVar[str] = "azure_storage_file_share" mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), "tags": S("tags", default={}), @@ -289,8 +289,8 @@ class AzureFileShare(MicrosoftResource, BaseNetworkShare): @define(eq=False, slots=False) -class AzureQueue(MicrosoftResource, BaseQueue): - kind: ClassVar[str] = "azure_queue" +class AzureStorageQueue(MicrosoftResource, BaseQueue): + kind: ClassVar[str] = "azure_storage_queue" mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), "tags": S("tags", default={}), @@ -531,8 +531,8 @@ class AzureActiveDirectoryProperties: @define(eq=False, slots=False) -class AzureAzureFilesIdentityBasedAuthentication: - kind: ClassVar[str] = "azure_azure_files_identity_based_authentication" +class AzureFilesIdentityBasedAuthentication: + kind: ClassVar[str] = "azure_files_identity_based_authentication" mapping: ClassVar[Dict[str, Bender]] = { "active_directory_properties": S("activeDirectoryProperties") >> Bend(AzureActiveDirectoryProperties.mapping), "default_share_permission": S("defaultSharePermission"), @@ -704,7 +704,13 @@ class AzureStorageAccount(MicrosoftResource): ) reference_kinds: ClassVar[ModelReference] = { "successors": { - "default": ["azure_storage_sku", "azure_file_share", "azure_blob_container", "azure_queue", "azure_table"] + "default": [ + "azure_storage_sku", + "azure_storage_file_share", + "azure_storage_blob_container", + "azure_storage_queue", + "azure_storage_table", + ] }, } mapping: ClassVar[Dict[str, Bender]] = { @@ -720,7 +726,7 @@ class AzureStorageAccount(MicrosoftResource): "allow_shared_key_access": S("properties", "allowSharedKeyAccess"), "allowed_copy_scope": S("properties", "allowedCopyScope"), "azure_files_identity_based_authentication": S("properties", "azureFilesIdentityBasedAuthentication") - >> Bend(AzureAzureFilesIdentityBasedAuthentication.mapping), + >> Bend(AzureFilesIdentityBasedAuthentication.mapping), "blob_restore_status": S("properties", "blobRestoreStatus") >> Bend(AzureBlobRestoreStatus.mapping), "creation_time": S("properties", "creationTime"), "storage_custom_domain": S("properties", "customDomain") >> Bend(AzureCustomDomain.mapping), @@ -776,12 +782,12 @@ class AzureStorageAccount(MicrosoftResource): allow_cross_tenant_replication: Optional[bool] = field(default=None, metadata={'description': 'Allow or disallow cross AAD tenant object replication. Set this property to true for new or existing accounts only if object replication policies will involve storage accounts in different AAD tenants. The default interpretation is false for new accounts to follow best security practices by default.'}) # fmt: skip allow_shared_key_access: Optional[bool] = field(default=None, metadata={'description': 'Indicates whether the storage account permits requests to be authorized with the account access key via Shared Key. If false, then all requests, including shared access signatures, must be authorized with Azure Active Directory (Azure AD). The default value is null, which is equivalent to true.'}) # fmt: skip allowed_copy_scope: Optional[str] = field(default=None, metadata={'description': 'Restrict copy to and from Storage Accounts within an AAD tenant or with Private Links to the same VNet.'}) # fmt: skip - azure_files_identity_based_authentication: Optional[AzureAzureFilesIdentityBasedAuthentication] = field(default=None, metadata={'description': 'Settings for Azure Files identity based authentication.'}) # fmt: skip + azure_files_identity_based_authentication: Optional[AzureFilesIdentityBasedAuthentication] = field(default=None, metadata={'description': 'Settings for Azure Files identity based authentication.'}) # fmt: skip blob_restore_status: Optional[AzureBlobRestoreStatus] = field(default=None, metadata={'description': 'Blob restore status.'}) # fmt: skip creation_time: Optional[datetime] = field(default=None, metadata={'description': 'Gets the creation date and time of the storage account in UTC.'}) # fmt: skip storage_custom_domain: Optional[AzureCustomDomain] = field(default=None, metadata={'description': 'The custom domain assigned to this storage account. This can be set via Update.'}) # fmt: skip default_to_oauth_authentication: Optional[bool] = field(default=None, metadata={'description': 'A boolean flag which indicates whether the default authentication is OAuth or not. The default interpretation is false for this property.'}) # fmt: skip - dns_endpoint_type: Optional[str] = field(default=None, metadata={'description': 'Allows you to specify the type of endpoint. Set this to AzureDNSZone to create a large number of accounts in a single subscription, which creates accounts in an Azure DNS Zone and the endpoint URL will have an alphanumeric DNS Zone identifier.'}) # fmt: skip + dns_endpoint_type: Optional[str] = field(default=None, metadata={'description': 'Allows you to specify the type of endpoint. Set this to AzureNetworkDNSZone to create a large number of accounts in a single subscription, which creates accounts in an Azure DNS Zone and the endpoint URL will have an alphanumeric DNS Zone identifier.'}) # fmt: skip storage_encryption: Optional[AzureStorageEncryption] = field(default=None, metadata={'description': 'The encryption settings on the storage account.'}) # fmt: skip extended_location: Optional[AzureExtendedLocation] = field(default=None, metadata={'description': 'The complex type of the extended location.'}) # fmt: skip failover_in_progress: Optional[bool] = field(default=None, metadata={'description': 'If the failover is in progress, the value will be true, otherwise, it will be null.'}) # fmt: skip @@ -855,7 +861,7 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: account_id, "fileServices", "shares", - AzureFileShare, + AzureStorageFileShare, ) graph_builder.submit_work( service_name, @@ -864,7 +870,7 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: account_id, "blobServices", "containers", - AzureBlobContainer, + AzureStorageBlobContainer, ) graph_builder.submit_work( service_name, @@ -873,7 +879,7 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: account_id, "queueServices", "queues", - AzureQueue, + AzureStorageQueue, ) graph_builder.submit_work( service_name, @@ -882,7 +888,7 @@ def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: account_id, "tableServices", "tables", - AzureTable, + AzureStorageTable, ) def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: @@ -1071,8 +1077,8 @@ class AzureTableSignedIdentifier: @define(eq=False, slots=False) -class AzureTable(MicrosoftResource): - kind: ClassVar[str] = "azure_table" +class AzureStorageTable(MicrosoftResource): + kind: ClassVar[str] = "azure_storage_table" mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), "tags": S("tags", default={}), @@ -1088,10 +1094,10 @@ class AzureTable(MicrosoftResource): resources: List[Type[MicrosoftResource]] = [ AzureStorageAccountDeleted, AzureStorageSku, - AzureFileShare, - AzureQueue, - AzureBlobContainer, - AzureTable, + AzureStorageFileShare, + AzureStorageQueue, + AzureStorageBlobContainer, + AzureStorageTable, AzureStorageAccount, AzureStorageAccountUsage, ] diff --git a/plugins/azure/fix_plugin_azure/resource/web.py b/plugins/azure/fix_plugin_azure/resource/web.py index 979d0c1c4d..78d589e869 100644 --- a/plugins/azure/fix_plugin_azure/resource/web.py +++ b/plugins/azure/fix_plugin_azure/resource/web.py @@ -14,7 +14,9 @@ GraphBuilder, parse_json, ) +from fix_plugin_azure.resource.keyvault import AzureKeyVault from fix_plugin_azure.utils import NoneIfEmpty +from fixlib.baseresources import BaseServerlessFunction, ModelReference from fixlib.json_bender import Bender, S, ForallBend, Bend, MapDict from fixlib.types import Json @@ -66,8 +68,8 @@ class AzureKubeEnvironmentProfile: @define(eq=False, slots=False) -class AzureAppServicePlan(MicrosoftResource): - kind: ClassVar[str] = "azure_app_service_plan" +class AzureWebAppServicePlan(MicrosoftResource): + kind: ClassVar[str] = "azure_web_app_service_plan" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="web", version="2023-12-01", @@ -138,8 +140,8 @@ class AzureAppServicePlan(MicrosoftResource): @define(eq=False, slots=False) -class AzureCertificate(MicrosoftResource): - kind: ClassVar[str] = "azure_certificate" +class AzureWebCertificate(MicrosoftResource): + kind: ClassVar[str] = "azure_web_certificate" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="web", version="2023-12-01", @@ -149,6 +151,14 @@ class AzureCertificate(MicrosoftResource): access_path="value", expect_array=True, ) + reference_kinds: ClassVar[ModelReference] = { + "predecessors": { + "default": [ + "azure_web_app_service_plan", + AzureKeyVault.kind, + ] + }, + } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), "tags": S("tags", default={}), @@ -203,6 +213,12 @@ class AzureCertificate(MicrosoftResource): thumbprint: Optional[str] = field(default=None, metadata={"description": "Certificate thumbprint."}) valid: Optional[bool] = field(default=None, metadata={"description": "Is the certificate valid?."}) + def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: + if server_farm_id := self.server_farm_id: + builder.add_edge(self, clazz=AzureWebAppServicePlan, reverse=True, id=server_farm_id) + if key_vault_id := self.key_vault_id: + builder.add_edge(self, clazz=AzureKeyVault, reverse=True, id=key_vault_id) + @define(eq=False, slots=False) class AzureTrafficWeight: @@ -366,8 +382,8 @@ class AzureTemplate: @define(eq=False, slots=False) -class AzureContainerApp(MicrosoftResource): - kind: ClassVar[str] = "azure_container_app" +class AzureWebContainerApp(MicrosoftResource): + kind: ClassVar[str] = "azure_web_container_app" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="web", version="2021-03-01", @@ -474,8 +490,8 @@ class AzureDomainPurchaseConsent: @define(eq=False, slots=False) -class AzureDomain(MicrosoftResource): - kind: ClassVar[str] = "azure_domain" +class AzureWebDomain(MicrosoftResource): + kind: ClassVar[str] = "azure_web_domain" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="web", version="2023-12-01", @@ -614,8 +630,8 @@ class AzureNetworkAccessControlEntry: @define(eq=False, slots=False) -class AzureHostingEnvironment(MicrosoftResource): - kind: ClassVar[str] = "azure_hosting_environment" +class AzureWebHostingEnvironment(MicrosoftResource): + kind: ClassVar[str] = "azure_web_hosting_environment" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="web", version="2015-08-01", @@ -755,8 +771,8 @@ class AzureContainerAppsConfiguration: @define(eq=False, slots=False) -class AzureKubeEnvironment(MicrosoftResource): - kind: ClassVar[str] = "azure_kube_environment" +class AzureWebKubeEnvironment(MicrosoftResource): + kind: ClassVar[str] = "azure_web_kube_environment" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="web", version="2023-12-01", @@ -1000,8 +1016,8 @@ class AzureIpSecurityRestriction: @define(eq=False, slots=False) -class AzureAzureStorageInfoValue: - kind: ClassVar[str] = "azure_azure_storage_info_value" +class AzureStorageInfoValue: + kind: ClassVar[str] = "azure_storage_info_value" mapping: ClassVar[Dict[str, Bender]] = { "access_key": S("accessKey"), "account_name": S("accountName"), @@ -1106,7 +1122,7 @@ class AzureSiteConfig: app_settings: Optional[Json] = field(default=None, metadata={"description": "Application settings."}) auto_heal_enabled: Optional[bool] = field(default=None, metadata={'description': 'true if Auto Heal is enabled; otherwise, false.'}) # fmt: skip auto_swap_slot_name: Optional[str] = field(default=None, metadata={"description": "Auto-swap slot name."}) - azure_storage_accounts: Optional[Dict[str, AzureAzureStorageInfoValue]] = field(default=None, metadata={'description': 'List of Azure Storage Accounts.'}) # fmt: skip + azure_storage_accounts: Optional[Dict[str, AzureStorageInfoValue]] = field(default=None, metadata={'description': 'List of Azure Storage Accounts.'}) # fmt: skip connection_strings: Optional[List[AzureConnStringInfo]] = field(default=None, metadata={'description': 'Connection strings.'}) # fmt: skip cors: Optional[AzureCorsSettings] = field(default=None, metadata={'description': 'Cross-Origin Resource Sharing (CORS) settings for the app.'}) # fmt: skip default_documents: Optional[List[str]] = field(default=None, metadata={"description": "Default documents."}) @@ -1352,7 +1368,7 @@ class AzureWebAppAuthSettings: @define(eq=False, slots=False) -class AzureWebApp(MicrosoftResource): +class AzureWebApp(MicrosoftResource, BaseServerlessFunction): kind: ClassVar[str] = "azure_web_app" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="web", @@ -1363,6 +1379,13 @@ class AzureWebApp(MicrosoftResource): access_path="value", expect_array=True, ) + reference_kinds: ClassVar[ModelReference] = { + "successors": { + "default": [ + "azure_web_app_service_plan", + ] + }, + } mapping: ClassVar[Dict[str, Bender]] = { "id": S("id"), "tags": S("tags", default={}), @@ -1500,6 +1523,10 @@ def auth_settings() -> None: graph_builder.submit_work(service_name, auth_settings) + def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: + if server_farm_id := self.server_farm_id: + builder.add_edge(self, clazz=AzureWebAppServicePlan, id=server_farm_id) + @define(eq=False, slots=False) class AzureStaticSiteBuildProperties: @@ -1597,8 +1624,8 @@ class AzureDatabaseConnectionOverview: @define(eq=False, slots=False) -class AzureAppStaticSite(MicrosoftResource): - kind: ClassVar[str] = "azure_app_static_site" +class AzureWebAppStaticSite(MicrosoftResource): + kind: ClassVar[str] = "azure_web_app_static_site" api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec( service="web", version="2023-12-01", @@ -1662,12 +1689,12 @@ class AzureAppStaticSite(MicrosoftResource): resources: List[Type[MicrosoftResource]] = [ - AzureAppServicePlan, + AzureWebAppServicePlan, AzureWebApp, - AzureAppStaticSite, - AzureCertificate, - AzureContainerApp, - AzureDomain, - AzureHostingEnvironment, - AzureKubeEnvironment, + AzureWebAppStaticSite, + AzureWebCertificate, + AzureWebContainerApp, + AzureWebDomain, + AzureWebHostingEnvironment, + AzureWebKubeEnvironment, ] diff --git a/plugins/azure/test/authorization_test.py b/plugins/azure/test/authorization_test.py index eec948efaf..e7ba651062 100644 --- a/plugins/azure/test/authorization_test.py +++ b/plugins/azure/test/authorization_test.py @@ -1,10 +1,14 @@ from conftest import roundtrip_check -from fix_plugin_azure.resource.authorization import AzureRoleAssignment, AzureRoleDefinition, AzureDenyAssignment +from fix_plugin_azure.resource.authorization import ( + AzureAuthorizationRoleAssignment, + AzureAuthorizationRoleDefinition, + AzureAuthorizationDenyAssignment, +) from fix_plugin_azure.resource.base import GraphBuilder def test_role_assignment(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureRoleAssignment, builder) + collected = roundtrip_check(AzureAuthorizationRoleAssignment, builder) assert len(collected) == 3 for c in collected: c.connect_in_graph(builder, {}) @@ -12,10 +16,10 @@ def test_role_assignment(builder: GraphBuilder) -> None: def test_role_definition(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureRoleDefinition, builder) + collected = roundtrip_check(AzureAuthorizationRoleDefinition, builder) assert len(collected) == 2 def test_deny_assignment(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureDenyAssignment, builder) + collected = roundtrip_check(AzureAuthorizationDenyAssignment, builder) assert len(collected) == 1 diff --git a/plugins/azure/test/collector_test.py b/plugins/azure/test/collector_test.py index b261b88fe0..3b8c1ffa2a 100644 --- a/plugins/azure/test/collector_test.py +++ b/plugins/azure/test/collector_test.py @@ -11,11 +11,11 @@ from fix_plugin_azure.config import AzureCredentials, AzureConfig from fix_plugin_azure.resource.base import MicrosoftResource, AzureSubscription, GraphBuilder from fix_plugin_azure.resource.compute import ( - AzureDiskTypePricing, - AzureVirtualMachine, - AzureVirtualMachineSize, - AzureDisk, - AzureDiskType, + AzureComputeDiskTypePricing, + AzureComputeVirtualMachine, + AzureComputeVirtualMachineSize, + AzureComputeDisk, + AzureComputeDiskType, ) from fixlib.baseresources import Cloud from fixlib.core.actions import CoreFeedback @@ -48,8 +48,8 @@ def test_collect( config, Cloud(id="azure"), azure_subscription, credentials, core_feedback ) subscription_collector.collect() - assert len(subscription_collector.graph.nodes) == 646 - assert len(subscription_collector.graph.edges) == 1038 + assert len(subscription_collector.graph.nodes) == 645 + assert len(subscription_collector.graph.edges) == 1034 graph_collector = MicrosoftGraphOrganizationCollector( config, Cloud(id="azure"), MicrosoftGraphOrganization(id="test", name="test"), credentials, core_feedback @@ -62,49 +62,51 @@ def test_collect( def test_filter(credentials: AzureCredentials, builder: GraphBuilder) -> None: with open(os.path.dirname(__file__) + "/files/compute/vmSizes.json") as f: - AzureVirtualMachineSize.collect(raw=json.load(f)["value"], builder=builder) + AzureComputeVirtualMachineSize.collect(raw=json.load(f)["value"], builder=builder) with open(os.path.dirname(__file__) + "/files/compute/virtualMachines.json") as f: - AzureVirtualMachine.collect(raw=json.load(f)["value"], builder=builder) + AzureComputeVirtualMachine.collect(raw=json.load(f)["value"], builder=builder) with open(os.path.dirname(__file__) + "/files/compute/calculator.json") as f: - AzureDiskTypePricing.collect(raw=json.load(f), builder=builder) + AzureComputeDiskTypePricing.collect(raw=json.load(f), builder=builder) collector = collector_with_graph(builder.graph, credentials) - num_all_virtual_machine_types = list(collector.graph.search("kind", "azure_virtual_machine_size")) + num_all_virtual_machine_types = list(collector.graph.search("kind", "azure_compute_virtual_machine_size")) collector.remove_unused() - assert len(list(collector.graph.search("kind", "azure_virtual_machine_size"))) < len(num_all_virtual_machine_types) + assert len(list(collector.graph.search("kind", "azure_compute_virtual_machine_size"))) < len( + num_all_virtual_machine_types + ) - pricing_info = list(collector.graph.search("kind", "azure_disk_type_pricing")) + pricing_info = list(collector.graph.search("kind", "azure_compute_disk_type_pricing")) assert len(pricing_info) > 0 collector.after_collect() - assert len(list(collector.graph.search("kind", "azure_disk_type_pricing"))) < len(pricing_info) + assert len(list(collector.graph.search("kind", "azure_compute_disk_type_pricing"))) < len(pricing_info) def test_collect_cost(credentials: AzureCredentials, builder: GraphBuilder) -> None: with open(os.path.dirname(__file__) + "/files/compute/vmSizes.json") as f: - AzureVirtualMachineSize.collect(raw=json.load(f)["value"], builder=builder) + AzureComputeVirtualMachineSize.collect(raw=json.load(f)["value"], builder=builder) with open(os.path.dirname(__file__) + "/files/compute/virtualMachines.json") as f: - AzureVirtualMachine.collect(raw=json.load(f)["value"], builder=builder) + AzureComputeVirtualMachine.collect(raw=json.load(f)["value"], builder=builder) with open(os.path.dirname(__file__) + "/files/compute/prices.json") as f: - AzureDiskType.collect(raw=json.load(f)["Items"], builder=builder) + AzureComputeDiskType.collect(raw=json.load(f)["Items"], builder=builder) with open(os.path.dirname(__file__) + "/files/compute/disks.json") as f: - AzureDisk.collect(raw=json.load(f)["value"], builder=builder) + AzureComputeDisk.collect(raw=json.load(f)["value"], builder=builder) collector = collector_with_graph(builder.graph, credentials) resource_types: List[Type[MicrosoftResource]] = [ - AzureVirtualMachine, - AzureDisk, + AzureComputeVirtualMachine, + AzureComputeDisk, ] connect_resources(builder, resource_types) for node, data in list(collector.graph.nodes(data=True)): - if isinstance(node, AzureVirtualMachineSize): + if isinstance(node, AzureComputeVirtualMachineSize): node.after_collect(builder, data.get("source", {})) - assert list(collector.graph.search("kind", "azure_virtual_machine_size"))[12].ondemand_cost == 13.14 # type: ignore[attr-defined] - assert list(collector.graph.search("kind", "azure_disk_type"))[2].ondemand_cost == 0.3640833333333333 # type: ignore[attr-defined] + assert list(collector.graph.search("kind", "azure_compute_virtual_machine_size"))[12].ondemand_cost == 13.14 # type: ignore[attr-defined] + assert list(collector.graph.search("kind", "azure_compute_disk_type"))[2].ondemand_cost == 0.3640833333333333 # type: ignore[attr-defined] diff --git a/plugins/azure/test/compute_test.py b/plugins/azure/test/compute_test.py index 07c54ea8da..bf085444da 100644 --- a/plugins/azure/test/compute_test.py +++ b/plugins/azure/test/compute_test.py @@ -2,7 +2,7 @@ from fix_plugin_azure.resource.base import GraphBuilder, MicrosoftResource from fix_plugin_azure.resource.compute import * from fix_plugin_azure.resource.network import ( - AzureLoadBalancer, + AzureNetworkLoadBalancer, AzureNetworkInterface, AzureNetworkSecurityGroup, ) @@ -11,45 +11,44 @@ def test_availability_sets(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureAvailabilitySet, builder) + collected = roundtrip_check(AzureComputeAvailabilitySet, builder) assert len(collected) == 4 - resource_types: List[Type[MicrosoftResource]] = [AzureProximityPlacementGroup, AzureVirtualMachine] + resource_types: List[Type[MicrosoftResource]] = [AzureComputeProximityPlacementGroup, AzureComputeVirtualMachine] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureAvailabilitySet, AzureProximityPlacementGroup)) == 2 - assert len(builder.edges_of(AzureAvailabilitySet, AzureVirtualMachine)) == 2 + assert len(builder.edges_of(AzureComputeAvailabilitySet, AzureComputeProximityPlacementGroup)) == 2 + assert len(builder.edges_of(AzureComputeAvailabilitySet, AzureComputeVirtualMachine)) == 2 def test_capacity_reservation_group(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureCapacityReservationGroup, builder) + collected = roundtrip_check(AzureComputeCapacityReservationGroup, builder) assert len(collected) == 2 - resource_type: List[Type[MicrosoftResource]] = [AzureVirtualMachine] + resource_type: List[Type[MicrosoftResource]] = [AzureComputeVirtualMachine] connect_resources(builder, resource_type) - assert len(builder.edges_of(AzureCapacityReservationGroup, AzureVirtualMachine)) == 2 + assert len(builder.edges_of(AzureComputeCapacityReservationGroup, AzureComputeVirtualMachine)) == 2 def test_cloud_service(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureCloudService, builder) + collected = roundtrip_check(AzureComputeCloudService, builder) assert len(collected) == 1 def test_dedicated_host_group(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureDedicatedHostGroup, builder) + collected = roundtrip_check(AzureComputeDedicatedHostGroup, builder) assert len(collected) == 1 def test_disks(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureDisk, builder, all_props=True, ignore_props={"etag"}) + collected = roundtrip_check(AzureComputeDisk, builder, all_props=True, ignore_props={"etag"}) assert len(collected) == 3 - resource_types: List[Type[MicrosoftResource]] = [AzureDiskAccess, AzureDiskEncryptionSet] + resource_types: List[Type[MicrosoftResource]] = [AzureComputeDiskEncryptionSet] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureDiskAccess, AzureDisk)) == 2 - assert len(builder.edges_of(AzureDisk, AzureDiskEncryptionSet)) == 2 + assert len(builder.edges_of(AzureComputeDisk, AzureComputeDiskEncryptionSet)) == 2 first = collected[0] assert first.volume_size == 200 @@ -61,104 +60,104 @@ def test_disks(builder: GraphBuilder) -> None: def test_disk_access(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureDiskAccess, builder) + collected = roundtrip_check(AzureComputeDiskAccess, builder) assert len(collected) == 2 def test_disk_encryption_set(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureDiskEncryptionSet, builder) + collected = roundtrip_check(AzureComputeDiskEncryptionSet, builder) assert len(collected) == 2 def test_gallery(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureGallery, builder) + collected = roundtrip_check(AzureComputeGallery, builder) assert len(collected) == 1 def test_image(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureImage, builder) + collected = roundtrip_check(AzureComputeImage, builder) assert len(collected) == 1 def test_placement_group(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureProximityPlacementGroup, builder) + collected = roundtrip_check(AzureComputeProximityPlacementGroup, builder) assert len(collected) == 1 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualMachineScaleSet] + resource_types: List[Type[MicrosoftResource]] = [AzureComputeVirtualMachineScaleSet] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureProximityPlacementGroup, AzureVirtualMachineScaleSet)) == 1 + assert len(builder.edges_of(AzureComputeProximityPlacementGroup, AzureComputeVirtualMachineScaleSet)) == 1 def test_restore_point_collection(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureRestorePointCollection, builder) + collected = roundtrip_check(AzureComputeRestorePointCollection, builder) assert len(collected) == 2 - resource_type: List[Type[MicrosoftResource]] = [AzureVirtualMachine] + resource_type: List[Type[MicrosoftResource]] = [AzureComputeVirtualMachine] connect_resources(builder, resource_type) - assert len(builder.edges_of(AzureRestorePointCollection, AzureVirtualMachine)) == 2 + assert len(builder.edges_of(AzureComputeRestorePointCollection, AzureComputeVirtualMachine)) == 2 def test_ssh_key(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureSshPublicKeyResource, builder) + collected = roundtrip_check(AzureComputeSshPublicKey, builder) assert len(collected) == 1 def test_virtual_machine(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualMachine, builder) + collected = roundtrip_check(AzureComputeVirtualMachine, builder) assert len(collected) == 2 resource_types: List[Type[MicrosoftResource]] = [ - AzureProximityPlacementGroup, - AzureImage, - AzureDisk, + AzureComputeProximityPlacementGroup, + AzureComputeImage, + AzureComputeDisk, AzureNetworkInterface, AzureNetworkSecurityGroup, - AzureLoadBalancer, - AzureVirtualMachineSize, + AzureNetworkLoadBalancer, + AzureComputeVirtualMachineSize, ] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureProximityPlacementGroup, AzureVirtualMachine)) == 2 - assert len(builder.edges_of(AzureVirtualMachine, AzureImage)) == 2 - assert len(builder.edges_of(AzureVirtualMachine, AzureDisk)) == 2 - assert len(builder.edges_of(AzureVirtualMachine, AzureNetworkInterface)) == 1 - assert len(builder.edges_of(AzureNetworkSecurityGroup, AzureVirtualMachine)) == 1 - assert len(builder.edges_of(AzureLoadBalancer, AzureVirtualMachine)) == 1 - assert len(builder.edges_of(AzureVirtualMachine, AzureVirtualMachineSize)) == 2 + assert len(builder.edges_of(AzureComputeProximityPlacementGroup, AzureComputeVirtualMachine)) == 2 + assert len(builder.edges_of(AzureComputeVirtualMachine, AzureComputeImage)) == 2 + assert len(builder.edges_of(AzureComputeVirtualMachine, AzureComputeDisk)) == 2 + assert len(builder.edges_of(AzureComputeVirtualMachine, AzureNetworkInterface)) == 1 + assert len(builder.edges_of(AzureNetworkSecurityGroup, AzureComputeVirtualMachine)) == 1 + assert len(builder.edges_of(AzureNetworkLoadBalancer, AzureComputeVirtualMachine)) == 1 + assert len(builder.edges_of(AzureComputeVirtualMachine, AzureComputeVirtualMachineSize)) == 2 def test_virtual_machine_resources(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualMachine, builder)[0] + collected = roundtrip_check(AzureComputeVirtualMachine, builder)[0] assert collected.instance_type == "Standard_A1_V2" assert collected.instance_status == InstanceStatus.RUNNING def test_virtual_machine_scale_set(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualMachineScaleSet, builder) + collected = roundtrip_check(AzureComputeVirtualMachineScaleSet, builder) assert len(collected) == 1 resource_types: List[Type[MicrosoftResource]] = [ - AzureLoadBalancer, + AzureNetworkLoadBalancer, ] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureLoadBalancer, AzureVirtualMachineScaleSet)) == 1 + assert len(builder.edges_of(AzureNetworkLoadBalancer, AzureComputeVirtualMachineScaleSet)) == 1 def test_snapshot(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualMachineSnapshot, builder) + collected = roundtrip_check(AzureComputeVirtualMachineSnapshot, builder) assert len(collected) == 2 - resource_type: List[Type[MicrosoftResource]] = [AzureDisk] + resource_type: List[Type[MicrosoftResource]] = [AzureComputeDisk] connect_resources(builder, resource_type) - assert len(builder.edges_of(AzureDisk, AzureVirtualMachineSnapshot)) == 1 + assert len(builder.edges_of(AzureComputeDisk, AzureComputeVirtualMachineSnapshot)) == 1 def test_snapshot_resources(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualMachineSnapshot, builder)[1] + collected = roundtrip_check(AzureComputeVirtualMachineSnapshot, builder)[1] assert collected.snapshot_status == "None" assert ( collected.volume_id diff --git a/plugins/azure/test/containerservice_test.py b/plugins/azure/test/containerservice_test.py index 736b4a88a2..2628600fef 100644 --- a/plugins/azure/test/containerservice_test.py +++ b/plugins/azure/test/containerservice_test.py @@ -1,37 +1,41 @@ from conftest import roundtrip_check, connect_resources from fix_plugin_azure.resource.base import GraphBuilder, MicrosoftResource -from fix_plugin_azure.resource.containerservice import AzureFleet, AzureManagedCluster, AzureManagedClusterSnapshot -from fix_plugin_azure.resource.compute import AzureDiskEncryptionSet, AzureVirtualMachineScaleSet +from fix_plugin_azure.resource.containerservice import ( + AzureContainerServiceFleet, + AzureContainerServiceManagedCluster, + AzureContainerServiceManagedClusterSnapshot, +) +from fix_plugin_azure.resource.compute import AzureComputeDiskEncryptionSet, AzureComputeVirtualMachineScaleSet from typing import List, Type def test_fleet(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureFleet, builder) + collected = roundtrip_check(AzureContainerServiceFleet, builder) assert len(collected) == 1 - resource_types: List[Type[MicrosoftResource]] = [AzureManagedCluster] - roundtrip_check(AzureManagedCluster, builder) + resource_types: List[Type[MicrosoftResource]] = [AzureContainerServiceManagedCluster] + roundtrip_check(AzureContainerServiceManagedCluster, builder) connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureFleet, AzureManagedCluster)) == 1 + assert len(builder.edges_of(AzureContainerServiceFleet, AzureContainerServiceManagedCluster)) == 1 def test_managed_cluster(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureManagedCluster, builder) + collected = roundtrip_check(AzureContainerServiceManagedCluster, builder) assert len(collected) == 1 - resource_types: List[Type[MicrosoftResource]] = [AzureDiskEncryptionSet, AzureVirtualMachineScaleSet] + resource_types: List[Type[MicrosoftResource]] = [AzureComputeDiskEncryptionSet, AzureComputeVirtualMachineScaleSet] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureManagedCluster, AzureDiskEncryptionSet)) == 1 - assert len(builder.edges_of(AzureManagedCluster, AzureVirtualMachineScaleSet)) == 1 + assert len(builder.edges_of(AzureContainerServiceManagedCluster, AzureComputeDiskEncryptionSet)) == 1 + assert len(builder.edges_of(AzureContainerServiceManagedCluster, AzureComputeVirtualMachineScaleSet)) == 1 def test_kub_snapshot(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureManagedClusterSnapshot, builder) + collected = roundtrip_check(AzureContainerServiceManagedClusterSnapshot, builder) assert len(collected) == 1 - resource_types: List[Type[MicrosoftResource]] = [AzureManagedCluster] + resource_types: List[Type[MicrosoftResource]] = [AzureContainerServiceManagedCluster] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureManagedCluster, AzureManagedClusterSnapshot)) == 1 + assert len(builder.edges_of(AzureContainerServiceManagedCluster, AzureContainerServiceManagedClusterSnapshot)) == 1 diff --git a/plugins/azure/test/files/network/networkSecurityGroups.json b/plugins/azure/test/files/network/networkSecurityGroups.json index 795d33bd98..c8ac660a25 100644 --- a/plugins/azure/test/files/network/networkSecurityGroups.json +++ b/plugins/azure/test/files/network/networkSecurityGroups.json @@ -34,7 +34,7 @@ "protocol": "*", "sourcePortRange": "*", "destinationPortRange": "*", - "sourceAddressPrefix": "AzureLoadBalancer", + "sourceAddressPrefix": "AzureNetworkLoadBalancer", "destinationAddressPrefix": "*", "access": "Allow", "priority": 65001, @@ -142,7 +142,7 @@ "protocol": "*", "sourcePortRange": "*", "destinationPortRange": "*", - "sourceAddressPrefix": "AzureLoadBalancer", + "sourceAddressPrefix": "AzureNetworkLoadBalancer", "destinationAddressPrefix": "*", "access": "Allow", "priority": 65001, diff --git a/plugins/azure/test/keyvault_test.py b/plugins/azure/test/keyvault_test.py index f99dec65a6..e4abe3e8fd 100644 --- a/plugins/azure/test/keyvault_test.py +++ b/plugins/azure/test/keyvault_test.py @@ -1,6 +1,6 @@ from conftest import roundtrip_check from fix_plugin_azure.resource.base import GraphBuilder -from fix_plugin_azure.resource.keyvault import AzureKeyVault, AzureManagedHsm, AzureKey +from fix_plugin_azure.resource.keyvault import AzureKeyVault, AzureKeyVaultManagedHsm, AzureKeyVaultKey def test_key_vault(builder: GraphBuilder) -> None: @@ -8,9 +8,9 @@ def test_key_vault(builder: GraphBuilder) -> None: assert len(collected) == 1 collected[0].post_process(builder, {}) builder.executor.wait_for_submitted_work() - assert len(builder.nodes(AzureKey)) == 4 + assert len(builder.nodes(AzureKeyVaultKey)) == 4 def test_hsm(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureManagedHsm, builder) + collected = roundtrip_check(AzureKeyVaultManagedHsm, builder) assert len(collected) == 2 diff --git a/plugins/azure/test/monitor_test.py b/plugins/azure/test/monitor_test.py index 40f0bc3df6..abae514e80 100644 --- a/plugins/azure/test/monitor_test.py +++ b/plugins/azure/test/monitor_test.py @@ -2,7 +2,7 @@ from fix_plugin_azure.resource.base import GraphBuilder from fix_plugin_azure.resource.monitor import ( AzureMonitorActionGroup, - AzureActivityLogAlert, + AzureMonitorActivityLogAlert, AzureMonitorAlertRule, AzureMonitorLogProfile, AzureMetricAlert, @@ -21,7 +21,7 @@ def test_action_groups(builder: GraphBuilder) -> None: def test_activity_log_alert(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureActivityLogAlert, builder) + collected = roundtrip_check(AzureMonitorActivityLogAlert, builder) assert len(collected) == 2 diff --git a/plugins/azure/test/network_test.py b/plugins/azure/test/network_test.py index 7aec480d0f..07f3483e45 100644 --- a/plugins/azure/test/network_test.py +++ b/plugins/azure/test/network_test.py @@ -1,129 +1,132 @@ from conftest import roundtrip_check, connect_resources from fix_plugin_azure.resource.base import GraphBuilder, MicrosoftResource -from fix_plugin_azure.resource.containerservice import AzureManagedCluster +from fix_plugin_azure.resource.containerservice import AzureContainerServiceManagedCluster from fix_plugin_azure.resource.network import * from typing import List, Type def test_application_gateway_available_waf_rule_set(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureApplicationGatewayFirewallRuleSet, builder) + collected = roundtrip_check(AzureNetworkApplicationGatewayFirewallRuleSet, builder) assert len(collected) == 1 def test_application_gateway(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureApplicationGateway, builder) + collected = roundtrip_check(AzureNetworkApplicationGateway, builder) assert len(collected) == 1 - resource_types: List[Type[MicrosoftResource]] = [AzureWebApplicationFirewallPolicy] + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkWebApplicationFirewallPolicy] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureApplicationGateway, AzureWebApplicationFirewallPolicy)) == 1 + assert len(builder.edges_of(AzureNetworkApplicationGateway, AzureNetworkWebApplicationFirewallPolicy)) == 1 def test_application_gateway_web_application_firewall_policy(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureWebApplicationFirewallPolicy, builder) + collected = roundtrip_check(AzureNetworkWebApplicationFirewallPolicy, builder) assert len(collected) == 1 def test_azure_firewall(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureFirewall, builder) + collected = roundtrip_check(AzureNetworkFirewall, builder) assert len(collected) == 1 - resource_types: List[Type[MicrosoftResource]] = [AzureFirewallPolicy, AzureVirtualHub] + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkFirewallPolicy, AzureNetworkVirtualHub] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureFirewall, AzureFirewallPolicy)) == 1 - assert len(builder.edges_of(AzureFirewall, AzureVirtualHub)) == 1 + assert len(builder.edges_of(AzureNetworkFirewall, AzureNetworkFirewallPolicy)) == 1 + assert len(builder.edges_of(AzureNetworkFirewall, AzureNetworkVirtualHub)) == 1 def test_bastion_host(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureBastionHost, builder) + collected = roundtrip_check(AzureNetworkBastionHost, builder) assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualNetwork, AzurePublicIPAddress] + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkVirtualNetwork, AzureNetworkPublicIPAddress] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureVirtualNetwork, AzureBastionHost)) == 1 - assert len(builder.edges_of(AzureBastionHost, AzurePublicIPAddress)) == 1 + assert len(builder.edges_of(AzureNetworkVirtualNetwork, AzureNetworkBastionHost)) == 1 + assert len(builder.edges_of(AzureNetworkBastionHost, AzureNetworkPublicIPAddress)) == 1 def test_custom_ip_prefix(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureCustomIpPrefix, builder) + collected = roundtrip_check(AzureNetworkCustomIpPrefix, builder) assert len(collected) == 12 def test_ddos_protection_plan(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureDdosProtectionPlan, builder) + collected = roundtrip_check(AzureNetworkDdosProtectionPlan, builder) assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualNetwork, AzurePublicIPAddress] + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkVirtualNetwork, AzureNetworkPublicIPAddress] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureDdosProtectionPlan, AzureVirtualNetwork)) == 1 - assert len(builder.edges_of(AzureDdosProtectionPlan, AzurePublicIPAddress)) == 1 + assert len(builder.edges_of(AzureNetworkDdosProtectionPlan, AzureNetworkVirtualNetwork)) == 1 + assert len(builder.edges_of(AzureNetworkDdosProtectionPlan, AzureNetworkPublicIPAddress)) == 1 def test_dscp_configuration(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureDscpConfiguration, builder) + collected = roundtrip_check(AzureNetworkDscpConfiguration, builder) assert len(collected) == 2 def test_express_route_circuit(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureExpressRouteCircuit, builder) + collected = roundtrip_check(AzureNetworkExpressRouteCircuit, builder) assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureExpressRoutePort, AzureExpressRoutePortsLocation] - roundtrip_check(AzureExpressRoutePortsLocation, builder) + resource_types: List[Type[MicrosoftResource]] = [ + AzureNetworkExpressRoutePort, + AzureNetworkExpressRoutePortsLocation, + ] + roundtrip_check(AzureNetworkExpressRoutePortsLocation, builder) connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureExpressRouteCircuit, AzureExpressRoutePort)) == 1 - assert len(builder.edges_of(AzureExpressRouteCircuit, AzureExpressRoutePortsLocation)) == 1 + assert len(builder.edges_of(AzureNetworkExpressRouteCircuit, AzureNetworkExpressRoutePort)) == 1 + assert len(builder.edges_of(AzureNetworkExpressRouteCircuit, AzureNetworkExpressRoutePortsLocation)) == 1 def test_express_route_gateway(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureExpressRouteGateway, builder) + collected = roundtrip_check(AzureNetworkExpressRouteGateway, builder) assert len(collected) == 1 def test_express_route_port(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureExpressRoutePort, builder) + collected = roundtrip_check(AzureNetworkExpressRoutePort, builder) assert len(collected) == 1 def test_express_route_port_location(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureExpressRoutePortsLocation, builder) + collected = roundtrip_check(AzureNetworkExpressRoutePortsLocation, builder) assert len(collected) == 1 def test_firewall_policy(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureFirewallPolicy, builder) + collected = roundtrip_check(AzureNetworkFirewallPolicy, builder) assert len(collected) == 1 def test_ip_allocation(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureIpAllocation, builder) + collected = roundtrip_check(AzureNetworkIpAllocation, builder) assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualNetwork] + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkVirtualNetwork] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureVirtualNetwork, AzureIpAllocation)) == 1 + assert len(builder.edges_of(AzureNetworkVirtualNetwork, AzureNetworkIpAllocation)) == 1 def test_ip_group(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureIpGroup, builder) + collected = roundtrip_check(AzureNetworkIpGroup, builder) assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualNetwork] - roundtrip_check(AzureVirtualNetwork, builder) + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkVirtualNetwork] + roundtrip_check(AzureNetworkVirtualNetwork, builder) connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureVirtualNetwork, AzureIpGroup)) == 1 + assert len(builder.edges_of(AzureNetworkVirtualNetwork, AzureNetworkIpGroup)) == 1 def test_load_balancer(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureLoadBalancer, builder) + collected = roundtrip_check(AzureNetworkLoadBalancer, builder) assert collected[0].lb_type == "Microsoft.Network/loadBalancers" assert collected[0].backends == [ "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/vnet1", @@ -131,28 +134,32 @@ def test_load_balancer(builder: GraphBuilder) -> None: ] assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualNetwork, AzureManagedCluster, AzureLoadBalancerProbe] - roundtrip_check(AzurePublicIPAddress, builder) + resource_types: List[Type[MicrosoftResource]] = [ + AzureNetworkVirtualNetwork, + AzureContainerServiceManagedCluster, + AzureNetworkLoadBalancerProbe, + ] + roundtrip_check(AzureNetworkPublicIPAddress, builder) connect_resources(builder, resource_types) assert collected[0].aks_public_ip_address == "41.85.154.247" - assert len(builder.edges_of(AzureVirtualNetwork, AzureLoadBalancer)) == 1 - assert len(builder.edges_of(AzureManagedCluster, AzureLoadBalancer)) == 1 - assert len(builder.edges_of(AzureLoadBalancer, AzureLoadBalancerProbe)) == 2 + assert len(builder.edges_of(AzureNetworkVirtualNetwork, AzureNetworkLoadBalancer)) == 1 + assert len(builder.edges_of(AzureContainerServiceManagedCluster, AzureNetworkLoadBalancer)) == 1 + assert len(builder.edges_of(AzureNetworkLoadBalancer, AzureNetworkLoadBalancerProbe)) == 2 def test_network_profile(builder: GraphBuilder) -> None: - from fix_plugin_azure.resource.compute import AzureVirtualMachine # pylint: disable=import-outside-toplevel + from fix_plugin_azure.resource.compute import AzureComputeVirtualMachine # pylint: disable=import-outside-toplevel collected = roundtrip_check(AzureNetworkProfile, builder) assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualMachine] + resource_types: List[Type[MicrosoftResource]] = [AzureComputeVirtualMachine] roundtrip_check(AzureNetworkInterface, builder) connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureNetworkProfile, AzureVirtualMachine)) == 1 + assert len(builder.edges_of(AzureNetworkProfile, AzureComputeVirtualMachine)) == 1 def test_network_virtual_appliance(builder: GraphBuilder) -> None: @@ -175,35 +182,35 @@ def test_network_watcher(builder: GraphBuilder) -> None: collected = roundtrip_check(AzureNetworkWatcher, builder) assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualNetwork] - roundtrip_check(AzureVirtualNetwork, builder) + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkVirtualNetwork] + roundtrip_check(AzureNetworkVirtualNetwork, builder) connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureVirtualNetwork, AzureNetworkWatcher)) == 2 + assert len(builder.edges_of(AzureNetworkVirtualNetwork, AzureNetworkWatcher)) == 2 def test_p2s_vpn_gateway(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureP2SVpnGateway, builder) + collected = roundtrip_check(AzureNetworkP2SVpnGateway, builder) assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualHub] + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkVirtualHub] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureP2SVpnGateway, AzureVirtualHub)) == 2 + assert len(builder.edges_of(AzureNetworkP2SVpnGateway, AzureNetworkVirtualHub)) == 2 def test_public_ip_prefix(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzurePublicIPPrefix, builder) + collected = roundtrip_check(AzureNetworkPublicIPPrefix, builder) assert len(collected) == 3 def test_route_filter(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureRouteFilter, builder) + collected = roundtrip_check(AzureNetworkRouteFilter, builder) assert len(collected) == 1 def test_security_partner_provider(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureSecurityPartnerProvider, builder) + collected = roundtrip_check(AzureNetworkSecurityPartnerProvider, builder) assert len(collected) == 1 @@ -213,68 +220,68 @@ def test_usage(builder: GraphBuilder) -> None: def test_virtual_hub(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualHub, builder) + collected = roundtrip_check(AzureNetworkVirtualHub, builder) assert len(collected) == 2 resource_types: List[Type[MicrosoftResource]] = [ - AzureExpressRouteGateway, - AzureVirtualWANVpnGateway, - AzureVirtualWAN, - AzurePublicIPAddress, + AzureNetworkExpressRouteGateway, + AzureNetworkVirtualWANVpnGateway, + AzureNetworkVirtualWAN, + AzureNetworkPublicIPAddress, ] roundtrip_check(AzureNetworkInterface, builder) connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureExpressRouteGateway, AzureVirtualHub)) == 1 - assert len(builder.edges_of(AzureVirtualWANVpnGateway, AzureVirtualHub)) == 1 - assert len(builder.edges_of(AzureVirtualWAN, AzureVirtualHub)) == 1 - assert len(builder.edges_of(AzureVirtualHub, AzurePublicIPAddress)) == 1 + assert len(builder.edges_of(AzureNetworkExpressRouteGateway, AzureNetworkVirtualHub)) == 1 + assert len(builder.edges_of(AzureNetworkVirtualWANVpnGateway, AzureNetworkVirtualHub)) == 1 + assert len(builder.edges_of(AzureNetworkVirtualWAN, AzureNetworkVirtualHub)) == 1 + assert len(builder.edges_of(AzureNetworkVirtualHub, AzureNetworkPublicIPAddress)) == 1 def test_virtual_network(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualNetwork, builder) + collected = roundtrip_check(AzureNetworkVirtualNetwork, builder) assert len(collected) == 2 def test_virtual_router(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualRouter, builder) + collected = roundtrip_check(AzureNetworkVirtualRouter, builder) assert len(collected) == 1 def test_virtual_wan(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualWAN, builder) + collected = roundtrip_check(AzureNetworkVirtualWAN, builder) assert len(collected) == 2 def test_vpn_gateway(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualWANVpnGateway, builder) + collected = roundtrip_check(AzureNetworkVirtualWANVpnGateway, builder) assert len(collected) == 2 resource_types: List[Type[MicrosoftResource]] = [ - AzureVirtualWANVpnConnection, + AzureNetworkVirtualWANVpnConnection, ] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureVirtualWANVpnGateway, AzureVirtualWANVpnConnection)) == 2 + assert len(builder.edges_of(AzureNetworkVirtualWANVpnGateway, AzureNetworkVirtualWANVpnConnection)) == 2 def test_vpn_server_configuration(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVpnServerConfiguration, builder) + collected = roundtrip_check(AzureNetworkVpnServerConfiguration, builder) assert len(collected) == 2 def test_vpn_site(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVpnSite, builder) + collected = roundtrip_check(AzureNetworkVpnSite, builder) assert len(collected) == 2 - resource_types: List[Type[MicrosoftResource]] = [AzureVirtualWAN] + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkVirtualWAN] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureVirtualWAN, AzureVpnSite)) == 1 + assert len(builder.edges_of(AzureNetworkVirtualWAN, AzureNetworkVpnSite)) == 1 def test_nat_gateway(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureNatGateway, builder) + collected = roundtrip_check(AzureNetworkNatGateway, builder) assert len(collected) == 2 @@ -283,17 +290,17 @@ def test_network_interface(builder: GraphBuilder) -> None: assert len(collected) == 2 resource_types: List[Type[MicrosoftResource]] = [ - AzureVirtualNetworkTap, - AzureDscpConfiguration, + AzureNetworkVirtualNetworkTap, + AzureNetworkDscpConfiguration, AzureNetworkSecurityGroup, - AzurePrivateLinkService, + AzureNetworkPrivateLinkService, ] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureVirtualNetworkTap, AzureNetworkInterface)) == 1 - assert len(builder.edges_of(AzurePrivateLinkService, AzureNetworkInterface)) == 1 + assert len(builder.edges_of(AzureNetworkVirtualNetworkTap, AzureNetworkInterface)) == 1 + assert len(builder.edges_of(AzureNetworkPrivateLinkService, AzureNetworkInterface)) == 1 assert len(builder.edges_of(AzureNetworkSecurityGroup, AzureNetworkInterface)) == 1 - assert len(builder.edges_of(AzureNetworkInterface, AzureDscpConfiguration)) == 1 + assert len(builder.edges_of(AzureNetworkInterface, AzureNetworkDscpConfiguration)) == 1 def test_network_security_group(builder: GraphBuilder) -> None: @@ -302,21 +309,21 @@ def test_network_security_group(builder: GraphBuilder) -> None: def test_private_link_service(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzurePrivateLinkService, builder) + collected = roundtrip_check(AzureNetworkPrivateLinkService, builder) assert len(collected) == 2 def test_public_ip_address(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzurePublicIPAddress, builder) + collected = roundtrip_check(AzureNetworkPublicIPAddress, builder) assert len(collected) == 3 - resource_types: List[Type[MicrosoftResource]] = [AzureNatGateway, AzurePublicIPPrefix] + resource_types: List[Type[MicrosoftResource]] = [AzureNetworkNatGateway, AzureNetworkPublicIPPrefix] connect_resources(builder, resource_types) - assert len(builder.edges_of(AzureNatGateway, AzurePublicIPAddress)) == 1 - assert len(builder.edges_of(AzurePublicIPPrefix, AzurePublicIPAddress)) == 1 + assert len(builder.edges_of(AzureNetworkNatGateway, AzureNetworkPublicIPAddress)) == 1 + assert len(builder.edges_of(AzureNetworkPublicIPPrefix, AzureNetworkPublicIPAddress)) == 1 def test_virtual_network_tap(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureVirtualNetworkTap, builder) + collected = roundtrip_check(AzureNetworkVirtualNetworkTap, builder) assert len(collected) == 2 diff --git a/plugins/azure/test/security_test.py b/plugins/azure/test/security_test.py index f6f0c79ef3..73c84bdf50 100644 --- a/plugins/azure/test/security_test.py +++ b/plugins/azure/test/security_test.py @@ -5,7 +5,7 @@ AzureSecurityPricing, AzureSecurityServerVulnerabilityAssessmentsSetting, AzureSecuritySetting, - AzureAutoProvisioningSetting, + AzureSecurityAutoProvisioningSetting, ) @@ -30,7 +30,7 @@ def test_security_setting(builder: GraphBuilder) -> None: def test_auto_provisioning_setting(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureAutoProvisioningSetting, builder) + collected = roundtrip_check(AzureSecurityAutoProvisioningSetting, builder) assert len(collected) == 2 assert collected[0].auto_provision assert not collected[1].auto_provision diff --git a/plugins/azure/test/web_test.py b/plugins/azure/test/web_test.py index c5cdd81d8b..878d1055b6 100644 --- a/plugins/azure/test/web_test.py +++ b/plugins/azure/test/web_test.py @@ -1,19 +1,19 @@ from conftest import roundtrip_check from fix_plugin_azure.resource.base import GraphBuilder from fix_plugin_azure.resource.web import ( - AzureAppServicePlan, + AzureWebAppServicePlan, AzureWebApp, - AzureAppStaticSite, - AzureCertificate, - AzureContainerApp, - AzureDomain, - AzureHostingEnvironment, - AzureKubeEnvironment, + AzureWebAppStaticSite, + AzureWebCertificate, + AzureWebContainerApp, + AzureWebDomain, + AzureWebHostingEnvironment, + AzureWebKubeEnvironment, ) def test_app_service_plan(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureAppServicePlan, builder) + collected = roundtrip_check(AzureWebAppServicePlan, builder) assert len(collected) == 2 @@ -26,30 +26,30 @@ def test_web_app(builder: GraphBuilder) -> None: def test_app_static_site(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureAppStaticSite, builder) + collected = roundtrip_check(AzureWebAppStaticSite, builder) assert len(collected) == 1 def test_app_certificate(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureCertificate, builder) + collected = roundtrip_check(AzureWebCertificate, builder) assert len(collected) == 2 def test_app_container_app(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureContainerApp, builder) + collected = roundtrip_check(AzureWebContainerApp, builder) assert len(collected) == 1 def test_app_domain(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureDomain, builder) + collected = roundtrip_check(AzureWebDomain, builder) assert len(collected) == 1 def test_app_hosting_environment(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureHostingEnvironment, builder) + collected = roundtrip_check(AzureWebHostingEnvironment, builder) assert len(collected) == 1 def test_app_kube_environment(builder: GraphBuilder) -> None: - collected = roundtrip_check(AzureKubeEnvironment, builder) + collected = roundtrip_check(AzureWebKubeEnvironment, builder) assert len(collected) == 2 diff --git a/plugins/k8s/fix_plugin_k8s/deferred_edges/azure.py b/plugins/k8s/fix_plugin_k8s/deferred_edges/azure.py index 51822f07aa..8cde8dd945 100644 --- a/plugins/k8s/fix_plugin_k8s/deferred_edges/azure.py +++ b/plugins/k8s/fix_plugin_k8s/deferred_edges/azure.py @@ -9,7 +9,7 @@ def link_k8s_node_to_vmss_instance(graph: Graph, resource: BaseResource) -> None vmss_vmss_instance_id = pid.replace("azure://", "", 1) graph.add_deferred_edge( BySearchCriteria( - f"is(azure_virtual_machine_scale_set_instance) and reported.id={vmss_vmss_instance_id}" + f"is(azure_compute_virtual_machine_scale_set_instance) and reported.id={vmss_vmss_instance_id}" ), ByNodeId(resource.chksum), ) @@ -18,7 +18,7 @@ def link_k8s_node_to_vmss_instance(graph: Graph, resource: BaseResource) -> None def link_k8s_cluster_to_aks_cluster(graph: Graph, resource: BaseResource) -> None: if resource.kind == "kubernetes_cluster": graph.add_deferred_edge( - BySearchCriteria(f"is(azure_managed_cluster) and reported.name={resource.id}"), + BySearchCriteria(f"is(azure_container_service_managed_cluster) and reported.name={resource.id}"), ByNodeId(resource.chksum), ) @@ -31,7 +31,7 @@ def link_service_to_azure_lb(graph: Graph, resource: BaseResource) -> None: for ingress in ingresses: if lb_ip := rgetattr(ingress, "ip", None): graph.add_deferred_edge( - BySearchCriteria(f"is(azure_load_balancer) and reported.aks_public_ip_address={lb_ip}"), + BySearchCriteria(f"is(azure_network_load_balancer) and reported.aks_public_ip_address={lb_ip}"), ByNodeId(resource.chksum), ) @@ -44,7 +44,7 @@ def link_pv_to_azure_disk(graph: Graph, resource: BaseResource) -> None: and (vol_id := csi.get("volumeHandle")) ): graph.add_deferred_edge( - BySearchCriteria(f"is(azure_disk) and reported.id={vol_id}"), ByNodeId(resource.chksum) + BySearchCriteria(f"is(azure_compute_disk) and reported.id={vol_id}"), ByNodeId(resource.chksum) )