Skip to content

Commit 869d5d6

Browse files
authored
[azure][feat] Add new resources for collect to existing base resources (#2127)
1 parent 526b549 commit 869d5d6

24 files changed

+1733
-61
lines changed

plugins/azure/fix_plugin_azure/azure_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def is_retryable_exception(e: Exception) -> bool:
6262
@define
6363
class AzureResourceSpec:
6464
service: str
65-
version: str
6665
path: str
66+
version: str
6767
path_parameters: List[str] = []
6868
query_parameters: List[str] = []
6969
access_path: Optional[str] = None

plugins/azure/fix_plugin_azure/resource/base.py

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010

1111
from fix_plugin_azure.azure_client import AzureResourceSpec, MicrosoftClient, MicrosoftRestSpec
1212
from fix_plugin_azure.config import AzureConfig
13-
from fixlib.baseresources import BaseGroup, BaseResource, Cloud, EdgeType, BaseAccount, BaseRegion, ModelReference
13+
from fixlib.baseresources import (
14+
BaseGroup,
15+
BaseResource,
16+
Cloud,
17+
EdgeType,
18+
BaseAccount,
19+
BaseRegion,
20+
ModelReference,
21+
)
1422
from fixlib.config import current_config
1523
from fixlib.core.actions import CoreFeedback
1624
from fixlib.graph import Graph, EdgeKey
@@ -324,7 +332,7 @@ def collect_resources_in_group() -> None:
324332
resources_api_spec = AzureResourceSpec(
325333
service="resources",
326334
version="2021-04-01",
327-
path="/subscriptions/{subscriptionId}/resourceGroups/" + f"{self.safe_name}/resources",
335+
path=f"{self.id}/resources",
328336
path_parameters=["subscriptionId"],
329337
query_parameters=["api-version"],
330338
access_path="value",
@@ -333,7 +341,55 @@ def collect_resources_in_group() -> None:
333341

334342
self._resource_ids_in_group = [r["id"] for r in graph_builder.client.list(resources_api_spec)]
335343

344+
def collect_network_gateways() -> None:
345+
from fix_plugin_azure.resource.network import AzureVirtualNetworkGateway
346+
347+
api_spec = AzureResourceSpec(
348+
service="network",
349+
version="2023-09-01",
350+
path=f"{self.id}/providers/Microsoft.Network/virtualNetworkGateways",
351+
path_parameters=[],
352+
query_parameters=["api-version"],
353+
access_path="value",
354+
expect_array=True,
355+
)
356+
items = graph_builder.client.list(api_spec)
357+
AzureVirtualNetworkGateway.collect(items, graph_builder)
358+
359+
def collect_local_network_gateway() -> None:
360+
from fix_plugin_azure.resource.network import AzureLocalNetworkGateway
361+
362+
api_spec = AzureResourceSpec(
363+
service="network",
364+
version="2023-09-01",
365+
path=f"{self.id}/providers/Microsoft.Network/localNetworkGateways",
366+
path_parameters=[],
367+
query_parameters=["api-version"],
368+
access_path="value",
369+
expect_array=True,
370+
)
371+
items = graph_builder.client.list(api_spec)
372+
AzureLocalNetworkGateway.collect(items, graph_builder)
373+
374+
def collect_network_gateway_connections() -> None:
375+
from fix_plugin_azure.resource.network import AzureVirtualNetworkGatewayConnection
376+
377+
api_spec = AzureResourceSpec(
378+
service="network",
379+
version="2023-09-01",
380+
path=f"{self.id}/providers/Microsoft.Network/connections",
381+
path_parameters=[],
382+
query_parameters=["api-version"],
383+
access_path="value",
384+
expect_array=True,
385+
)
386+
items = graph_builder.client.list(api_spec)
387+
AzureVirtualNetworkGatewayConnection.collect(items, graph_builder)
388+
336389
graph_builder.submit_work(service_name, collect_resources_in_group)
390+
graph_builder.submit_work(service_name, collect_network_gateways)
391+
graph_builder.submit_work(service_name, collect_local_network_gateway)
392+
graph_builder.submit_work(service_name, collect_network_gateway_connections)
337393

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

742798

743-
resources: List[Type[MicrosoftResource]] = [AzureResourceGroup]
799+
resources: List[Type[MicrosoftResource]] = [
800+
AzureResourceGroup,
801+
]

plugins/azure/fix_plugin_azure/resource/compute.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
AzureExtendedLocation,
1616
AzurePrincipalClient,
1717
AzurePrivateLinkServiceConnectionState,
18-
MicrosoftResource,
1918
)
2019
from fix_plugin_azure.resource.metrics import AzureMetricData, AzureMetricQuery, update_resource_metrics
2120
from fix_plugin_azure.resource.network import (

plugins/azure/fix_plugin_azure/resource/containerservice.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
AzureUserAssignedIdentity,
1414
AzurePrincipalClient,
1515
AzureManagedServiceIdentity,
16-
MicrosoftResource,
1716
)
1817
from fixlib.baseresources import BaseManagedKubernetesClusterProvider, BaseSnapshot, EdgeType, ModelReference
1918
from fixlib.json_bender import Bender, S, Bend, ForallBend

plugins/azure/fix_plugin_azure/resource/microsoft_graph.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from fix_plugin_azure.azure_client import RestApiSpec, MicrosoftRestSpec
99
from fix_plugin_azure.resource.base import GraphBuilder, MicrosoftResource
10-
from fixlib.baseresources import BaseRole, BaseAccount, BaseRegion, ModelReference
10+
from fixlib.baseresources import BaseGroup, BaseRole, BaseAccount, BaseRegion, ModelReference, BaseUser
1111
from fixlib.json_bender import Bender, S, ForallBend, Bend, F, MapDict
1212
from fixlib.types import Json
1313

@@ -573,6 +573,7 @@ class MicrosoftGraphServicePrincipal(MicrosoftGraphEntity):
573573
"sign_in_audience": S("signInAudience"),
574574
"token_encryption_key_id": S("tokenEncryptionKeyId"),
575575
"verified_publisher": S("verifiedPublisher") >> Bend(MicrosoftGraphVerifiedPublisher.mapping),
576+
"access_key_status": S("disabledByMicrosoftStatus"),
576577
}
577578
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
578579
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
@@ -717,7 +718,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
717718

718719

719720
@define(eq=False, slots=False)
720-
class MicrosoftGraphUser(MicrosoftGraphEntity):
721+
class MicrosoftGraphUser(MicrosoftGraphEntity, BaseUser):
721722
kind: ClassVar[str] = "microsoft_graph_user"
722723
api_spec: ClassVar[MicrosoftRestSpec] = RestApiSpec(
723724
"graph",
@@ -884,7 +885,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
884885

885886

886887
@define(eq=False, slots=False)
887-
class MicrosoftGraphGroup(MicrosoftGraphEntity):
888+
class MicrosoftGraphGroup(MicrosoftGraphEntity, BaseGroup):
888889
kind: ClassVar[str] = "microsoft_graph_group"
889890
api_spec: ClassVar[MicrosoftRestSpec] = RestApiSpec(
890891
"graph",

0 commit comments

Comments
 (0)