Skip to content

Commit d7fcb84

Browse files
authored
[plugins][fix] Add missing metadata (#2192)
1 parent 90139f5 commit d7fcb84

File tree

14 files changed

+116
-8
lines changed

14 files changed

+116
-8
lines changed

plugins/aws/fix_plugin_aws/resource/ec2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3409,6 +3409,7 @@ class AwsEc2Image(AwsResource):
34093409
kind_service: ClassVar[Optional[str]] = service_name
34103410
metadata: ClassVar[Dict[str, Any]] = {"icon": "image", "group": "compute"}
34113411
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/ec2/home?region={region}#ImageDetails:imageId={id}", "arn_tpl": "arn:{partition}:ec2:{region}:{account}:image/{id}"} # fmt: skip
3412+
reference_kinds: ClassVar[ModelReference] = {"successors": {"default": ["aws_ec2_snapshot"]}}
34123413
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("ec2", "describe-images", "Images", {"Owners": ["self"]})
34133414
mapping: ClassVar[Dict[str, Bender]] = {
34143415
"id": S("ImageId"),
@@ -3486,7 +3487,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
34863487
return
34873488
for bdm in self.block_device_mappings:
34883489
if bdm.ebs and bdm.ebs.snapshot_id:
3489-
builder.add_edge(self, EdgeType.default, reverse=False, clazz=AwsEc2Snapshot, id=bdm.ebs.snapshot_id)
3490+
builder.add_edge(self, EdgeType.default, clazz=AwsEc2Snapshot, id=bdm.ebs.snapshot_id)
34903491

34913492

34923493
@define(eq=False, slots=False)

plugins/aws/fix_plugin_aws/resource/opensearch.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from fix_plugin_aws.resource.cognito import AwsCognitoUserPool
1010
from fix_plugin_aws.resource.ec2 import AwsEc2Subnet, AwsEc2SecurityGroup, AwsEc2Vpc, AwsEc2InstanceType
1111
from fix_plugin_aws.utils import ToDict
12+
from fixlib.baseresources import ModelReference
1213
from fixlib.json_bender import Bender, S, Bend, ParseJson, Sorted
1314
from fixlib.types import Json
1415

@@ -251,6 +252,12 @@ class AwsOpenSearchDomain(AwsResource):
251252
kind_display: ClassVar[str] = "AWS OpenSearch Domain"
252253
kind_description: ClassVar[str] = "An AWS OpenSearch Domain provides a managed environment in the AWS cloud to easily deploy, operate, and scale OpenSearch, a popular search and analytics engine." # fmt: skip
253254
kind_service: ClassVar[Optional[str]] = service_name
255+
reference_kinds: ClassVar[ModelReference] = {
256+
"predecessors": {
257+
"default": [AwsEc2InstanceType.kind, AwsEc2Vpc.kind, AwsEc2SecurityGroup.kind, AwsEc2Subnet.kind]
258+
},
259+
"successors": {"default": [AwsCognitoUserPool.kind]},
260+
}
254261
metadata: ClassVar[Dict[str, Any]] = {"icon": "database", "group": "database"}
255262
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/aos/home?region={region}#opensearch/domains/{name}", "arn_tpl": "arn:{partition}:opensearch:{region}:{account}:domain/{name}"} # fmt: skip
256263
mapping: ClassVar[Dict[str, Bender]] = {

plugins/aws/fix_plugin_aws/resource/rds.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ class AwsRdsSnapshot(RdsTaggable, AwsResource, BaseSnapshot):
10661066
kind_display: ClassVar[str] = "AWS RDS Snapshot"
10671067
kind_description: ClassVar[str] = "An AWS RDS Snapshot is a backup tool used for creating a point-in-time copy of an RDS database instance, facilitating data recovery and replication." # fmt: skip
10681068
kind_service: ClassVar[Optional[str]] = service_name
1069+
reference_kinds: ClassVar[ModelReference] = {"predecessors": {"default": [AwsRdsInstance.kind, AwsEc2Vpc.kind]}}
10691070
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/rds/home?region={region}#db-snapshot:engine={Engine};id={id}", "arn_tpl": "arn:{partition}:rds:{region}:{account}:snapshot:{id}/{name}"} # fmt: skip
10701071
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("rds", "describe-db-snapshots", "DBSnapshots")
10711072
mapping: ClassVar[Dict[str, Bender]] = {
@@ -1166,6 +1167,10 @@ class AwsRdsClusterSnapshot(AwsResource):
11661167
kind_display: ClassVar[str] = "AWS RDS Cluster Snapshot"
11671168
kind_description: ClassVar[str] = "An AWS RDS Cluster Snapshot is a point-in-time backup of an Amazon RDS cluster that provides data persistence and recovery for disaster management." # fmt: skip
11681169
kind_service: ClassVar[Optional[str]] = service_name
1170+
reference_kinds: ClassVar[ModelReference] = {
1171+
"predecessors": {"default": [AwsRdsCluster.kind, AwsEc2Vpc.kind]},
1172+
"successors": {"default": [AwsKmsKey.kind]},
1173+
}
11691174
metadata: ClassVar[Dict[str, Any]] = {"icon": "snapshot", "group": "storage"}
11701175
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/rds/home?region={region}#db-snapshot:engine={Engine};id={id}", "arn_tpl": "arn:{partition}:rds:{region}:{account}:snapshot/{name}"} # fmt: skip
11711176
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("rds", "describe-db-cluster-snapshots", "DBClusterSnapshots")

plugins/aws/fix_plugin_aws/resource/secretsmanager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from fix_plugin_aws.resource.base import AwsResource, AwsApiSpec, GraphBuilder
77
from fix_plugin_aws.resource.kms import AwsKmsKey
88
from fix_plugin_aws.utils import ToDict
9+
from fixlib.baseresources import ModelReference
910
from fixlib.json_bender import Bender, S, Bend
1011
from fixlib.types import Json
1112

@@ -32,6 +33,7 @@ class AwsSecretsManagerSecret(AwsResource):
3233
kind_display: ClassVar[str] = "AWS Secrets Manager Secret"
3334
kind_description: ClassVar[str] = "An AWS Secrets Manager Secret is used for securely storing and managing sensitive information, such as passwords, API keys, and database credentials, in AWS environments." # fmt: skip
3435
kind_service: ClassVar[Optional[str]] = service_name
36+
reference_kinds: ClassVar[ModelReference] = {"successors": {"default": [AwsKmsKey.kind]}}
3537
metadata: ClassVar[Dict[str, Any]] = {"icon": "key", "group": "access_control"}
3638
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/secretsmanager/home?region={region}#/secret?name={name}", "arn_tpl": "arn:{partition}:secretsmanager:{region}:{account}:secret/{name}"} # fmt: skip
3739
mapping: ClassVar[Dict[str, Bender]] = {

plugins/aws/test/collector_test.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import threading
33
from contextlib import suppress
4-
from typing import Type, List, Tuple, Set
4+
from typing import Type, List, Tuple, Set, Any
55

66
from networkx import DiGraph, is_directed_acyclic_graph
77

@@ -13,6 +13,7 @@
1313
)
1414
from fix_plugin_aws.resource.base import AwsResource, AwsApiSpec, GraphBuilder, AwsRegion
1515
from fix_plugin_aws.resource.ec2 import AwsEc2Instance
16+
from fixlib.baseresources import BaseResource
1617
from fixlib.core.model_export import dataclasses_to_fixcore_model
1718
from test import account_collector, builder, aws_client, aws_config, no_feedback # noqa: F401
1819

@@ -93,3 +94,25 @@ def test_raise_error_if_configured(builder: GraphBuilder) -> None:
9394
# ignore any mapping exception
9495
builder.config.discard_account_on_resource_error = False
9596
assert AwsEc2Instance.from_api({"is": "wrong"}, builder) is None
97+
98+
99+
def test_resource_classes() -> None:
100+
def all_base_classes(cls: Type[Any]) -> Set[Type[Any]]:
101+
bases = set(cls.__bases__)
102+
for base in cls.__bases__:
103+
bases.update(all_base_classes(base))
104+
return bases
105+
106+
expected_declared_properties = ["kind", "kind_display"]
107+
expected_props_in_hierarchy = ["kind_service", "metadata"]
108+
for rc in all_resources:
109+
for prop in expected_declared_properties:
110+
assert prop in rc.__dict__, f"{rc.__name__} missing {prop}"
111+
with_bases = (all_base_classes(rc) | {rc}) - {AwsResource, BaseResource}
112+
for prop in expected_props_in_hierarchy:
113+
assert any(prop in base.__dict__ for base in with_bases), f"{rc.__name__} missing {prop}"
114+
for base in with_bases:
115+
if "connect_in_graph" in base.__dict__:
116+
assert (
117+
"reference_kinds" in base.__dict__
118+
), f"{rc.__name__} should define reference_kinds property, since it defines connect_in_graph"

plugins/azure/fix_plugin_azure/resource/authorization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class AzureAuthorizationManagementLock(MicrosoftResource):
265265
kind_display: ClassVar[str] = "Azure Authorization Management Lock"
266266
kind_service: ClassVar[Optional[str]] = "resources"
267267
metadata: ClassVar[Dict[str, Any]] = {"icon": "lock", "group": "access_control"}
268+
reference_kinds: ClassVar[ModelReference] = {"successors": {"default": [MicrosoftResource.kind]}}
268269
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
269270
service="resources",
270271
version="2020-05-01",

plugins/azure/fix_plugin_azure/resource/microsoft_graph.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ class MicrosoftGraphAssignedPlan:
248248
class MicrosoftGraphRole(MicrosoftGraphEntity, BaseRole):
249249
kind: ClassVar[str] = "microsoft_graph_role"
250250
kind_service: ClassVar[Optional[str]] = "entra_id"
251+
kind_display: ClassVar[str] = "Microsoft Graph Role"
252+
metadata: ClassVar[Dict[str, Any]] = {"icon": "role", "group": "access_control"}
251253
api_spec: ClassVar[MicrosoftRestSpec] = RestApiSpec(
252254
"graph",
253255
"https://graph.microsoft.com/beta/roleManagement/directory/roleDefinitions",
@@ -524,6 +526,8 @@ class MicrosoftGraphVerifiedDomain:
524526
class MicrosoftGraphServicePrincipal(MicrosoftGraphEntity):
525527
kind: ClassVar[str] = "microsoft_graph_service_principal"
526528
kind_service: ClassVar[Optional[str]] = "entra_id"
529+
kind_display: ClassVar[str] = "Microsoft Graph Service Principal"
530+
metadata: ClassVar[Dict[str, Any]] = {"icon": "user", "group": "access_control"}
527531
api_spec: ClassVar[MicrosoftRestSpec] = RestApiSpec(
528532
"graph",
529533
"https://graph.microsoft.com/v1.0/serviceprincipals",
@@ -631,6 +635,8 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
631635
class MicrosoftGraphDevice(MicrosoftGraphEntity):
632636
kind: ClassVar[str] = "microsoft_graph_device"
633637
kind_service: ClassVar[Optional[str]] = "entra_id"
638+
kind_display: ClassVar[str] = "Microsoft Graph Device"
639+
metadata: ClassVar[Dict[str, Any]] = {"icon": "resource", "group": "access_control"}
634640
api_spec: ClassVar[MicrosoftRestSpec] = RestApiSpec(
635641
"graph",
636642
"https://graph.microsoft.com/v1.0/devices",
@@ -729,6 +735,8 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
729735
class MicrosoftGraphUser(MicrosoftGraphEntity, BaseUser):
730736
kind: ClassVar[str] = "microsoft_graph_user"
731737
kind_service: ClassVar[Optional[str]] = "entra_id"
738+
kind_display: ClassVar[str] = "Microsoft Graph User"
739+
metadata: ClassVar[Dict[str, Any]] = {"icon": "user", "group": "access_control"}
732740
api_spec: ClassVar[MicrosoftRestSpec] = RestApiSpec(
733741
"graph",
734742
"https://graph.microsoft.com/v1.0/users",
@@ -897,6 +905,8 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
897905
class MicrosoftGraphGroup(MicrosoftGraphEntity, BaseGroup):
898906
kind: ClassVar[str] = "microsoft_graph_group"
899907
kind_service: ClassVar[Optional[str]] = "entra_id"
908+
kind_display: ClassVar[str] = "Microsoft Graph Group"
909+
metadata: ClassVar[Dict[str, Any]] = {"icon": "group", "group": "access_control"}
900910
api_spec: ClassVar[MicrosoftRestSpec] = RestApiSpec(
901911
"graph",
902912
"https://graph.microsoft.com/v1.0/groups",
@@ -1127,6 +1137,8 @@ class MicrosoftGraphOrganizationRoot(MicrosoftGraphEntity, BaseRegion):
11271137
class MicrosoftGraphPolicy(MicrosoftGraphEntity):
11281138
kind: ClassVar[str] = "microsoft_graph_policy"
11291139
kind_service: ClassVar[Optional[str]] = "entra_id"
1140+
kind_display: ClassVar[str] = "Microsoft Graph Policy"
1141+
metadata: ClassVar[Dict[str, Any]] = {"icon": "policy", "group": "access_control"}
11301142

11311143
policy_kind: Optional[str] = field(default=None, metadata={"description": "The kind of policy."})
11321144
enabled: Optional[bool] = field(default=None, metadata={"description": "Indicates whether the policy is enabled."})

plugins/azure/fix_plugin_azure/resource/mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class AzureMysqlServerADAdministrator(MicrosoftResource):
108108
kind_display: ClassVar[str] = "Azure MySQL Server Ad Administrator"
109109
kind_service: ClassVar[Optional[str]] = service_name
110110
metadata: ClassVar[Dict[str, Any]] = {"icon": "user", "group": "database"}
111+
reference_kinds: ClassVar[ModelReference] = {"successors": {"default": [MicrosoftGraphUser.kind]}}
111112
# Collect via AzureMysqlServer()
112113
mapping: ClassVar[Dict[str, Bender]] = {
113114
"id": S("id"),

plugins/azure/fix_plugin_azure/resource/security.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from fix_plugin_azure.azure_client import AzureResourceSpec
77
from fix_plugin_azure.resource.base import MicrosoftResource, AzureSystemData, GraphBuilder
8+
from fixlib.baseresources import ModelReference
89
from fixlib.json_bender import Bender, S, Bend, ForallBend, F
910
from fixlib.types import Json
1011

@@ -94,6 +95,7 @@ class AzureSecurityAssessment(MicrosoftResource):
9495
kind_display: ClassVar[str] = "Azure Security Assessment"
9596
kind_service: ClassVar[Optional[str]] = service_name
9697
metadata: ClassVar[Dict[str, Any]] = {"icon": "log", "group": "control"}
98+
reference_kinds: ClassVar[ModelReference] = {"successors": {"default": [MicrosoftResource.kind]}}
9799
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
98100
service=service_name,
99101
version="2021-06-01",

plugins/azure/fix_plugin_azure/resource/sql_server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class AzureSqlServerADAdministrator(MicrosoftResource):
3131
kind_display: ClassVar[str] = "Azure SQL Server Ad Administrator"
3232
kind_service: ClassVar[Optional[str]] = service_name
3333
metadata: ClassVar[Dict[str, Any]] = {"icon": "user", "group": "database"}
34+
reference_kinds: ClassVar[ModelReference] = {"successors": {"default": [MicrosoftResource.kind]}}
3435
# Collect via AzureSqlServer()
3536
mapping: ClassVar[Dict[str, Bender]] = {
3637
"id": S("id"),
@@ -629,6 +630,7 @@ class AzureSqlServerManagedInstanceADAdministrator(MicrosoftResource):
629630
kind_display: ClassVar[str] = "Azure SQL Server Managed Instance Ad Administrator"
630631
kind_service: ClassVar[Optional[str]] = service_name
631632
metadata: ClassVar[Dict[str, Any]] = {"icon": "user", "group": "access_control"}
633+
reference_kinds: ClassVar[ModelReference] = {"successors": {"default": [MicrosoftResource.kind]}}
632634
# Collect via AzureSqlManagedInstance()
633635
mapping: ClassVar[Dict[str, Bender]] = {
634636
"id": S("id"),
@@ -1119,6 +1121,7 @@ class AzureSqlServerDatabaseWorkloadGroup(MicrosoftResource):
11191121
kind: ClassVar[str] = "azure_sql_server_database_workload_group"
11201122
kind_display: ClassVar[str] = "Azure SQL Server Database Workload Group"
11211123
kind_service: ClassVar[Optional[str]] = service_name
1124+
metadata: ClassVar[Dict[str, Any]] = {"icon": "group", "group": "compute"}
11221125
# Collect via AzureSqlServerDatabase()
11231126
mapping: ClassVar[Dict[str, Bender]] = {
11241127
"id": S("id"),

0 commit comments

Comments
 (0)