Skip to content

Commit

Permalink
[azure][fix] Define Phantom Resources (#2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Oct 9, 2024
1 parent 8482aa6 commit 303e661
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions plugins/azure/fix_plugin_azure/resource/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
MicrosoftGraphGroup,
MicrosoftGraphPrincipalTypes,
)
from fixlib.baseresources import BaseRole, ModelReference
from fixlib.baseresources import BaseRole, ModelReference, PhantomBaseResource
from fixlib.graph import BySearchCriteria
from fixlib.json_bender import Bender, S, ForallBend, Bend
from fixlib.types import Json
Expand Down Expand Up @@ -227,7 +227,7 @@ class AzurePermission:


@define(eq=False, slots=False)
class AzureAuthorizationRoleDefinition(MicrosoftResource, BaseRole):
class AzureAuthorizationRoleDefinition(MicrosoftResource, BaseRole, PhantomBaseResource):
kind: ClassVar[str] = "azure_authorization_role_definition"
_kind_display: ClassVar[str] = "Azure Authorization Role Definition"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down
5 changes: 4 additions & 1 deletion plugins/azure/fix_plugin_azure/resource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,11 @@ class AzureUsageName:


@define(eq=False, slots=False)
class AzureBaseUsage:
class AzureBaseUsage(PhantomBaseResource):
kind: ClassVar[str] = "azure_usage"
_kind_display: ClassVar[str] = "Azure Usage"
_kind_service: ClassVar[Optional[str]] = "resources"
_kind_description: ClassVar[str] = "Azure Usage represents the usage of a resource in an Azure subscription. It provides information about the current value of the usage, the limit of usage, and the unit of measurement. Azure Usage is used to track resource consumption and enforce usage limits, helping users manage costs and optimize resource utilization." # fmt: skip
mapping: ClassVar[Dict[str, Bender]] = {
"name": S("name", "value"), # inherited by BaseResource - name already defined there
"usage_name": S("name") >> Bend(AzureUsageName.mapping),
Expand Down
4 changes: 2 additions & 2 deletions plugins/azure/fix_plugin_azure/resource/cosmosdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from fix_plugin_azure.resource.mysql import AzureServerDataEncryption
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.baseresources import BaseDatabase, DatabaseInstanceStatus, EdgeType, ModelReference, PhantomBaseResource
from fixlib.graph import BySearchCriteria
from fixlib.json_bender import F, K, Bender, S, ForallBend, Bend, MapEnum, MapValue
from fixlib.types import Json
Expand Down Expand Up @@ -2042,7 +2042,7 @@ def collect_usages(cls, account_id: str, raw: List[Json], builder: GraphBuilder)


@define(eq=False, slots=False)
class AzureCosmosDBLocation(CosmosDBLocationSetter, MicrosoftResource):
class AzureCosmosDBLocation(CosmosDBLocationSetter, MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_cosmos_db_location"
_kind_display: ClassVar[str] = "Azure Cosmos DB Location"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down
6 changes: 3 additions & 3 deletions plugins/azure/fix_plugin_azure/resource/machinelearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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, BaseAIJob, BaseAIModel
from fixlib.baseresources import BaseInstanceType, ModelReference, BaseAIJob, BaseAIModel, PhantomBaseResource
from fixlib.graph import BySearchCriteria
from fixlib.json_bender import Bender, S, ForallBend, Bend, K
from fixlib.types import Json
Expand Down Expand Up @@ -1005,7 +1005,7 @@ def collect_versions() -> None:


@define(eq=False, slots=False)
class AzureMachineLearningEnvironmentVersionBase(CheckVersionIsArchived, AzureProxyResource):
class AzureMachineLearningEnvironmentVersionBase(CheckVersionIsArchived, AzureProxyResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_machine_learning_environment_version_base"
_kind_display: ClassVar[str] = "Azure Machine Learning Environment Version Base"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down Expand Up @@ -2224,7 +2224,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:


@define(eq=False, slots=False)
class AzureMachineLearningQuota(MicrosoftResource):
class AzureMachineLearningQuota(MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_machine_learning_quota"
_kind_display: ClassVar[str] = "Azure Machine Learning Quota"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down
9 changes: 5 additions & 4 deletions plugins/azure/fix_plugin_azure/resource/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
BaseTunnel,
ModelReference,
EdgeType,
PhantomBaseResource,
)
from fixlib.json_bender import F, Bender, S, Bend, ForallBend, AsInt, StringToUnitNumber, Upper, Lower
from fixlib.types import Json
Expand Down Expand Up @@ -1119,7 +1120,7 @@ class AzureApplicationGatewayFirewallRuleGroup:


@define(eq=False, slots=False)
class AzureNetworkApplicationGatewayFirewallRuleSet(MicrosoftResource):
class AzureNetworkApplicationGatewayFirewallRuleSet(MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_network_application_gateway_firewall_rule_set"
_kind_display: ClassVar[str] = "Azure Network Application Gateway Firewall Rule Set"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down Expand Up @@ -3465,7 +3466,7 @@ class AzureExpressRoutePortsLocationBandwidths:


@define(eq=False, slots=False)
class AzureNetworkExpressRoutePortsLocation(MicrosoftResource):
class AzureNetworkExpressRoutePortsLocation(MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_network_express_route_ports_location"
_kind_display: ClassVar[str] = "Azure Network Express Route Ports Location"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down Expand Up @@ -4530,7 +4531,7 @@ class AzureNetworkVirtualApplianceSkuInstances:


@define(eq=False, slots=False)
class AzureNetworkVirtualApplianceSku(MicrosoftResource):
class AzureNetworkVirtualApplianceSku(MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_network_virtual_appliance_sku"
_kind_display: ClassVar[str] = "Azure Network Virtual Appliance SKU"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down Expand Up @@ -4877,7 +4878,7 @@ class AzureNetworkRouteFilter(MicrosoftResource):


@define(eq=False, slots=False)
class AzureNetworkSecurityPartnerProvider(MicrosoftResource):
class AzureNetworkSecurityPartnerProvider(MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_network_security_partner_provider"
_kind_display: ClassVar[str] = "Azure Network Security Partner Provider"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down
6 changes: 3 additions & 3 deletions plugins/azure/fix_plugin_azure/resource/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from fix_plugin_azure.azure_client import AzureResourceSpec
from fix_plugin_azure.resource.base import MicrosoftResource, AzureSystemData, GraphBuilder
from fixlib.baseresources import ModelReference
from fixlib.baseresources import ModelReference, PhantomBaseResource
from fixlib.json_bender import Bender, S, Bend, ForallBend, F
from fixlib.types import Json

Expand Down Expand Up @@ -36,7 +36,7 @@ class AzureSecurityExtension:


@define(eq=False, slots=False)
class AzureSecurityPricing(MicrosoftResource):
class AzureSecurityPricing(MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_security_pricing"
_kind_display: ClassVar[str] = "Azure Security Pricing"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down Expand Up @@ -92,7 +92,7 @@ class AzureAssessmentStatus:


@define(eq=False, slots=False)
class AzureSecurityAssessment(MicrosoftResource):
class AzureSecurityAssessment(MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_security_assessment"
_kind_display: ClassVar[str] = "Azure Security Assessment"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down
5 changes: 3 additions & 2 deletions plugins/azure/fix_plugin_azure/resource/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
MetricName,
MetricUnit,
ModelReference,
PhantomBaseResource,
)
from fixlib.json_bender import Bender, S, ForallBend, Bend
from fixlib.types import Json
Expand Down Expand Up @@ -188,7 +189,7 @@ class AzureStorageBlobContainer(MicrosoftResource, BaseBucket):


@define(eq=False, slots=False)
class AzureStorageAccountDeleted(MicrosoftResource):
class AzureStorageAccountDeleted(MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_storage_account_deleted"
_kind_display: ClassVar[str] = "Azure Storage Account Deleted"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down Expand Up @@ -340,7 +341,7 @@ class AzureRestriction:


@define(eq=False, slots=False)
class AzureStorageSku(MicrosoftResource):
class AzureStorageSku(MicrosoftResource, PhantomBaseResource):
kind: ClassVar[str] = "azure_storage_sku"
_kind_display: ClassVar[str] = "Azure Storage SKU"
_kind_service: ClassVar[Optional[str]] = service_name
Expand Down
7 changes: 4 additions & 3 deletions plugins/azure/test/collector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def collector_with_graph(
account=AzureSubscription(id="test", subscription_id="test"),
credentials=credentials,
core_feedback=CoreFeedback("test", "test", "test", Queue()),
filter_unused_resources=False,
)
collector.graph = graph
return collector
Expand All @@ -44,11 +45,11 @@ def test_collect(
azure_client: MicrosoftClient,
) -> None:
subscription_collector = AzureSubscriptionCollector(
config, Cloud(id="azure"), azure_subscription, credentials, core_feedback
config, Cloud(id="azure"), azure_subscription, credentials, core_feedback, filter_unused_resources=False
)
subscription_collector.collect()
assert len(subscription_collector.graph.nodes) == 588
assert len(subscription_collector.graph.edges) == 977
assert len(subscription_collector.graph.nodes) == 952
assert len(subscription_collector.graph.edges) == 1341

graph_collector = MicrosoftGraphOrganizationCollector(
config, Cloud(id="azure"), MicrosoftGraphOrganization(id="test", name="test"), credentials, core_feedback
Expand Down
3 changes: 2 additions & 1 deletion plugins/gcp/fix_plugin_gcp/resources/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
VolumeStatus,
BaseInstance,
InstanceStatus,
PhantomBaseResource,
)
from fixlib.json_bender import Bender, S, Bend, ForallBend, MapDict, F, MapEnum, AsInt
from fixlib.types import Json
Expand Down Expand Up @@ -3705,7 +3706,7 @@ class GcpInterconnectLocationRegionInfo:


@define(eq=False, slots=False)
class GcpInterconnectLocation(GcpResource):
class GcpInterconnectLocation(GcpResource, PhantomBaseResource):
kind: ClassVar[str] = "gcp_interconnect_location"
_kind_display: ClassVar[str] = "GCP Interconnect Location"
_kind_description: ClassVar[str] = "A GCP Interconnect Location is a physical facility where Google Cloud Platform connects to external networks. It serves as a point of presence for establishing direct, private network connections between an organization's on-premises infrastructure and Google's network. This connection reduces latency, enhances security, and improves data transfer performance compared to public internet connections." # fmt: skip
Expand Down

0 comments on commit 303e661

Please sign in to comment.