Skip to content

Commit 4f4d80e

Browse files
1101-1aquamatthias
andauthored
[azure][feat] Add support for sql resource collection (#2144)
Co-authored-by: Matthias Veit <aquamatthias@users.noreply.github.com>
1 parent 75133b9 commit 4f4d80e

22 files changed

+2215
-19
lines changed

plugins/azure/fix_plugin_azure/collector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
AzureNetworkUsage,
3535
resources as network_resources,
3636
)
37+
from fix_plugin_azure.resource.sql import resources as sql_resources
3738
from fix_plugin_azure.resource.storage import AzureStorageAccountUsage, AzureStorageSku, resources as storage_resources
3839
from fixlib.baseresources import Cloud, GraphRoot, BaseAccount, BaseRegion
3940
from fixlib.core.actions import CoreFeedback, ErrorAccumulator
@@ -59,6 +60,7 @@ def resource_with_params(clazz: Type[MicrosoftResource], param: str) -> bool:
5960
+ aks_resources
6061
+ security_resources
6162
+ storage_resources
63+
+ sql_resources
6264
)
6365
all_resources = subscription_resources + graph_resources # defines all resource kinds. used in model check
6466

plugins/azure/fix_plugin_azure/resource/base.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,35 @@ class MicrosoftResource(BaseResource):
6262
etag: Optional[str] = field(default=None, metadata={'description': 'A unique read-only string that changes whenever the resource is updated.'}) # fmt: skip
6363
provisioning_state: Optional[str] = field(default=None, metadata={'description': 'The current provisioning state.'}) # fmt: skip
6464

65+
@property
6566
def resource_subscription_id(self) -> Optional[str]:
66-
return self.extract_part("subscriptionId")
67+
return self.extract_part("subscriptions")
68+
69+
@property
70+
def resource_group_name(self) -> Optional[str]:
71+
return self.extract_part("resourceGroups")
6772

6873
def extract_part(self, part: str) -> Optional[str]:
6974
"""
7075
Extracts a specific part from a resource ID.
7176
72-
The function takes a resource ID and a specified part to extract, such as 'subscriptionId'.
77+
The function takes a resource ID and a specified part to extract, such as 'subscriptions'.
7378
The resource ID is expected to follow the Azure Resource Manager path format.
7479
7580
Example:
7681
For the resource ID "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/...",
77-
calling extract_part("subscriptionId") would return the value within the curly braces,
78-
representing the subscription ID.
82+
calling extract_part("subscriptions") would return the value representing the subscription ID.
7983
8084
Parameters:
8185
- part (str): The part to extract from the resource ID.
8286
8387
Returns:
84-
str: The extracted part of the resource ID.
88+
Optional[str]: The extracted part of the resource ID, or None if not found.
8589
"""
8690
id_parts = self.id.split("/")
87-
88-
if part == "subscriptionId":
89-
if "subscriptions" not in id_parts:
90-
return None
91-
if index := id_parts.index("subscriptions"):
92-
return id_parts[index + 1]
93-
return None
94-
else:
91+
try:
92+
return id_parts[id_parts.index(part) + 1]
93+
except ValueError:
9594
return None
9695

9796
def delete(self, graph: Graph) -> bool:
@@ -101,7 +100,7 @@ def delete(self, graph: Graph) -> bool:
101100
Returns:
102101
bool: True if the resource was successfully deleted; False otherwise.
103102
"""
104-
subscription_id = self.resource_subscription_id()
103+
subscription_id = self.resource_subscription_id
105104
if subscription_id is None:
106105
log.warning("Failed to delete resource. Subscription ID is not available.")
107106
return False
@@ -113,7 +112,7 @@ def delete_tag(self, key: str) -> bool:
113112
This method removes a specific value from a tag associated with a subscription, while keeping the tag itself intact.
114113
The tag remains on the account, but the specified value will be deleted.
115114
"""
116-
subscription_id = self.resource_subscription_id()
115+
subscription_id = self.resource_subscription_id
117116
if subscription_id is None:
118117
log.warning("Failed to delete tag. Subscription ID is not available.")
119118
return False
@@ -125,7 +124,7 @@ def update_tag(self, key: str, value: str) -> bool:
125124
This method allows for the creation or update of a tag value associated with the specified tag name.
126125
The tag name must already exist for the operation to be successful.
127126
"""
128-
subscription_id = self.resource_subscription_id()
127+
subscription_id = self.resource_subscription_id
129128
if subscription_id is None:
130129
log.warning("Failed to update tag. Subscription ID is not available.")
131130
return False
@@ -570,11 +569,13 @@ class AzureSku:
570569
"name": S("name"),
571570
"tier": S("tier"),
572571
"family": S("family"),
572+
"size": S("size"),
573573
}
574574
capacity: Optional[int] = field(default=None, metadata={'description': 'Specifies the number of virtual machines in the scale set.'}) # fmt: skip
575575
family: Optional[str] = field(default=None, metadata={"description": "The family of the sku."})
576576
name: Optional[str] = field(default=None, metadata={"description": "The sku name."})
577577
tier: Optional[str] = field(default=None, metadata={'description': 'Specifies the tier of virtual machines in a scale set. Possible values: **standard** **basic**.'}) # fmt: skip
578+
size: Optional[str] = field(default=None, metadata={"description": "Size of the particular SKU"})
578579

579580

580581
class GraphBuilder:

plugins/azure/fix_plugin_azure/resource/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from fix_plugin_azure.azure_client import AzureResourceSpec
77
from fix_plugin_azure.resource.base import (
88
AzureBaseUsage,
9-
MicrosoftResource,
109
GraphBuilder,
1110
AzureSubResource,
1211
AzureSku,
1312
AzureExtendedLocation,
1413
AzurePrivateLinkServiceConnectionState,
1514
AzureManagedServiceIdentity,
15+
MicrosoftResource,
1616
)
1717
from fix_plugin_azure.resource.containerservice import AzureManagedCluster
1818
from fix_plugin_azure.utils import rgetattr

0 commit comments

Comments
 (0)