Skip to content

Commit

Permalink
[azure][feat] Add new resources for collect to existing base resources (
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 authored Jul 16, 2024
1 parent 526b549 commit 869d5d6
Show file tree
Hide file tree
Showing 24 changed files with 1,733 additions and 61 deletions.
2 changes: 1 addition & 1 deletion plugins/azure/fix_plugin_azure/azure_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def is_retryable_exception(e: Exception) -> bool:
@define
class AzureResourceSpec:
service: str
version: str
path: str
version: str
path_parameters: List[str] = []
query_parameters: List[str] = []
access_path: Optional[str] = None
Expand Down
64 changes: 61 additions & 3 deletions plugins/azure/fix_plugin_azure/resource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@

from fix_plugin_azure.azure_client import AzureResourceSpec, MicrosoftClient, MicrosoftRestSpec
from fix_plugin_azure.config import AzureConfig
from fixlib.baseresources import BaseGroup, BaseResource, Cloud, EdgeType, BaseAccount, BaseRegion, ModelReference
from fixlib.baseresources import (
BaseGroup,
BaseResource,
Cloud,
EdgeType,
BaseAccount,
BaseRegion,
ModelReference,
)
from fixlib.config import current_config
from fixlib.core.actions import CoreFeedback
from fixlib.graph import Graph, EdgeKey
Expand Down Expand Up @@ -324,7 +332,7 @@ def collect_resources_in_group() -> None:
resources_api_spec = AzureResourceSpec(
service="resources",
version="2021-04-01",
path="/subscriptions/{subscriptionId}/resourceGroups/" + f"{self.safe_name}/resources",
path=f"{self.id}/resources",
path_parameters=["subscriptionId"],
query_parameters=["api-version"],
access_path="value",
Expand All @@ -333,7 +341,55 @@ 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

api_spec = AzureResourceSpec(
service="network",
version="2023-09-01",
path=f"{self.id}/providers/Microsoft.Network/virtualNetworkGateways",
path_parameters=[],
query_parameters=["api-version"],
access_path="value",
expect_array=True,
)
items = graph_builder.client.list(api_spec)
AzureVirtualNetworkGateway.collect(items, graph_builder)

def collect_local_network_gateway() -> None:
from fix_plugin_azure.resource.network import AzureLocalNetworkGateway

api_spec = AzureResourceSpec(
service="network",
version="2023-09-01",
path=f"{self.id}/providers/Microsoft.Network/localNetworkGateways",
path_parameters=[],
query_parameters=["api-version"],
access_path="value",
expect_array=True,
)
items = graph_builder.client.list(api_spec)
AzureLocalNetworkGateway.collect(items, graph_builder)

def collect_network_gateway_connections() -> None:
from fix_plugin_azure.resource.network import AzureVirtualNetworkGatewayConnection

api_spec = AzureResourceSpec(
service="network",
version="2023-09-01",
path=f"{self.id}/providers/Microsoft.Network/connections",
path_parameters=[],
query_parameters=["api-version"],
access_path="value",
expect_array=True,
)
items = graph_builder.client.list(api_spec)
AzureVirtualNetworkGatewayConnection.collect(items, graph_builder)

graph_builder.submit_work(service_name, collect_resources_in_group)
graph_builder.submit_work(service_name, collect_network_gateways)
graph_builder.submit_work(service_name, collect_local_network_gateway)
graph_builder.submit_work(service_name, collect_network_gateway_connections)

def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
if resource_ids := self._resource_ids_in_group:
Expand Down Expand Up @@ -740,4 +796,6 @@ def with_location(self, location: BaseRegion) -> GraphBuilder:
)


resources: List[Type[MicrosoftResource]] = [AzureResourceGroup]
resources: List[Type[MicrosoftResource]] = [
AzureResourceGroup,
]
1 change: 0 additions & 1 deletion plugins/azure/fix_plugin_azure/resource/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
AzureExtendedLocation,
AzurePrincipalClient,
AzurePrivateLinkServiceConnectionState,
MicrosoftResource,
)
from fix_plugin_azure.resource.metrics import AzureMetricData, AzureMetricQuery, update_resource_metrics
from fix_plugin_azure.resource.network import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
AzureUserAssignedIdentity,
AzurePrincipalClient,
AzureManagedServiceIdentity,
MicrosoftResource,
)
from fixlib.baseresources import BaseManagedKubernetesClusterProvider, BaseSnapshot, EdgeType, ModelReference
from fixlib.json_bender import Bender, S, Bend, ForallBend
Expand Down
7 changes: 4 additions & 3 deletions plugins/azure/fix_plugin_azure/resource/microsoft_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from fix_plugin_azure.azure_client import RestApiSpec, MicrosoftRestSpec
from fix_plugin_azure.resource.base import GraphBuilder, MicrosoftResource
from fixlib.baseresources import BaseRole, BaseAccount, BaseRegion, ModelReference
from fixlib.baseresources import BaseGroup, BaseRole, BaseAccount, BaseRegion, ModelReference, BaseUser
from fixlib.json_bender import Bender, S, ForallBend, Bend, F, MapDict
from fixlib.types import Json

Expand Down Expand Up @@ -573,6 +573,7 @@ class MicrosoftGraphServicePrincipal(MicrosoftGraphEntity):
"sign_in_audience": S("signInAudience"),
"token_encryption_key_id": S("tokenEncryptionKeyId"),
"verified_publisher": S("verifiedPublisher") >> Bend(MicrosoftGraphVerifiedPublisher.mapping),
"access_key_status": S("disabledByMicrosoftStatus"),
}
account_enabled: Optional[bool] = field(default=None, metadata={'description': 'true if the service principal account is enabled; otherwise, false. If set to false, then no users are able to sign in to this app, even if they re assigned to it. Supports $filter (eq, ne, not, in).'}) # fmt: skip
add_ins: Optional[List[MicrosoftGraphAddIn]] = field(default=None, metadata={'description': 'Defines custom behavior that a consuming service can use to call an app in specific contexts. For example, applications that can render file streams may set the addIns property for its FileHandler functionality. This lets services like Microsoft 365 call the application in the context of a document the user is working on.'}) # fmt: skip
Expand Down Expand Up @@ -717,7 +718,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:


@define(eq=False, slots=False)
class MicrosoftGraphUser(MicrosoftGraphEntity):
class MicrosoftGraphUser(MicrosoftGraphEntity, BaseUser):
kind: ClassVar[str] = "microsoft_graph_user"
api_spec: ClassVar[MicrosoftRestSpec] = RestApiSpec(
"graph",
Expand Down Expand Up @@ -884,7 +885,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:


@define(eq=False, slots=False)
class MicrosoftGraphGroup(MicrosoftGraphEntity):
class MicrosoftGraphGroup(MicrosoftGraphEntity, BaseGroup):
kind: ClassVar[str] = "microsoft_graph_group"
api_spec: ClassVar[MicrosoftRestSpec] = RestApiSpec(
"graph",
Expand Down
Loading

0 comments on commit 869d5d6

Please sign in to comment.