|
13 | 13 | AzureSystemData, |
14 | 14 | ) |
15 | 15 | from fix_plugin_azure.resource.microsoft_graph import MicrosoftGraphServicePrincipal, MicrosoftGraphUser |
| 16 | +from fix_plugin_azure.utils import from_str_to_typed |
16 | 17 | from fixlib.baseresources import ( |
17 | 18 | BaseDatabase, |
18 | 19 | BaseDatabaseInstanceType, |
|
21 | 22 | ModelReference, |
22 | 23 | ) |
23 | 24 | from fixlib.graph import BySearchCriteria |
24 | | -from fixlib.json_bender import K, AsBool, Bender, S, ForallBend, Bend, MapEnum, MapValue |
| 25 | +from fixlib.json_bender import K, Bender, S, ForallBend, Bend, MapEnum, MapValue |
25 | 26 | from fixlib.types import Json |
26 | 27 |
|
27 | 28 | service_name = "azure_mysql" |
@@ -318,39 +319,34 @@ def collect( |
318 | 319 | class AzureMysqlServerConfiguration(MicrosoftResource): |
319 | 320 | kind: ClassVar[str] = "azure_mysql_server_configuration" |
320 | 321 | # Collect via AzureMysqlServer() |
321 | | - mapping: ClassVar[Dict[str, Bender]] = { |
322 | | - "id": S("id"), |
323 | | - "tags": S("tags", default={}), |
324 | | - "name": S("name"), |
325 | | - "system_data": S("systemData") >> Bend(AzureSystemData.mapping), |
326 | | - "type": S("type"), |
327 | | - "ctime": S("systemData", "createdAt"), |
328 | | - "mtime": S("systemData", "lastModifiedAt"), |
329 | | - "allowed_values": S("properties", "allowedValues"), |
330 | | - "current_value": S("properties", "currentValue"), |
331 | | - "data_type": S("properties", "dataType"), |
332 | | - "default_value": S("properties", "defaultValue"), |
333 | | - "description": S("properties", "description"), |
334 | | - "documentation_link": S("properties", "documentationLink"), |
335 | | - "is_config_pending_restart": S("properties", "isConfigPendingRestart") >> AsBool(), |
336 | | - "is_dynamic_config": S("properties", "isDynamicConfig") >> AsBool(), |
337 | | - "is_read_only": S("properties", "isReadOnly") >> AsBool(), |
338 | | - "source": S("properties", "source"), |
339 | | - "value": S("properties", "value"), |
340 | | - } |
341 | | - allowed_values: Optional[str] = field(default=None, metadata={'description': 'Allowed values of the configuration.'}) # fmt: skip |
342 | | - current_value: Optional[str] = field(default=None, metadata={"description": "Current value of the configuration."}) |
343 | | - data_type: Optional[str] = field(default=None, metadata={"description": "Data type of the configuration."}) |
344 | | - default_value: Optional[str] = field(default=None, metadata={"description": "Default value of the configuration."}) |
345 | | - description: Optional[str] = field(default=None, metadata={"description": "Description of the configuration."}) |
346 | | - documentation_link: Optional[str] = field(default=None, metadata={'description': 'The link used to get the document from community or Azure site.'}) # fmt: skip |
347 | | - is_config_pending_restart: Optional[bool] = field(default=None, metadata={'description': 'If is the configuration pending restart or not.'}) # fmt: skip |
348 | | - is_dynamic_config: Optional[bool] = field(default=None, metadata={'description': 'If is the configuration dynamic.'}) # fmt: skip |
349 | | - is_read_only: Optional[bool] = field(default=None, metadata={"description": "If is the configuration read only."}) |
350 | | - source: Optional[str] = field(default=None, metadata={"description": "Source of the configuration."}) |
351 | | - value: Optional[str] = field(default=None, metadata={"description": "Value of the configuration."}) |
352 | | - system_data: Optional[AzureSystemData] = field(default=None, metadata={'description': 'Metadata pertaining to creation and last modification of the resource.'}) # fmt: skip |
353 | | - type: Optional[str] = field(default=None, metadata={'description': 'The type of the resource. E.g. Microsoft.Compute/virtualMachines or Microsoft.Storage/storageAccounts '}) # fmt: skip |
| 322 | + config: Json = field(factory=dict) |
| 323 | + |
| 324 | + @classmethod |
| 325 | + def collect_configs( |
| 326 | + cls, |
| 327 | + server_id: str, |
| 328 | + raw: List[Json], |
| 329 | + builder: GraphBuilder, |
| 330 | + ) -> List["AzureMysqlServerConfiguration"]: |
| 331 | + if not raw: |
| 332 | + return [] |
| 333 | + configuration_instance = AzureMysqlServerConfiguration(id=server_id) |
| 334 | + for js in raw: |
| 335 | + properties = js.get("properties") |
| 336 | + if not properties: |
| 337 | + continue |
| 338 | + if ( |
| 339 | + (data_type := properties.get("dataType")) |
| 340 | + and (val := properties.get("currentValue") or properties.get("value")) |
| 341 | + and (config_name := js.get("name")) |
| 342 | + ): |
| 343 | + value = from_str_to_typed(data_type, val) |
| 344 | + if not value: |
| 345 | + continue |
| 346 | + configuration_instance.config[config_name] = value |
| 347 | + if (added := builder.add_node(configuration_instance, configuration_instance.config)) is not None: |
| 348 | + return [added] |
| 349 | + return [] |
354 | 350 |
|
355 | 351 |
|
356 | 352 | @define(eq=False, slots=False) |
@@ -667,14 +663,12 @@ def _collect_items( |
667 | 663 | items = graph_builder.client.list(api_spec) |
668 | 664 | if not items: |
669 | 665 | return |
670 | | - collected = class_instance.collect(items, graph_builder) |
671 | | - for clazz in collected: |
672 | | - graph_builder.add_edge( |
673 | | - self, |
674 | | - edge_type=EdgeType.default, |
675 | | - id=clazz.id, |
676 | | - clazz=class_instance, |
677 | | - ) |
| 666 | + if issubclass(AzureMysqlServerConfiguration, class_instance): # type: ignore |
| 667 | + collected = class_instance.collect_configs(self.id, items, graph_builder) # type: ignore |
| 668 | + else: |
| 669 | + collected = class_instance.collect(items, graph_builder) |
| 670 | + for resource in collected: |
| 671 | + graph_builder.add_edge(self, node=resource) |
678 | 672 |
|
679 | 673 | def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: |
680 | 674 | if server_id := self.id: |
|
0 commit comments