Skip to content

Commit

Permalink
#97 added more diagrams.net icons
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykorwat committed Nov 10, 2020
1 parent 34e8437 commit 7d7ecd3
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 60 deletions.
74 changes: 14 additions & 60 deletions cloudiscovery/shared/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
from diagrams import Diagram, Cluster, Edge

from shared.common import Resource, ResourceEdge, ResourceDigest, message_handler
from shared.diagramsnet import DIAGRAM_HEADER, DIAGRAM_SUFFIX, MX_FILE, CELL_TEMPLATE
from shared.diagramsnet import (
DIAGRAM_HEADER,
DIAGRAM_SUFFIX,
MX_FILE,
CELL_TEMPLATE,
build_styles,
)
from shared.error_handler import exception

PATH_DIAGRAM_OUTPUT = "./assets/diagrams/"
Expand Down Expand Up @@ -223,59 +229,7 @@ class Mapsources:
"aws_vpn_client_endpoint": "ClientVpn",
}

styles = {
"aws_vpn_gateway": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#5A30B5;strokeColor=none;"
"dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;"
"fontStyle=0;aspect=fixed;pointerEvents=1;shape=mxgraph.aws4.vpn_gateway;",
"aws_general": "gradientDirection=north;outlineConnect=0;fontColor=#232F3E;gradientColor=#505863;"
"fillColor=#1E262E;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;"
"align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;"
"resIcon=mxgraph.aws4.general;",
"aws_lambda_function": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#D05C17;"
"strokeColor=none;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;"
"html=1;fontSize=12;fontStyle=0;aspect=fixed;pointerEvents=1;"
"shape=mxgraph.aws4.lambda_function;",
"aws_route_table": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#5A30B5;strokeColor=none;"
"dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;"
"fontStyle=0;aspect=fixed;pointerEvents=1;shape=mxgraph.aws4.route_table;",
"aws_internet_gateway": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#5A30B5;"
"strokeColor=none;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;"
"align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;pointerEvents=1;"
"shape=mxgraph.aws4.internet_gateway;",
"aws_elb": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#5A30B5;strokeColor=none;"
"dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;"
"fontStyle=0;aspect=fixed;pointerEvents=1;shape=mxgraph.aws4.application_load_balancer;",
"aws_network_acl": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#5A30B5;strokeColor=none;"
"dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;"
"fontStyle=0;aspect=fixed;pointerEvents=1;shape=mxgraph.aws4.network_access_control_list;",
"aws_vpc_endpoint_gateway": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#5A30B5;"
"strokeColor=none;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;"
"align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;pointerEvents=1;"
"shape=mxgraph.aws4.endpoint;",
"aws_ecs_cluster": "outlineConnect=0;fontColor=#232F3E;gradientColor=#F78E04;gradientDirection=north;"
"fillColor=#D05C17;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;"
"verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;"
"shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.ecs;",
"aws_instance": "outlineConnect=0;fontColor=#232F3E;gradientColor=#F78E04;gradientDirection=north;"
"fillColor=#D05C17;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;"
"verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;"
"shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.ec2;",
"aws_s3": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#277116;strokeColor=none;"
"dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;"
"fontStyle=0;aspect=fixed;pointerEvents=1;shape=mxgraph.aws4.bucket;",
"aws_db_instance": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#3334B9;strokeColor=none;"
"dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;"
"fontStyle=0;aspect=fixed;pointerEvents=1;shape=mxgraph.aws4.rds_instance;",
"aws_dynamodb": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#3334B9;strokeColor=none;"
"dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;"
"fontStyle=0;aspect=fixed;pointerEvents=1;shape=mxgraph.aws4.table;",
"aws_sqs": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#BC1356;strokeColor=none;dashed=0;"
"verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;"
"aspect=fixed;pointerEvents=1;shape=mxgraph.aws4.queue;",
"aws_sns_topic": "outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#BC1356;strokeColor=none;"
"dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;"
"fontStyle=0;aspect=fixed;pointerEvents=1;shape=mxgraph.aws4.topic;",
}
resource_styles = build_styles()


