Skip to content

Commit

Permalink
[aws][fix] Define missing AWS Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias committed Jan 10, 2024
1 parent 4725be5 commit eef2439
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/aws/resoto_plugin_aws/resource/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class AwsAcmExtendedKeyUsage:
@define(eq=False, slots=False)
class AwsAcmCertificate(AwsResource):
kind: ClassVar[str] = "aws_acm_certificate"
kind_display: ClassVar[str] = "AWS ACM Certificate"
kind_description: ClassVar[str] = "An AWS ACM Certificate is used to provision, manage, and deploy Secure Sockets Layer/Transport Layer Security (SSL/TLS) certificates for secure web traffic on AWS services." # fmt: skip
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("acm", "describe-certificate", "Certificate")
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("DomainName"),
Expand Down
2 changes: 2 additions & 0 deletions plugins/aws/resoto_plugin_aws/resource/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3799,6 +3799,8 @@ class AwsEc2LaunchTemplateData:
@define(eq=False, slots=False)
class AwsEc2LaunchTemplate(EC2Taggable, AwsResource):
kind: ClassVar[str] = "aws_ec2_launch_template"
kind_display: ClassVar[str] = "AWS EC2 Launch Template"
kind_description: ClassVar[str] = "An AWS EC2 Launch Template provides a configurable blueprint for launching EC2 instances, allowing for the specification of settings like instance type, AMI, security groups, and block device mappings for consistency and automation in instance creation." # fmt: skip
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec(
"ec2", "describe-launch-template-versions", "LaunchTemplateVersions", {"Versions": ["$Default", "$Latest"]}
)
Expand Down
2 changes: 2 additions & 0 deletions plugins/aws/resoto_plugin_aws/resource/ecr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class AwsEcrEncryptionConfiguration:
@define(eq=False, slots=False)
class AwsEcrRepository(AwsResource):
kind: ClassVar[str] = "aws_ecr_repository"
kind_display: ClassVar[str] = "AWS ECR Repository"
kind_description: ClassVar[str] = "An AWS Elastic Container Registry (ECR) Repository is used for storing, managing, and deploying Docker container images in a secure, scalable, and private environment on AWS." # fmt: skip
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("ecr", "describe-repositories", "repositories")
public_spec: ClassVar[AwsApiSpec] = AwsApiSpec("ecr-public", "describe-repositories", "repositories")
mapping: ClassVar[Dict[str, Bender]] = {
Expand Down
2 changes: 2 additions & 0 deletions plugins/aws/resoto_plugin_aws/resource/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class AwsOpenSearchOffPeakWindowOptions:
@define(eq=False, slots=False)
class AwsOpenSearchDomain(AwsResource):
kind: ClassVar[str] = "aws_opensearch_domain"
kind_display: ClassVar[str] = "AWS OpenSearch Domain"
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
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("DomainId"),
"tags": S("Tags", default=[]) >> ToDict(),
Expand Down
4 changes: 4 additions & 0 deletions plugins/aws/resoto_plugin_aws/resource/rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,8 @@ def called_mutator_apis(cls) -> List[AwsApiSpec]:
@define(eq=False, slots=False)
class AwsRdsSnapshot(RdsTaggable, AwsResource, BaseSnapshot):
kind: ClassVar[str] = "aws_rds_snapshot"
kind_display: ClassVar[str] = "AWS RDS Snapshot"
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
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("rds", "describe-db-snapshots", "DBSnapshots")
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("DBSnapshotIdentifier"),
Expand Down Expand Up @@ -981,6 +983,8 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
@define(eq=False, slots=False)
class AwsRdsClusterSnapshot(AwsResource):
kind: ClassVar[str] = "aws_rds_cluster_snapshot"
kind_display: ClassVar[str] = "AWS RDS Cluster Snapshot"
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
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("rds", "describe-db-cluster-snapshots", "DBClusterSnapshots")
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("DBClusterSnapshotIdentifier"),
Expand Down
2 changes: 2 additions & 0 deletions plugins/aws/resoto_plugin_aws/resource/secretsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class AwsSecretsManagerRotationRulesType:
class AwsSecretsManagerSecret(AwsResource):
kind: ClassVar[str] = "aws_secretsmanager_secret"
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec(service_name, "list-secrets", "SecretList")
kind_display: ClassVar[str] = "AWS Secrets Manager Secret"
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
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("Name"),
"tags": S("Tags", default=[]) >> ToDict(),
Expand Down
6 changes: 6 additions & 0 deletions plugins/aws/resoto_plugin_aws/resource/ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class AwsSSMInstanceAggregatedAssociationOverview:
@define(eq=False, slots=False)
class AwsSSMInstance(AwsResource):
kind: ClassVar[str] = "aws_ssm_instance"
kind_display: ClassVar[str] = "AWS SSM Instance"
kind_description: ClassVar[str] = "An AWS SSM Instance refers to an EC2 instance or a managed node that has been configured for management by AWS Systems Manager, enabling centralized and automated management of configuration, security, and software updates." # fmt: skip
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("ssm", "describe-instance-information", "InstanceInformationList")
reference_kinds: ClassVar[ModelReference] = {
"successors": {"default": ["aws_ec2_instance"]},
Expand Down Expand Up @@ -147,6 +149,8 @@ class AwsSSMAccountSharingInfo:
@define(eq=False, slots=False)
class AwsSSMDocument(AwsResource):
kind: ClassVar[str] = "aws_ssm_document"
kind_display: ClassVar[str] = "AWS SSM Document"
kind_description: ClassVar[str] = "An AWS Systems Manager (SSM) Document defines the actions that Systems Manager performs on your managed instances and other AWS resources." # fmt: skip
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("Name"),
"tags": S("Tags", default=[]) >> ToDict(),
Expand Down Expand Up @@ -343,6 +347,8 @@ class AwsSSMNonCompliantSummary:
@define(eq=False, slots=False)
class AwsSSMResourceCompliance(AwsResource):
kind: ClassVar[str] = "aws_ssm_resource_compliance"
kind_display: ClassVar[str] = "AWS SSM Resource Compliance"
kind_description: ClassVar[str] = "AWS SSM Resource Compliance is used to track the compliance status of your resources in relation to your AWS Systems Manager (SSM) configurations and policies." # fmt: skip
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec(
"ssm", "list-resource-compliance-summaries", "ResourceComplianceSummaryItems"
)
Expand Down
2 changes: 2 additions & 0 deletions plugins/aws/resoto_plugin_aws/resource/waf.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ class AwsWafLoggingConfiguration:
@define(eq=False, slots=False)
class AwsWafWebACL(AwsResource):
kind: ClassVar[str] = "aws_waf_web_acl"
kind_display: ClassVar[str] = "AWS WAF Web ACL"
kind_description: ClassVar[str] = "An AWS WAF Web ACL (Web Access Control List) is used for monitoring HTTP and HTTPS requests directed to AWS resources, allowing you to control access by permitting or blocking specific requests based on defined criteria." # fmt: skip
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("wafv2", "get-web-acl", "WebACL")
reference_kinds: ClassVar[ModelReference] = {
"successors": {"default": ["aws_alb", "aws_apigateway_rest_api", "aws_cognito_user_pool"]}
Expand Down
14 changes: 14 additions & 0 deletions resotolib/resotolib/core/model_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from attrs import define

from resotolib.baseresources import BaseResource
from resotolib.core.model_export import transitive_classes
from resotolib.graph import resource_classes_to_resotocore_model
from resotolib.json import from_json
from resotolib.types import Json
Expand Down Expand Up @@ -96,6 +97,14 @@ def add_path(path: List[str], kinds: List[CheckClass], model: CheckClass) -> Non
raise AttributeError(f"Successor kind {kind} does not exist")


def check_model_class(clazz: Type[BaseResource]) -> None:
if clazz.__name__.startswith("Aws"): # Currently only AWS resources provide this information
if "kind_display" not in vars(clazz):
raise AttributeError(f"Class {clazz.__name__} does not have a kind_display attribute")
if "kind_description" not in vars(clazz):
raise AttributeError(f"Class {clazz.__name__} does not have a kind_description attribute")


def load_plugin_classes(*base: Type[BaseResource]) -> Set[Type[BaseResource]]:
def dynamic_import(name: str) -> List[Type[Any]]:
components = name.split(".")
Expand Down Expand Up @@ -141,4 +150,9 @@ def check_overlap(*base: Type[BaseResource]) -> None:
"""

model_classes = load_plugin_classes(*base)
for model in transitive_classes(model_classes):
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)

check_overlap_for(resource_classes_to_resotocore_model(model_classes, aggregate_root=BaseResource))

0 comments on commit eef2439

Please sign in to comment.