Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat][fixlib] Extend base resources with additional common properties #2278

Merged
merged 17 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: added more properties
  • Loading branch information
1101-1 committed Nov 11, 2024
commit ccd6657378a5daf6e3eacc90af2ce0f6203028cf
13 changes: 11 additions & 2 deletions fixlib/fixlib/baseresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
1101-1 marked this conversation as resolved.
Show resolved Hide resolved


@define(eq=False, slots=False)
Expand Down
1 change: 1 addition & 0 deletions plugins/aws/fix_plugin_aws/resource/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[])
Expand Down
1 change: 1 addition & 0 deletions plugins/aws/fix_plugin_aws/resource/cognito.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion plugins/aws/fix_plugin_aws/resource/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions plugins/aws/fix_plugin_aws/resource/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions plugins/aws/fix_plugin_aws/resource/route53.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 8 additions & 2 deletions plugins/aws/fix_plugin_aws/resource/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -118,16 +120,20 @@ 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"]
)
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions plugins/azure/fix_plugin_azure/resource/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -6791,15 +6791,22 @@ 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
name_servers: Optional[List[str]] = field(default=None, metadata={'description': 'The name servers for this DNS zone. This is a read-only property and any attempt to set this value will be ignored.'}) # fmt: skip
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:
Expand Down
7 changes: 4 additions & 3 deletions plugins/azure/fix_plugin_azure/resource/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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


Expand Down
Loading