From ccd6657378a5daf6e3eacc90af2ce0f6203028cf Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 11 Nov 2024 11:38:50 +0000 Subject: [PATCH] feat: added more properties --- fixlib/fixlib/baseresources.py | 13 +++++++++++-- plugins/aws/fix_plugin_aws/resource/acm.py | 1 + plugins/aws/fix_plugin_aws/resource/cognito.py | 1 + plugins/aws/fix_plugin_aws/resource/ec2.py | 1 - plugins/aws/fix_plugin_aws/resource/iam.py | 1 + plugins/aws/fix_plugin_aws/resource/route53.py | 4 ++-- plugins/aws/fix_plugin_aws/resource/sqs.py | 10 ++++++++-- .../fix_plugin_azure/resource/microsoft_graph.py | 1 + plugins/azure/fix_plugin_azure/resource/network.py | 13 ++++++++++--- plugins/azure/fix_plugin_azure/resource/storage.py | 7 ++++--- 10 files changed, 39 insertions(+), 13 deletions(-) diff --git a/fixlib/fixlib/baseresources.py b/fixlib/fixlib/baseresources.py index 480f21beb7..a931cf3f30 100644 --- a/fixlib/fixlib/baseresources.py +++ b/fixlib/fixlib/baseresources.py @@ -1100,6 +1100,11 @@ class BaseQueue(BaseResource): _kind_description: ClassVar[str] = "A storage queue." _metadata: ClassVar[Dict[str, Any]] = {"icon": "queue", "group": "storage"} _categories: ClassVar[List[Category]] = [Category.storage] + # Type of queue (e.g., standard, FIFO) + queue_type: Optional[str] = None + approximate_message_count: Optional[int] = None + # Message retention period in seconds + message_retention_period: Optional[int] = None @define(eq=False, slots=False) @@ -1339,6 +1344,8 @@ class BaseUser(BaseResource): _kind_description: ClassVar[str] = "A user." _metadata: ClassVar[Dict[str, Any]] = {"icon": "user", "group": "access_control"} _categories: ClassVar[List[Category]] = [Category.access_control] + # Name associated with the user account + username: Optional[str] = None @define(eq=False, slots=False) @@ -1383,8 +1390,8 @@ class BaseAccessKey(BaseResource): _kind_display: ClassVar[str] = "Access Key" _kind_description: ClassVar[str] = "An access key." _metadata: ClassVar[Dict[str, Any]] = {"icon": "key", "group": "access_control"} - access_key_status: str = "" _categories: ClassVar[List[Category]] = [Category.access_control, Category.security] + access_key_status: str = "" @define(eq=False, slots=False) @@ -1413,10 +1420,10 @@ class BaseStack(BaseResource): _kind_display: ClassVar[str] = "Stack" _kind_description: ClassVar[str] = "A stack." _metadata: ClassVar[Dict[str, Any]] = {"icon": "stack", "group": "management"} + _categories: ClassVar[List[Category]] = [Category.devops, Category.management] stack_status: str = "" stack_status_reason: str = "" stack_parameters: Dict[str, str] = field(factory=dict) - _categories: ClassVar[List[Category]] = [Category.devops, Category.management] @define(eq=False, slots=False) @@ -1462,6 +1469,8 @@ class BaseDNSZone(BaseResource): _kind_description: ClassVar[str] = "A DNS zone." _metadata: ClassVar[Dict[str, Any]] = {"icon": "dns", "group": "networking"} _categories: ClassVar[List[Category]] = [Category.dns, Category.networking] + private_zone: Optional[bool] = None + zone_resource_record_set_count: Optional[int] = field(default=None, metadata=dict(ignore_history=True)) @define(eq=False, slots=False) diff --git a/plugins/aws/fix_plugin_aws/resource/acm.py b/plugins/aws/fix_plugin_aws/resource/acm.py index 8a12298791..9b7e4c0115 100644 --- a/plugins/aws/fix_plugin_aws/resource/acm.py +++ b/plugins/aws/fix_plugin_aws/resource/acm.py @@ -80,6 +80,7 @@ class AwsAcmCertificate(AwsResource, BaseCertificate): "tags": S("Tags", default=[]) >> ToDict(), "name": S("DomainName"), "ctime": S("CreatedAt"), + "mtime": S("RenewalSummary", "UpdatedAt"), "arn": S("CertificateArn"), "subject_alternative_names": S("SubjectAlternativeNames", default=[]), "domain_validation_options": S("DomainValidationOptions", default=[]) diff --git a/plugins/aws/fix_plugin_aws/resource/cognito.py b/plugins/aws/fix_plugin_aws/resource/cognito.py index c2cdd3e0ae..ebc39fbdbd 100644 --- a/plugins/aws/fix_plugin_aws/resource/cognito.py +++ b/plugins/aws/fix_plugin_aws/resource/cognito.py @@ -113,6 +113,7 @@ class AwsCognitoUser(AwsResource, BaseUser): "enabled": S("Enabled"), "user_status": S("UserStatus"), "mfa_options": S("MFAOptions", default=[]) >> ForallBend(AwsCognitoMFAOptionType.mapping), + "username": S("Username"), } user_attributes: List[AwsCognitoAttributeType] = field(factory=list) enabled: Optional[bool] = field(default=None) diff --git a/plugins/aws/fix_plugin_aws/resource/ec2.py b/plugins/aws/fix_plugin_aws/resource/ec2.py index ff658110e4..2a21b2f097 100644 --- a/plugins/aws/fix_plugin_aws/resource/ec2.py +++ b/plugins/aws/fix_plugin_aws/resource/ec2.py @@ -23,7 +23,6 @@ from fix_plugin_aws.resource.kms import AwsKmsKey from fix_plugin_aws.resource.s3 import AwsS3Bucket from fix_plugin_aws.utils import ToDict, TagsValue -from fix_plugin_aws.aws_client import AwsClient from fixlib.baseresources import ( BaseInstance, BaseKeyPair, diff --git a/plugins/aws/fix_plugin_aws/resource/iam.py b/plugins/aws/fix_plugin_aws/resource/iam.py index bdf6b15a39..ced7704b64 100644 --- a/plugins/aws/fix_plugin_aws/resource/iam.py +++ b/plugins/aws/fix_plugin_aws/resource/iam.py @@ -654,6 +654,7 @@ class AwsIamUser(AwsResource, BaseUser, BaseIamPrincipal): "arn": S("Arn"), "user_policies": S("UserPolicyList", default=[]) >> ForallBend(AwsIamPolicyDetail.mapping), "user_permissions_boundary": S("PermissionsBoundary") >> Bend(AwsIamAttachedPermissionsBoundary.mapping), + "username": S("UserName"), } path: Optional[str] = field(default=None) user_policies: List[AwsIamPolicyDetail] = field(factory=list) diff --git a/plugins/aws/fix_plugin_aws/resource/route53.py b/plugins/aws/fix_plugin_aws/resource/route53.py index c92f2c4659..8202924b8e 100644 --- a/plugins/aws/fix_plugin_aws/resource/route53.py +++ b/plugins/aws/fix_plugin_aws/resource/route53.py @@ -81,12 +81,12 @@ class AwsRoute53Zone(AwsResource, BaseDNSZone): "name": S("Name"), "zone_caller_reference": S("CallerReference"), "zone_config": S("Config") >> Bend(AwsRoute53ZoneConfig.mapping), - "zone_resource_record_set_count": S("ResourceRecordSetCount"), "zone_linked_service": S("LinkedService") >> Bend(AwsRoute53LinkedService.mapping), + "private_zone": S("Config", "PrivateZone"), + "zone_resource_record_set_count": S("ResourceRecordSetCount"), } zone_caller_reference: Optional[str] = field(default=None) zone_config: Optional[AwsRoute53ZoneConfig] = field(default=None) - zone_resource_record_set_count: Optional[int] = field(default=None, metadata=dict(ignore_history=True)) zone_linked_service: Optional[AwsRoute53LinkedService] = field(default=None) zone_logging_config: Optional[AwsRoute53LoggingConfig] = field(default=None) diff --git a/plugins/aws/fix_plugin_aws/resource/sqs.py b/plugins/aws/fix_plugin_aws/resource/sqs.py index ebaa8923be..4e0723a7bb 100644 --- a/plugins/aws/fix_plugin_aws/resource/sqs.py +++ b/plugins/aws/fix_plugin_aws/resource/sqs.py @@ -80,6 +80,8 @@ class AwsSqsQueue(AwsResource, BaseQueue, HasResourcePolicy): "sqs_delay_seconds": S("DelaySeconds") >> AsInt(), "sqs_receive_message_wait_time_seconds": S("ReceiveMessageWaitTimeSeconds") >> AsInt(), "sqs_managed_sse_enabled": S("SqsManagedSseEnabled") >> AsBool(), + "message_retention_period": S("MessageRetentionPeriod") >> AsInt(), + "approximate_message_count": S("ApproximateNumberOfMessages") >> AsInt(), } sqs_queue_url: Optional[str] = field(default=None) sqs_approximate_number_of_messages: Optional[int] = field(default=None, metadata=dict(ignore_history=True)) @@ -118,7 +120,7 @@ def called_collect_apis(cls) -> List[AwsApiSpec]: ] @classmethod - def collect(cls: Type[AwsResource], json: List[Json], builder: GraphBuilder) -> None: + def collect(cls, json: List[Json], builder: GraphBuilder) -> None: def add_instance(queue_url: str) -> None: queue_attributes = builder.client.get( service_name, "get-queue-attributes", "Attributes", QueueUrl=queue_url, AttributeNames=["All"] @@ -126,8 +128,12 @@ def add_instance(queue_url: str) -> None: if queue_attributes is not None: queue_attributes["QueueUrl"] = queue_url queue_attributes["QueueName"] = queue_url.rsplit("/", 1)[-1] - if instance := cls.from_api(queue_attributes, builder): + if instance := AwsSqsQueue.from_api(queue_attributes, builder): builder.add_node(instance, queue_attributes) + if instance.sqs_fifo_queue: + instance.queue_type = "FIFO" + else: + instance.queue_type = "default" builder.submit_work(service_name, add_tags, instance) def add_tags(queue: AwsSqsQueue) -> None: diff --git a/plugins/azure/fix_plugin_azure/resource/microsoft_graph.py b/plugins/azure/fix_plugin_azure/resource/microsoft_graph.py index 9b90b9e145..b77d159a20 100644 --- a/plugins/azure/fix_plugin_azure/resource/microsoft_graph.py +++ b/plugins/azure/fix_plugin_azure/resource/microsoft_graph.py @@ -826,6 +826,7 @@ class MicrosoftGraphUser(MicrosoftGraphEntity, BaseUser): "usage_location": S("usageLocation"), "user_principal_name": S("userPrincipalName"), "user_type": S("userType"), + "username": S("displayName"), } account_enabled: Optional[bool] = field(default=None, metadata={'description': 'true if the account is enabled; otherwise, false. This property is required when a user is created. Supports $filter (eq, ne, not, and in).'}) # fmt: skip age_group: Optional[str] = field(default=None, metadata={'description': 'Sets the age group of the user. Allowed values: null, Minor, NotAdult, and Adult. For more information, see legal age group property definitions. Supports $filter (eq, ne, not, and in).'}) # fmt: skip diff --git a/plugins/azure/fix_plugin_azure/resource/network.py b/plugins/azure/fix_plugin_azure/resource/network.py index 636372fcda..a33fda4ce6 100644 --- a/plugins/azure/fix_plugin_azure/resource/network.py +++ b/plugins/azure/fix_plugin_azure/resource/network.py @@ -40,7 +40,7 @@ EdgeType, PhantomBaseResource, ) -from fixlib.json_bender import F, Bender, S, Bend, ForallBend, AsInt, StringToUnitNumber, Upper, Lower +from fixlib.json_bender import F, MapValue, Bender, S, Bend, ForallBend, AsInt, StringToUnitNumber, Upper, Lower from fixlib.types import Json service_name = "networking" @@ -6791,7 +6791,15 @@ class AzureNetworkDNSZone(MicrosoftResource, BaseDNSZone): "resolution_virtual_networks": S("properties") >> S("resolutionVirtualNetworks", default=[]) >> ForallBend(S("id")), - "zone_type": S("properties", "zoneType"), + "private_zone": S("properties", "zoneType") + >> MapValue( + { + "Public": False, + "Private": True, + }, + default=False, + ), + "zone_resource_record_set_count": S("properties", "maxNumberOfRecordSets"), } max_number_of_record_sets: Optional[int] = field(default=None, metadata={'description': 'The maximum number of record sets that can be created in this DNS zone. This is a read-only property and any attempt to set this value will be ignored.'}) # fmt: skip max_number_of_records_per_record_set: Optional[int] = field(default=None, metadata={'description': 'The maximum number of records per record set that can be created in this DNS zone. This is a read-only property and any attempt to set this value will be ignored.'}) # fmt: skip @@ -6799,7 +6807,6 @@ class AzureNetworkDNSZone(MicrosoftResource, BaseDNSZone): number_of_record_sets: Optional[int] = field(default=None, metadata={'description': 'The current number of record sets in this DNS zone. This is a read-only property and any attempt to set this value will be ignored.'}) # fmt: skip registration_virtual_networks: Optional[List[str]] = field(default=None, metadata={'description': 'A list of references to virtual networks that register hostnames in this DNS zone. This is a only when ZoneType is Private.'}) # fmt: skip resolution_virtual_networks: Optional[List[str]] = field(default=None, metadata={'description': 'A list of references to virtual networks that resolve records in this DNS zone. This is a only when ZoneType is Private.'}) # fmt: skip - zone_type: Optional[str] = field(default=None, metadata={'description': 'The type of this DNS zone (Public or Private).'}) # fmt: skip def post_process(self, graph_builder: GraphBuilder, source: Json) -> None: def collect_record_sets() -> None: diff --git a/plugins/azure/fix_plugin_azure/resource/storage.py b/plugins/azure/fix_plugin_azure/resource/storage.py index 5afe721502..a4cb9e9169 100644 --- a/plugins/azure/fix_plugin_azure/resource/storage.py +++ b/plugins/azure/fix_plugin_azure/resource/storage.py @@ -27,7 +27,7 @@ ModelReference, PhantomBaseResource, ) -from fixlib.json_bender import Bender, S, ForallBend, Bend, AsBool +from fixlib.json_bender import K, Bender, S, ForallBend, Bend, AsBool from fixlib.types import Json log = logging.getLogger("fix.plugins.azure") @@ -318,10 +318,11 @@ class AzureStorageQueue(MicrosoftResource, BaseQueue): "id": S("id"), "tags": S("tags", default={}), "name": S("name"), - "approximate_message_count": S("properties", "approximateMessageCount"), "queue_metadata": S("properties", "metadata"), + "queue_type": K("default"), + "message_retention_period": K(7), + "approximate_message_count": S("properties", "approximateMessageCount"), } - approximate_message_count: Optional[int] = field(default=None, metadata={'description': 'Integer indicating an approximate number of messages in the queue. This number is not lower than the actual number of messages in the queue, but could be higher.'}) # fmt: skip queue_metadata: Optional[Dict[str, str]] = field(default=None, metadata={'description': 'A name-value pair that represents queue metadata.'}) # fmt: skip