def add_resource_to_group(ordered_resources, group, resource):
Expand Down Expand Up @@ -562,9 +516,9 @@ def build_diagram(
if resource.digest not in added_resources:
added_resources.append(resource.digest)
style = (
Mapsources.styles[resource.digest.type]
if resource.digest.type in Mapsources.styles
else Mapsources.styles["aws_general"]
Mapsources.resource_styles[resource.digest.type]
if resource.digest.type in Mapsources.resource_styles
else Mapsources.resource_styles["aws_general"]
)
cell = CELL_TEMPLATE.format_map(
{
Expand Down Expand Up @@ -608,9 +562,9 @@ def render_subnet_items(
):
added_resources.append(relation.from_node)
style = (
Mapsources.styles[relation.from_node.type]
if relation.from_node.type in Mapsources.styles
else Mapsources.styles["aws_general"]
Mapsources.resource_styles[relation.from_node.type]
if relation.from_node.type in Mapsources.resource_styles
else Mapsources.resource_styles["aws_general"]
)

cell = CELL_TEMPLATE.format_map(
Expand Down
235 changes: 235 additions & 0 deletions cloudiscovery/shared/diagramsnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,238 @@
<mxGeometry x="{X}" y="{Y}" width="50" height="50" as="geometry" />
</mxCell>
"""


# from https://github.com/jgraph/drawio/blob/master/src/main/webapp/js/diagramly/sidebar/Sidebar-AWS4.js
gn = "mxgraph.aws4"

s = 1
w = s * 100
h = s * 100
w2 = s * 78


def _add_general_resources(styles):
n3 = (
"gradientDirection=north;outlineConnect=0;fontColor=#232F3E;gradientColor=#505863;fillColor=#1E262E;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_general"] = n3 + "resourceIcon;resIcon=" + gn + ".general;"


def _add_analytics_resources(styles):
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#945DF2;gradientDirection=north;fillColor=#5A30B5;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)
styles["aws_athena"] = n2 + "resourceIcon;resIcon=" + gn + ".athena;"
styles["aws_elasticsearch_domain"] = (
n2 + "resourceIcon;resIcon=" + gn + ".elasticsearch_service;"
)
styles["aws_emr"] = n2 + "resourceIcon;resIcon=" + gn + ".emr;"
styles["aws_emr_cluster"] = n2 + "resourceIcon;resIcon=" + gn + ".emr;"
styles["aws_kinesis"] = n2 + "resourceIcon;resIcon=" + gn + ".kinesis;"
styles["aws_kinesisanalytics"] = (
n2 + "resourceIcon;resIcon=" + gn + ".kinesis_data_analytics;"
)
styles["aws_kinesis_firehose"] = (
n2 + "resourceIcon;resIcon=" + gn + ".kinesis_data_firehose;"
)
styles["aws_quicksight"] = n2 + "resourceIcon;resIcon=" + gn + ".quicksight;"
styles["aws_redshift"] = n2 + "resourceIcon;resIcon=" + gn + ".redshift;"
styles["aws_data_pipeline"] = n2 + "resourceIcon;resIcon=" + gn + ".data_pipeline;"
styles["aws_msk_cluster"] = (
n2 + "resourceIcon;resIcon=" + gn + ".managed_streaming_for_kafka;"
)
styles["aws_glue"] = n2 + "resourceIcon;resIcon=" + gn + ".glue;"
styles["aws_lakeformation"] = n2 + "resourceIcon;resIcon=" + gn + ".lake_formation;"


def _add_application_integration_resources(styles):
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#F34482;gradientDirection=north;fillColor=#BC1356;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_sns_topic"] = n2 + "resourceIcon;resIcon=" + gn + ".sns;"
styles["aws_sqs"] = n2 + "resourceIcon;resIcon=" + gn + ".sqs;"
styles["aws_appsync_graphql_api"] = n2 + "resourceIcon;resIcon=" + gn + ".appsync;"
styles["aws_events"] = n2 + "resourceIcon;resIcon=" + gn + ".eventbridge;"


def _add_compute_resources(styles):
n = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#D05C17;strokeColor=none;dashed=0;"
"verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;"
"pointerEvents=1;shape=mxgraph.aws4."
)
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#F78E04;gradientDirection=north;fillColor=#D05C17;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_instance"] = n2 + "resourceIcon;resIcon=" + gn + ".ec2;"
styles["aws_autoscaling_group"] = (
n2 + "resourceIcon;resIcon=" + gn + ".auto_scaling2;"
)
styles["aws_batch"] = n2 + "resourceIcon;resIcon=" + gn + ".batch;"
styles["aws_elastic_beanstalk_environment"] = (
n2 + "resourceIcon;resIcon=" + gn + ".elastic_beanstalk;"
)
styles["aws_lambda_function"] = n + "lambda_function;"


def _add_container_resources(styles):
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#F78E04;gradientDirection=north;fillColor=#D05C17;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_eks_cluster"] = n2 + "resourceIcon;resIcon=" + gn + ".eks;"
styles["aws_ecr"] = n2 + "resourceIcon;resIcon=" + gn + ".ecr;"
styles["aws_ecs_cluster"] = n2 + "resourceIcon;resIcon=" + gn + ".ecs;"


def _add_customer_engagement_resources(styles):
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#4D72F3;gradientDirection=north;fillColor=#3334B9;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_connect"] = n2 + "resourceIcon;resIcon=" + gn + ".connect;"
styles["aws_pinpoint"] = n2 + "resourceIcon;resIcon=" + gn + ".pinpoint;"
styles["aws_ses"] = n2 + "resourceIcon;resIcon=" + gn + ".simple_email_service;"


def _add_database_resources(styles):
n = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#3334B9;strokeColor=none;dashed=0;"
"verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;"
"pointerEvents=1;shape=mxgraph.aws4."
)
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#4D72F3;gradientDirection=north;fillColor=#3334B9;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_docdb_cluster"] = (
n2 + "resourceIcon;resIcon=" + gn + ".documentdb_with_mongodb_compatibility;"
)
styles["aws_dynamodb"] = n2 + "resourceIcon;resIcon=" + gn + ".dynamodb;"
styles["aws_elasticache_cluster"] = (
n2 + "resourceIcon;resIcon=" + gn + ".elasticache;"
)
styles["aws_neptune_cluster"] = n2 + "resourceIcon;resIcon=" + gn + ".neptune;"
styles["aws_redshift"] = n2 + "resourceIcon;resIcon=" + gn + ".redshift;"

styles["aws_db_instance"] = n + "rds_instance;"
styles["aws_dax"] = n + "dynamodb_dax;"


def _add_ml_resources(styles):
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#4AB29A;gradientDirection=north;fillColor=#116D5B;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_sagemaker"] = n2 + "resourceIcon;resIcon=" + gn + ".sagemaker;"


def _add_management_governance_resources(styles):
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#F34482;gradientDirection=north;fillColor=#BC1356;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_cloudwatch"] = n2 + "resourceIcon;resIcon=" + gn + ".cloudwatch_2;"
styles["aws_autoscaling_group"] = (
n2 + "resourceIcon;resIcon=" + gn + ".autoscaling;"
)
styles["aws_auto_scaling"] = n2 + "resourceIcon;resIcon=" + gn + ".autoscaling;"
styles["aws_cloudformation"] = (
n2 + "resourceIcon;resIcon=" + gn + ".cloudformation;"
)


def _add_network_resources(styles):
n = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#5A30B5;strokeColor=none;dashed=0;"
"verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;"
"pointerEvents=1;shape=mxgraph.aws4."
)
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#945DF2;gradientDirection=north;fillColor=#5A30B5;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_api_gateway_rest_api"] = (
n2 + "resourceIcon;resIcon=" + gn + ".api_gateway;"
)
styles["aws_cloudfront_distribution"] = (
n2 + "resourceIcon;resIcon=" + gn + ".cloudfront;"
)
styles["aws_vpc"] = n2 + "resourceIcon;resIcon=" + gn + ".vpc;"
styles["aws_vpn_client_endpoint"] = (
n2 + "resourceIcon;resIcon=" + gn + ".client_vpn;"
)
styles["aws_elb"] = n2 + "resourceIcon;resIcon=" + gn + ".elastic_load_balancing;"
styles["aws_directconnect"] = n2 + "resourceIcon;resIcon=" + gn + ".direct_connect;"
styles["aws_global_accelerator"] = (
n2 + "resourceIcon;resIcon=" + gn + ".global_accelerator;"
)

styles["aws_route_table"] = n + "route_table;"
styles["aws_vpc_endpoint_gateway"] = n + "gateway;"
styles["aws_internet_gateway"] = n + "internet_gateway;"
styles["aws_nat_gateway"] = n + "nat_gateway;"
styles["aws_network_acl"] = n + "network_access_control_list;"
styles["aws_elb_classic"] = n + "classic_load_balancer;"
styles["aws_vpn_connection"] = n + "vpn_connection;"
styles["aws_vpn_gateway"] = n + "vpn_gateway;"


def _add_storage_resources(styles):
n = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=none;fillColor=#277116;strokeColor=none;dashed=0;"
"verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;"
"pointerEvents=1;shape=mxgraph.aws4."
)
n2 = (
"outlineConnect=0;fontColor=#232F3E;gradientColor=#60A337;gradientDirection=north;fillColor=#277116;"
"strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;"
"fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4."
)

styles["aws_efs_file_system"] = (
n2 + "resourceIcon;resIcon=" + gn + ".elastic_file_system;"
)
styles["aws_fsx"] = n2 + "resourceIcon;resIcon=" + gn + ".fsx;"

styles["aws_s3"] = n + "bucket;"


def build_styles():
styles = {}
_add_general_resources(styles)
_add_analytics_resources(styles)
_add_application_integration_resources(styles)
_add_compute_resources(styles)
_add_container_resources(styles)
_add_customer_engagement_resources(styles)
_add_database_resources(styles)
_add_ml_resources(styles)
_add_management_governance_resources(styles)
_add_network_resources(styles)
_add_storage_resources(styles)
return styles

0 comments on commit 7d7ecd3

Please sign in to comment.