Skip to content

Commit

Permalink
[lib][fix] Fix kind names (#2103)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Jun 9, 2024
1 parent 1ad2be6 commit 3c944e8
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 109 deletions.
6 changes: 6 additions & 0 deletions fixlib/fixlib/core/model_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,14 @@ def check_overlap(*base: Type[BaseResource]) -> None:
:raise Exception: if there is an overlap
"""

kind_names: Dict[str, Type[Any]] = {}
model_classes = load_plugin_classes(*base)
for model in transitive_classes(model_classes):
if kind := getattr(model, "kind", None):
if (existing := kind_names.get(kind)) and existing != model:
raise AttributeError(f"Kind {kind} is defined in {model.__name__} and {existing.__name__}")
kind_names[kind] = model

if issubclass(model, BaseResource) and not getattr(model, "__abstractmethods__"):
# check that the model class is not abstract and has no abstract methods
check_model_class(model)
Expand Down
4 changes: 2 additions & 2 deletions fixlib/test/core/model_check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BreakingResource(BaseResource, ABC):
def test_check() -> None:
# this will throw an exception, since breaking resource has a breaking property
with raises(Exception):
check_overlap()
check_overlap(BaseResource, BreakingResource)
# hacky way to "delete" the fields - the exporter will not see the field any longer.
BreakingResource.__attrs_attrs__ = {}
check_overlap()
check_overlap(BaseResource)
2 changes: 1 addition & 1 deletion plugins/aws/fix_plugin_aws/resource/waf.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class AwsWafRequestInspection:

@define(eq=False, slots=False)
class AwsWafResponseInspectionPart:
kind: ClassVar[str] = "aws_waf_response_inspection"
kind: ClassVar[str] = "aws_waf_response_inspection_part"
mapping: ClassVar[Dict[str, Bender]] = {
"name": S("Name"),
"identifier": S("Identifier"),
Expand Down
34 changes: 32 additions & 2 deletions plugins/azure/fix_plugin_azure/resource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,43 @@ class AzureExtendedLocation:


@define(eq=False, slots=False)
class AzurePrincipalidClientid:
kind: ClassVar[str] = "azure_principalid_clientid"
class AzureUserAssignedIdentity:
kind: ClassVar[str] = "azure_user_assigned_identity"
mapping: ClassVar[Dict[str, Bender]] = {
"client_id": S("clientId"),
"principal_id": S("principalId"),
"object_id": S("objectId"),
"resource_id": S("resourceId"),
}
client_id: Optional[str] = field(default=None, metadata={"description": "The client ID of the identity."})
principal_id: Optional[str] = field(default=None, metadata={"description": "The principal ID of the identity."})
object_id: Optional[str] = field(default=None, metadata={'description': 'The object ID of the user assigned identity.'}) # fmt: skip
resource_id: Optional[str] = field(default=None, metadata={'description': 'The resource ID of the user assigned identity.'}) # fmt: skip


@define(eq=False, slots=False)
class AzurePrincipalClient:
kind: ClassVar[str] = "azure_principal_client"
mapping: ClassVar[Dict[str, Bender]] = {"client_id": S("clientId"), "principal_id": S("principalId")}
client_id: Optional[str] = field(default=None, metadata={'description': 'The client id of user assigned identity.'}) # fmt: skip
principal_id: Optional[str] = field(default=None, metadata={'description': 'The principal id of user assigned identity.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureManagedServiceIdentity:
kind: ClassVar[str] = "azure_managed_service_identity"
mapping: ClassVar[Dict[str, Bender]] = {
"principal_id": S("principalId"),
"tenant_id": S("tenantId"),
"type": S("type"),
"user_assigned_identities": S("userAssignedIdentities"),
}
principal_id: Optional[str] = field(default=None, metadata={'description': 'The principal id of the system assigned identity. This property will only be provided for a system assigned identity.'}) # fmt: skip
tenant_id: Optional[str] = field(default=None, metadata={'description': 'The tenant id of the system assigned identity. This property will only be provided for a system assigned identity.'}) # fmt: skip
type: Optional[str] = field(default=None, metadata={'description': 'The type of identity used for the resource. The type SystemAssigned, UserAssigned includes both an implicitly created identity and a set of user assigned identities. The type None will remove any identities from the virtual machine.'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalClient]] = field(default=None, metadata={'description': 'The list of user identities associated with resource. The user identity dictionary key references will be ARM resource ids in the form: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName} .'}) # fmt: skip


@define(eq=False, slots=False)
class AzurePrivateLinkServiceConnectionState:
kind: ClassVar[str] = "azure_private_link_service_connection_state"
Expand Down
8 changes: 4 additions & 4 deletions plugins/azure/fix_plugin_azure/resource/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
AzureSystemData,
AzureSku,
AzureExtendedLocation,
AzurePrincipalidClientid,
AzurePrincipalClient,
AzurePrivateLinkServiceConnectionState,
)
from fix_plugin_azure.resource.metrics import AzureMetricData, AzureMetricQuery, update_resource_metrics
Expand Down Expand Up @@ -1273,7 +1273,7 @@ class AzureEncryptionSetIdentity:
principal_id: Optional[str] = field(default=None, metadata={'description': 'The object id of the managed identity resource. This will be sent to the rp from arm via the x-ms-identity-principal-id header in the put request if the resource has a systemassigned(implicit) identity.'}) # fmt: skip
tenant_id: Optional[str] = field(default=None, metadata={'description': 'The tenant id of the managed identity resource. This will be sent to the rp from arm via the x-ms-client-tenant-id header in the put request if the resource has a systemassigned(implicit) identity.'}) # fmt: skip
type: Optional[str] = field(default=None, metadata={'description': 'The type of managed identity used by the diskencryptionset. Only systemassigned is supported for new creations. Disk encryption sets can be updated with identity type none during migration of subscription to a new azure active directory tenant; it will cause the encrypted resources to lose access to the keys.'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalidClientid]] = field(default=None, metadata={'description': 'The list of user identities associated with the virtual machine. The user identity dictionary key references will be arm resource ids in the form: /subscriptions/{subscriptionid}/resourcegroups/{resourcegroupname}/providers/microsoft. Managedidentity/userassignedidentities/{identityname}.'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalClient]] = field(default=None, metadata={'description': 'The list of user identities associated with the virtual machine. The user identity dictionary key references will be arm resource ids in the form: /subscriptions/{subscriptionid}/resourcegroups/{resourcegroupname}/providers/microsoft. Managedidentity/userassignedidentities/{identityname}.'}) # fmt: skip


@define(eq=False, slots=False)
Expand Down Expand Up @@ -2812,7 +2812,7 @@ class AzureVirtualMachineIdentity:
principal_id: Optional[str] = field(default=None, metadata={'description': 'The principal id of virtual machine identity. This property will only be provided for a system assigned identity.'}) # fmt: skip
tenant_id: Optional[str] = field(default=None, metadata={'description': 'The tenant id associated with the virtual machine. This property will only be provided for a system assigned identity.'}) # fmt: skip
type: Optional[str] = field(default=None, metadata={'description': 'The type of identity used for the virtual machine. The type systemassigned, userassigned includes both an implicitly created identity and a set of user assigned identities. The type none will remove any identities from the virtual machine.'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalidClientid]] = field(default=None, metadata={'description': 'The list of user identities associated with the virtual machine. The user identity dictionary key references will be arm resource ids in the form: /subscriptions/{subscriptionid}/resourcegroups/{resourcegroupname}/providers/microsoft. Managedidentity/userassignedidentities/{identityname}.'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalClient]] = field(default=None, metadata={'description': 'The list of user identities associated with the virtual machine. The user identity dictionary key references will be arm resource ids in the form: /subscriptions/{subscriptionid}/resourcegroups/{resourcegroupname}/providers/microsoft. Managedidentity/userassignedidentities/{identityname}.'}) # fmt: skip


InstanceStatusMapping = {
Expand Down Expand Up @@ -3529,7 +3529,7 @@ class AzureVirtualMachineScaleSetIdentity:
principal_id: Optional[str] = field(default=None, metadata={'description': 'The principal id of virtual machine scale set identity. This property will only be provided for a system assigned identity.'}) # fmt: skip
tenant_id: Optional[str] = field(default=None, metadata={'description': 'The tenant id associated with the virtual machine scale set. This property will only be provided for a system assigned identity.'}) # fmt: skip
type: Optional[str] = field(default=None, metadata={'description': 'The type of identity used for the virtual machine scale set. The type systemassigned, userassigned includes both an implicitly created identity and a set of user assigned identities. The type none will remove any identities from the virtual machine scale set.'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalidClientid]] = field(default=None, metadata={'description': 'The list of user identities associated with the virtual machine. The user identity dictionary key references will be arm resource ids in the form: /subscriptions/{subscriptionid}/resourcegroups/{resourcegroupname}/providers/microsoft. Managedidentity/userassignedidentities/{identityname}.'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalClient]] = field(default=None, metadata={'description': 'The list of user identities associated with the virtual machine. The user identity dictionary key references will be arm resource ids in the form: /subscriptions/{subscriptionid}/resourcegroups/{resourcegroupname}/providers/microsoft. Managedidentity/userassignedidentities/{identityname}.'}) # fmt: skip


@define(eq=False, slots=False)
Expand Down
56 changes: 10 additions & 46 deletions plugins/azure/fix_plugin_azure/resource/containerservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
from attr import define, field

from fix_plugin_azure.azure_client import AzureApiSpec
from fix_plugin_azure.resource.base import AzureResource, AzureSystemData, GraphBuilder
from fix_plugin_azure.resource.base import (
AzureResource,
AzureSystemData,
GraphBuilder,
AzureExtendedLocation,
AzureUserAssignedIdentity,
AzurePrincipalClient,
AzureManagedServiceIdentity,
)
from fixlib.baseresources import EdgeType, ModelReference
from fixlib.json_bender import Bender, S, Bend, ForallBend
from fixlib.types import Json
Expand Down Expand Up @@ -73,34 +81,6 @@ class AzureFleetHubProfile:
portal_fqdn: Optional[str] = field(default=None, metadata={'description': 'The Azure Portal FQDN of the Fleet hub.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureUserAssignedIdentity:
kind: ClassVar[str] = "azure_user_assigned_identity"
mapping: ClassVar[Dict[str, Bender]] = {
"client_id": S("clientId"),
"object_id": S("objectId"),
"resource_id": S("resourceId"),
}
client_id: Optional[str] = field(default=None, metadata={'description': 'The client ID of the user assigned identity.'}) # fmt: skip
object_id: Optional[str] = field(default=None, metadata={'description': 'The object ID of the user assigned identity.'}) # fmt: skip
resource_id: Optional[str] = field(default=None, metadata={'description': 'The resource ID of the user assigned identity.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureManagedServiceIdentity:
kind: ClassVar[str] = "azure_managed_service_identity"
mapping: ClassVar[Dict[str, Bender]] = {
"principal_id": S("principalId"),
"tenant_id": S("tenantId"),
"type": S("type"),
"user_assigned_identities": S("userAssignedIdentities"),
}
principal_id: Optional[str] = field(default=None, metadata={'description': 'The service principal ID of the system assigned identity. This property will only be provided for a system assigned identity.'}) # fmt: skip
tenant_id: Optional[str] = field(default=None, metadata={'description': 'The tenant ID of the system assigned identity. This property will only be provided for a system assigned identity.'}) # fmt: skip
type: Optional[str] = field(default=None, metadata={'description': 'Type of managed service identity (where both SystemAssigned and UserAssigned types are allowed).'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzureUserAssignedIdentity]] = field(default=None, metadata={'description': 'The set of user assigned identities associated with the resource. The userAssignedIdentities dictionary keys will be ARM resource ids in the form: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. The dictionary values can be empty objects ({}) in requests.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureFleet(AzureResource):
kind: ClassVar[str] = "azure_fleet"
Expand Down Expand Up @@ -183,14 +163,6 @@ class AzureManagedClusterSKU:
tier: Optional[str] = field(default=None, metadata={'description': 'If not specified, the default is Free . See [AKS Pricing Tier](https://learn.microsoft.com/azure/aks/free-standard-pricing-tiers) for more details.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureExtendedLocation:
kind: ClassVar[str] = "azure_extended_location"
mapping: ClassVar[Dict[str, Bender]] = {"name": S("name"), "type": S("type")}
name: Optional[str] = field(default=None, metadata={"description": "The name of the extended location."})
type: Optional[str] = field(default=None, metadata={"description": "The type of extendedLocation."})


@define(eq=False, slots=False)
class AzureDelegatedResource:
kind: ClassVar[str] = "azure_delegated_resource"
Expand All @@ -206,14 +178,6 @@ class AzureDelegatedResource:
tenant_id: Optional[str] = field(default=None, metadata={'description': 'The tenant id of the delegated resource - internal use only.'}) # fmt: skip


@define(eq=False, slots=False)
class AzurePrincipalidClientid:
kind: ClassVar[str] = "azure_principalid_clientid"
mapping: ClassVar[Dict[str, Bender]] = {"client_id": S("clientId"), "principal_id": S("principalId")}
client_id: Optional[str] = field(default=None, metadata={'description': 'The client id of user assigned identity.'}) # fmt: skip
principal_id: Optional[str] = field(default=None, metadata={'description': 'The principal id of user assigned identity.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureManagedClusterIdentity:
kind: ClassVar[str] = "azure_managed_cluster_identity"
Expand All @@ -228,7 +192,7 @@ class AzureManagedClusterIdentity:
principal_id: Optional[str] = field(default=None, metadata={'description': 'The principal id of the system assigned identity which is used by master components.'}) # fmt: skip
tenant_id: Optional[str] = field(default=None, metadata={'description': 'The tenant id of the system assigned identity which is used by master components.'}) # fmt: skip
type: Optional[str] = field(default=None, metadata={'description': 'For more information see [use managed identities in AKS](https://docs.microsoft.com/azure/aks/use-managed-identity).'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalidClientid]] = field(default=None, metadata={'description': 'The keys must be ARM resource IDs in the form: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName} .'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalClient]] = field(default=None, metadata={'description': 'The keys must be ARM resource IDs in the form: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName} .'}) # fmt: skip


@define(eq=False, slots=False)
Expand Down
17 changes: 1 addition & 16 deletions plugins/azure/fix_plugin_azure/resource/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
AzureSubResource,
AzureSku,
AzureExtendedLocation,
AzurePrincipalidClientid,
AzurePrivateLinkServiceConnectionState,
AzureManagedServiceIdentity,
)
from fix_plugin_azure.resource.containerservice import AzureManagedCluster
from fix_plugin_azure.utils import rgetattr
Expand Down Expand Up @@ -962,21 +962,6 @@ class AzureApplicationGatewayGlobalConfiguration:
enable_response_buffering: Optional[bool] = field(default=None, metadata={'description': 'Enable response buffering.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureManagedServiceIdentity:
kind: ClassVar[str] = "azure_managed_service_identity"
mapping: ClassVar[Dict[str, Bender]] = {
"principal_id": S("principalId"),
"tenant_id": S("tenantId"),
"type": S("type"),
"user_assigned_identities": S("userAssignedIdentities"),
}
principal_id: Optional[str] = field(default=None, metadata={'description': 'The principal id of the system assigned identity. This property will only be provided for a system assigned identity.'}) # fmt: skip
tenant_id: Optional[str] = field(default=None, metadata={'description': 'The tenant id of the system assigned identity. This property will only be provided for a system assigned identity.'}) # fmt: skip
type: Optional[str] = field(default=None, metadata={'description': 'The type of identity used for the resource. The type SystemAssigned, UserAssigned includes both an implicitly created identity and a set of user assigned identities. The type None will remove any identities from the virtual machine.'}) # fmt: skip
user_assigned_identities: Optional[Dict[str, AzurePrincipalidClientid]] = field(default=None, metadata={'description': 'The list of user identities associated with resource. The user identity dictionary key references will be ARM resource ids in the form: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName} .'}) # fmt: skip


@define(eq=False, slots=False)
class AzureApplicationGateway(AzureResource, BaseGateway):
kind: ClassVar[str] = "azure_application_gateway"
Expand Down
Loading

0 comments on commit 3c944e8

Please sign in to comment.