From dabdb5034a2f8bc6b8c83e6e00d978fd27461d9d Mon Sep 17 00:00:00 2001 From: Frederik Martini Date: Tue, 29 Apr 2025 17:33:52 +0200 Subject: [PATCH 1/9] prepare multiple FE --- .gitignore | 1 + cmd/cloudsketch.go | 10 +- go.mod | 14 +-- go.sum | 22 +--- .../datastructures/build_graph/build_graph.go | 102 ++++----------- internal/frontends/dot/main.go | 107 ++++++++++++++++ .../drawio/handlers/ai_services/handler.go | 8 +- .../drawio/handlers/app_service/handler.go | 8 +- .../handlers/app_service_plan/handler.go | 10 +- .../handlers/application_gateway/handler.go | 8 +- .../drawio/handlers/application_group/main.go | 46 +++++++ .../handlers/application_insights/handler.go | 8 +- .../application_security_group/handler.go | 8 +- .../drawio/handlers/bastion/handler.go | 8 +- .../drawio/handlers/connection/handler.go | 8 +- .../handlers/container_registry/handler.go | 8 +- .../drawio/handlers/cosmos/handler.go | 8 +- .../drawio/handlers/data_factory/handler.go | 10 +- .../handler.go | 10 +- .../handler.go | 10 +- .../handlers/databricks_workspace/handler.go | 8 +- .../drawio/handlers/diagram/diagram.go | 0 .../drawio/handlers/dns_record/handler.go | 6 +- .../handlers/express_route_circuit/handler.go | 8 +- .../handlers/express_route_gateway/handler.go | 8 +- .../drawio/handlers/function_app/handler.go | 8 +- .../drawio/handlers/host_pool/main.go | 65 ++++++++++ .../drawio/handlers/key_vault/handler.go | 8 +- .../drawio/handlers/load_balancer/handler.go | 8 +- .../load_balancer_frontend/handler.go | 8 +- .../drawio/handlers/log_analytics/handler.go | 8 +- .../drawio/handlers/logic_app/handler.go | 8 +- .../machine_learning_workspace/handler.go | 8 +- .../drawio/handlers/nat_gateway/handler.go | 8 +- .../handlers/network_interface/handler.go | 8 +- .../network_security_group/handler.go | 8 +- .../drawio/handlers/node/arrow.go | 0 .../drawio/handlers/node/common.go | 4 +- .../drawio/handlers/node/node.go | 0 .../drawio/handlers/node/types.go | 2 +- .../handlers/postgres_sql_server/handler.go | 10 +- .../handlers/private_dns_resolver/handler.go | 8 +- .../handlers/private_dns_zone/handler.go | 10 +- .../handlers/private_endpoint/handler.go | 8 +- .../handlers/private_link_service/handler.go | 8 +- .../handlers/public_ip_address/handler.go | 8 +- .../recovery_service_vault/handler.go | 8 +- .../drawio/handlers/redis/handler.go | 8 +- .../drawio/handlers/route_table/handler.go | 8 +- .../drawio/handlers/search_service/handler.go | 8 +- .../drawio/handlers/signalr/handler.go | 8 +- .../drawio/handlers/sql_database/handler.go | 8 +- .../drawio/handlers/sql_server/handler.go | 8 +- .../drawio/handlers/static_web_app/handler.go | 8 +- .../handlers/storage_account/handler.go | 8 +- .../drawio/handlers/subnet/handler.go | 12 +- .../drawio/handlers/subscription/handler.go | 10 +- .../user_assigned_identity/handler.go | 8 +- .../drawio/handlers/virtual_hub/handler.go | 8 +- .../handlers/virtual_machine/handler.go | 8 +- .../virtual_machine_scale_set/handler.go | 8 +- .../handlers/virtual_network/handler.go | 12 +- .../virtual_network_gateway/handler.go | 8 +- .../drawio/handlers/virtual_wan/handler.go | 8 +- .../drawio/handlers/workspace/main.go | 46 +++++++ .../{ => frontends}/drawio/images/images.go | 3 + .../drawio.go => frontends/drawio/main.go} | 117 ++++++++++-------- .../{ => frontends}/drawio/models/resource.go | 0 .../{ => frontends}/drawio/types/types.go | 3 + .../handlers/application_group/handler.go | 48 +++++++ .../azure/handlers/host_pool/handler.go | 57 +++++++++ internal/providers/azure/provider.go | 11 +- internal/providers/azure/types/types.go | 3 + 73 files changed, 708 insertions(+), 381 deletions(-) create mode 100644 internal/frontends/dot/main.go rename internal/{ => frontends}/drawio/handlers/ai_services/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/app_service/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/app_service_plan/handler.go (94%) rename internal/{ => frontends}/drawio/handlers/application_gateway/handler.go (88%) create mode 100644 internal/frontends/drawio/handlers/application_group/main.go rename internal/{ => frontends}/drawio/handlers/application_insights/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/application_security_group/handler.go (84%) rename internal/{ => frontends}/drawio/handlers/bastion/handler.go (87%) rename internal/{ => frontends}/drawio/handlers/connection/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/container_registry/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/cosmos/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/data_factory/handler.go (93%) rename internal/{ => frontends}/drawio/handlers/data_factory_integration_runtime/handler.go (80%) rename internal/{ => frontends}/drawio/handlers/data_factory_managed_private_endpoint/handler.go (81%) rename internal/{ => frontends}/drawio/handlers/databricks_workspace/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/diagram/diagram.go (100%) rename internal/{ => frontends}/drawio/handlers/dns_record/handler.go (92%) rename internal/{ => frontends}/drawio/handlers/express_route_circuit/handler.go (92%) rename internal/{ => frontends}/drawio/handlers/express_route_gateway/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/function_app/handler.go (92%) create mode 100644 internal/frontends/drawio/handlers/host_pool/main.go rename internal/{ => frontends}/drawio/handlers/key_vault/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/load_balancer/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/load_balancer_frontend/handler.go (84%) rename internal/{ => frontends}/drawio/handlers/log_analytics/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/logic_app/handler.go (88%) rename internal/{ => frontends}/drawio/handlers/machine_learning_workspace/handler.go (84%) rename internal/{ => frontends}/drawio/handlers/nat_gateway/handler.go (87%) rename internal/{ => frontends}/drawio/handlers/network_interface/handler.go (92%) rename internal/{ => frontends}/drawio/handlers/network_security_group/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/node/arrow.go (100%) rename internal/{ => frontends}/drawio/handlers/node/common.go (98%) rename internal/{ => frontends}/drawio/handlers/node/node.go (100%) rename internal/{ => frontends}/drawio/handlers/node/types.go (72%) rename internal/{ => frontends}/drawio/handlers/postgres_sql_server/handler.go (80%) rename internal/{ => frontends}/drawio/handlers/private_dns_resolver/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/private_dns_zone/handler.go (91%) rename internal/{ => frontends}/drawio/handlers/private_endpoint/handler.go (95%) rename internal/{ => frontends}/drawio/handlers/private_link_service/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/public_ip_address/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/recovery_service_vault/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/redis/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/route_table/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/search_service/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/signalr/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/sql_database/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/sql_server/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/static_web_app/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/storage_account/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/subnet/handler.go (93%) rename internal/{ => frontends}/drawio/handlers/subscription/handler.go (90%) rename internal/{ => frontends}/drawio/handlers/user_assigned_identity/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/virtual_hub/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/virtual_machine/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/virtual_machine_scale_set/handler.go (84%) rename internal/{ => frontends}/drawio/handlers/virtual_network/handler.go (89%) rename internal/{ => frontends}/drawio/handlers/virtual_network_gateway/handler.go (83%) rename internal/{ => frontends}/drawio/handlers/virtual_wan/handler.go (83%) create mode 100644 internal/frontends/drawio/handlers/workspace/main.go rename internal/{ => frontends}/drawio/images/images.go (94%) rename internal/{drawio/drawio.go => frontends/drawio/main.go} (73%) rename internal/{ => frontends}/drawio/models/resource.go (100%) rename internal/{ => frontends}/drawio/types/types.go (94%) create mode 100644 internal/providers/azure/handlers/application_group/handler.go create mode 100644 internal/providers/azure/handlers/host_pool/handler.go diff --git a/.gitignore b/.gitignore index 7365bc0..66499dc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.drawio* *.json *.exe +*.dot !example/example.json !example/example.drawio .cloudsketch \ No newline at end of file diff --git a/cmd/cloudsketch.go b/cmd/cloudsketch.go index 303e651..ce5079b 100644 --- a/cmd/cloudsketch.go +++ b/cmd/cloudsketch.go @@ -1,8 +1,8 @@ package cmd import ( - "cloudsketch/internal/drawio" - "cloudsketch/internal/drawio/models" + "cloudsketch/internal/frontends/drawio" + "cloudsketch/internal/frontends/drawio/models" "cloudsketch/internal/marshall" "cloudsketch/internal/providers/azure" "context" @@ -51,6 +51,12 @@ func newCloudsketch(_ context.Context, command *cli.Command) error { if err != nil { return err } + /* + filename = fmt.Sprintf("%s.dot", filename) + + if err := dot.New(resources).WriteDiagram(filename); err != nil { + return err + }*/ filename = fmt.Sprintf("%s.drawio", filename) diff --git a/go.mod b/go.mod index 8303776..e497ac8 100644 --- a/go.mod +++ b/go.mod @@ -6,20 +6,16 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v4 v4.1.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/datafactory/armdatafactory/v9 v9.1.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/desktopvirtualization/armdesktopvirtualization/v2 v2.3.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dnsresolver/armdnsresolver v1.2.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.3.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0 - github.com/google/uuid v1.6.0 -) - -require ( - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources/v2 v2.0.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.3.0 + github.com/google/uuid v1.6.0 ) -require github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources/v2 v2.0.0 - -require github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dnsresolver/armdnsresolver v1.2.0 - require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.0 // indirect diff --git a/go.sum b/go.sum index 81204bf..a4bbaba 100644 --- a/go.sum +++ b/go.sum @@ -1,25 +1,21 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 h1:g0EZJwz7xkXQiZAI5xi9f3WWFYBlX1CPTrR+NDToRkQ= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0/go.mod h1:XCW7KnZet0Opnr7HccfUw1PLc4CjHqpcaxW8DHklNkQ= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0 h1:Gt0j3wceWMwPmiazCa8MzMA0MfhmPIz0Qp0FJ6qcM0U= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0/go.mod h1:Ot/6aikWnKWi4l9QB7qVSwa8iMphQNqkWALMoNT3rzM= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2 h1:F0gBpfdPLGsw+nsgk6aqqkZS1jiixa5WwFe3fk/T3Ys= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2/go.mod h1:SqINnQ9lVVdRlyC8cd1lCI0SdX4n2paeABd2K8ggfnE= github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2 h1:yz1bePFlP5Vws5+8ez6T3HWXPmwOK7Yvq8QxDBD3SKY= github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2/go.mod h1:Pa9ZNPuoNu/GztvBSKk9J1cDJW6vk/n0zLtV4mgd8N8= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.0 h1:Bg8m3nq/X1DeePkAbCfb6ml6F3F0IunEhE8TMh+lY48= github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.0/go.mod h1:j2chePtV91HrC22tGoRX3sGY42uF13WzmmV80/OdVAA= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/applicationinsights/armapplicationinsights v1.2.0 h1:7FX6sHNPamIAyukt6w9Gw5Qa5bu+gVN2Iy70yHc0xns= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/applicationinsights/armapplicationinsights v1.2.0/go.mod h1:S7Ss6Rm0nlKDRHKrO9eL2Be5EnX29Z09CNPWgK7o4+I= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v4 v4.1.0 h1:dZurN2OdkxAZlaNw6cjEvo7uOonGFErtqQtos0RDl5Q= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v4 v4.1.0/go.mod h1:/Qjzbz3yeXizRgrwP1lbwBIYYsAuMfDRWN0P5YbYgBM= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v6 v6.2.0 h1:JAebRMoc3vL+Nd97GBprHYHucO4+wlW+tNbBIumqJlk= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v6 v6.2.0/go.mod h1:zflC9v4VfViJrSvcvplqws/yGXVbUEMZi/iHpZdSPWA= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v6 v6.4.0 h1:z7Mqz6l0EFH549GvHEqfjKvi+cRScxLWbaoeLm9wxVQ= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v6 v6.4.0/go.mod h1:v6gbfH+7DG7xH2kUNs+ZJ9tF6O3iNnR85wMtmr+F54o= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/datafactory/armdatafactory/v9 v9.1.0 h1:82oTC4oB/7AjVmPR8KMvlyHZgZ8PGdboh8c0Jol/XWY= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/datafactory/armdatafactory/v9 v9.1.0/go.mod h1:nuDWiSqiFv4Bo8LX99dl+Ecl9o1iNSLJDBsrl8iRWr4= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/desktopvirtualization/armdesktopvirtualization/v2 v2.3.0 h1:58Pq8MyJ4hT2rkkSaZ7gS25+Q1YdsNn+3nuAt+Sg0Yc= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/desktopvirtualization/armdesktopvirtualization/v2 v2.3.0/go.mod h1:awlKdgQzRV48H2/m3VEhHQrHwqRpLqDEVkz4LvSgTEc= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dnsresolver/armdnsresolver v1.2.0 h1:a9tUwEFoR0ReDuT1tYBZygqhu+e9vrytcK5L3coRgJc= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dnsresolver/armdnsresolver v1.2.0/go.mod h1:sAxC5H7BmYLl5bLFRv84znoflLf6fOM+ymEuIolJ4hU= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do= @@ -42,8 +38,6 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.3.0/go.mod h1:TpiwjwnW/khS0LKs4vW5UmmT9OWcxaveS8U7+tlknzo= github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1 h1:WJTmL004Abzc5wDB5VtZG2PJk5ndYDgVacGqfirKxjM= github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1/go.mod h1:tCcJZ0uHAmvjsVYzEFivsRTN00oz5BEsRgQHu5JZ9WE= -github.com/AzureAD/microsoft-authentication-library-for-go v1.4.0 h1:MUkXAnvvDHgvPItl0nBj0hgk0f7hnnQbGm0h0+YxbN4= -github.com/AzureAD/microsoft-authentication-library-for-go v1.4.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 h1:oygO0locgZJe7PpYPXT5A29ZkwJaPqcva7BVeemZOZs= github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -52,8 +46,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= -github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -70,25 +62,15 @@ github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg= -github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= github.com/urfave/cli/v3 v3.1.1 h1:bNnl8pFI5dxPOjeONvFCDFoECLQsceDG4ejahs4Jtxk= github.com/urfave/cli/v3 v3.1.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo= -golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= -golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= -golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= -golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= -golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/datastructures/build_graph/build_graph.go b/internal/datastructures/build_graph/build_graph.go index 2bd66f3..b948cc6 100644 --- a/internal/datastructures/build_graph/build_graph.go +++ b/internal/datastructures/build_graph/build_graph.go @@ -1,49 +1,47 @@ package build_graph import ( - "bytes" "cloudsketch/internal/list" "errors" "fmt" "sort" - "strings" ) -type build_graph struct { - tasks []*Task - graph map[*Task][]*Task - inverse_graph map[*Task][]*Task +type Build_graph struct { + Tasks []*Task + Graph map[*Task][]*Task + Inverse_graph map[*Task][]*Task } -func NewGraph(tasks []*Task) (*build_graph, error) { +func NewGraph(tasks []*Task) (*Build_graph, error) { graph, inverse_graph, err := buildGraph(tasks) if err != nil { return nil, err } - return &build_graph{ - tasks: tasks, - graph: graph, - inverse_graph: inverse_graph, + return &Build_graph{ + Tasks: tasks, + Graph: graph, + Inverse_graph: inverse_graph, }, nil } type Task struct { - label string - references []string - inputs []string - outputs []string - action func() + Label string + References []string + Inputs []string + Outputs []string + Action func() } func NewTask(label string, references, inputs, outputs []string, action func()) *Task { return &Task{ - label: label, - references: references, - inputs: inputs, - outputs: outputs, - action: action, + Label: label, + References: references, + Inputs: inputs, + Outputs: outputs, + Action: action, } } @@ -53,11 +51,11 @@ func buildGraph(tasks []*Task) (map[*Task][]*Task, map[*Task][]*Task, error) { // sort tasks lowest amount of dependencies first sort.Slice(tasks, func(i, j int) bool { - return len(tasks[i].references) > len(tasks[j].references) + return len(tasks[i].References) > len(tasks[j].References) }) // if the last entry has refernces the graph is cyclic - if len(tasks[len(tasks)-1].references) != 0 { + if len(tasks[len(tasks)-1].References) != 0 { return nil, nil, errors.New("cyclic graph detected") } @@ -67,9 +65,9 @@ func buildGraph(tasks []*Task) (map[*Task][]*Task, map[*Task][]*Task, error) { graph[task] = []*Task{} } - for _, reference := range task.references { + for _, reference := range task.References { dependentTask := list.FirstOrDefault(tasks, nil, func(t *Task) bool { - return t.label == reference + return t.Label == reference }) if dependentTask == nil { @@ -90,60 +88,12 @@ func buildGraph(tasks []*Task) (map[*Task][]*Task, map[*Task][]*Task, error) { return graph, inverse_graph, nil } -func (g *build_graph) Resolve(t *Task) { - for _, ref := range g.inverse_graph[t] { +func (g *Build_graph) Resolve(t *Task) { + for _, ref := range g.Inverse_graph[t] { // recursively resolve the tasks dependencies g.Resolve(ref) } // when the task has no dependencies it can be resolved - t.action() -} - -func ReplaceMany(s string, old []string, new string) string { - for _, toReplace := range old { - s = strings.ReplaceAll(s, toReplace, new) - } - - return s -} - -func (g *build_graph) ToDotFile(name string) string { - var buffer bytes.Buffer - - buffer.WriteString(fmt.Sprintf("digraph %s {\n", name)) - - for _, task := range g.tasks { - writeInputNodes(&buffer, task.label, task.inputs) - - writeReferences(&buffer, task.label, task.references) - - writeOutputNodes(&buffer, task.label, task.outputs) - } - - buffer.WriteString("}") - - return buffer.String() -} - -func writeInputNodes(buffer *bytes.Buffer, label string, inputs []string) { - for _, input := range inputs { - buffer.WriteString("\t") - buffer.WriteString(fmt.Sprintf(`%s [label="%s" shape=plaintext];`, input, input)) - buffer.WriteString(fmt.Sprintf("\n\t%s -> %s;\n", input, label)) - } -} - -func writeReferences(buffer *bytes.Buffer, label string, references []string) { - for _, reference := range references { - buffer.WriteString(fmt.Sprintf("\t%s -> %s;\n", label, reference)) - } -} - -func writeOutputNodes(buffer *bytes.Buffer, label string, outputs []string) { - for _, output := range outputs { - buffer.WriteString("\t") - buffer.WriteString(fmt.Sprintf(`%s [label="%s" shape=plaintext];`, output, output)) - buffer.WriteString(fmt.Sprintf("\n\t%s -> %s;\n", label, output)) - } + t.Action() } diff --git a/internal/frontends/dot/main.go b/internal/frontends/dot/main.go new file mode 100644 index 0000000..6b02dea --- /dev/null +++ b/internal/frontends/dot/main.go @@ -0,0 +1,107 @@ +package dot + +import ( + "bytes" + "cloudsketch/internal/datastructures/build_graph" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/list" + "fmt" + "os" + "strings" +) + +type dot struct { + resources []*models.Resource +} + +func New(resources []*models.Resource) *dot { + return &dot{ + resources: resources, + } +} + +func removeChars(s string) string { + r := []string{"-", "_", "/", "."} + + for _, c := range r { + s = strings.ReplaceAll(s, c, "") + } + + return s +} + +func (d *dot) WriteDiagram(filename string) error { + tasks := list.Map(d.resources, func(r *models.Resource) *build_graph.Task { + return build_graph.NewTask(r.Name, r.DependsOn, []string{}, []string{}, func() {}) + }) + + tasks = list.Map(tasks, func(task *build_graph.Task) *build_graph.Task { + return &build_graph.Task{ + Label: removeChars(task.Label), + References: list.Map(task.References, removeChars), + Inputs: list.Map(task.Inputs, removeChars), + Outputs: list.Map(task.Outputs, removeChars), + } + }) + + bg, err := build_graph.NewGraph(tasks) + + if err != nil { + return err + } + + graphName := removeChars(strings.ReplaceAll(filename, ".dot", "")) + content := ToDotFile(bg, graphName) + + f, err := os.Create(filename) + + if err != nil { + return err + } + + defer f.Close() + + _, err = f.WriteString(content) + + return err +} + +func ToDotFile(g *build_graph.Build_graph, name string) string { + var buffer bytes.Buffer + + buffer.WriteString(fmt.Sprintf("digraph %s {\n", name)) + + for _, task := range g.Tasks { + writeInputNodes(&buffer, task.Label, task.Inputs) + + writeReferences(&buffer, task.Label, task.References) + + writeOutputNodes(&buffer, task.Label, task.Outputs) + } + + buffer.WriteString("}") + + return buffer.String() +} + +func writeInputNodes(buffer *bytes.Buffer, label string, inputs []string) { + for _, input := range inputs { + buffer.WriteString("\t") + buffer.WriteString(fmt.Sprintf(`%s [label="%s" shape=plaintext];`, input, input)) + buffer.WriteString(fmt.Sprintf("\n\t%s -> %s;\n", input, label)) + } +} + +func writeReferences(buffer *bytes.Buffer, label string, references []string) { + for _, reference := range references { + buffer.WriteString(fmt.Sprintf("\t%s -> %s;\n", label, reference)) + } +} + +func writeOutputNodes(buffer *bytes.Buffer, label string, outputs []string) { + for _, output := range outputs { + buffer.WriteString("\t") + buffer.WriteString(fmt.Sprintf(`%s [label="%s" shape=plaintext];`, output, output)) + buffer.WriteString(fmt.Sprintf("\n\t%s -> %s;\n", label, output)) + } +} diff --git a/internal/drawio/handlers/ai_services/handler.go b/internal/frontends/drawio/handlers/ai_services/handler.go similarity index 83% rename from internal/drawio/handlers/ai_services/handler.go rename to internal/frontends/drawio/handlers/ai_services/handler.go index e47d918..28534b2 100644 --- a/internal/drawio/handlers/ai_services/handler.go +++ b/internal/frontends/drawio/handlers/ai_services/handler.go @@ -1,10 +1,10 @@ package ai_services import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/app_service/handler.go b/internal/frontends/drawio/handlers/app_service/handler.go similarity index 83% rename from internal/drawio/handlers/app_service/handler.go rename to internal/frontends/drawio/handlers/app_service/handler.go index 70bc541..c40e306 100644 --- a/internal/drawio/handlers/app_service/handler.go +++ b/internal/frontends/drawio/handlers/app_service/handler.go @@ -1,10 +1,10 @@ package app_service import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/app_service_plan/handler.go b/internal/frontends/drawio/handlers/app_service_plan/handler.go similarity index 94% rename from internal/drawio/handlers/app_service_plan/handler.go rename to internal/frontends/drawio/handlers/app_service_plan/handler.go index 4afb91b..9c91497 100644 --- a/internal/drawio/handlers/app_service_plan/handler.go +++ b/internal/frontends/drawio/handlers/app_service_plan/handler.go @@ -2,11 +2,11 @@ package app_service_plan import ( "cloudsketch/internal/datastructures/set" - "cloudsketch/internal/drawio/handlers/diagram" - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/diagram" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" "log" ) diff --git a/internal/drawio/handlers/application_gateway/handler.go b/internal/frontends/drawio/handlers/application_gateway/handler.go similarity index 88% rename from internal/drawio/handlers/application_gateway/handler.go rename to internal/frontends/drawio/handlers/application_gateway/handler.go index ad5733c..6133dda 100644 --- a/internal/drawio/handlers/application_gateway/handler.go +++ b/internal/frontends/drawio/handlers/application_gateway/handler.go @@ -1,10 +1,10 @@ package application_gateway import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/application_group/main.go b/internal/frontends/drawio/handlers/application_group/main.go new file mode 100644 index 0000000..b9473ae --- /dev/null +++ b/internal/frontends/drawio/handlers/application_group/main.go @@ -0,0 +1,46 @@ +package application_group + +import ( + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" +) + +type handler struct{} + +const ( + TYPE = types.APPLICATION_GROUP + IMAGE = images.APPLICATION_GROUP + WIDTH = 68 + HEIGHT = 68 +) + +func New() *handler { + return &handler{} +} + +func (*handler) MapResource(resource *models.Resource) *node.Node { + geometry := node.Geometry{ + X: 0, + Y: 0, + Width: WIDTH, + Height: HEIGHT, + } + + link := resource.GetLinkOrDefault() + + return node.NewIcon(IMAGE, resource.Name, &geometry, link) +} + +func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *map[string]*node.ResourceAndNode) *node.Node { + return nil +} + +func (*handler) DrawDependencies(source *models.Resource, targets []*models.Resource, resource_map *map[string]*node.ResourceAndNode) []*node.Arrow { + return node.DrawDependencyArrowsToTarget(source, targets, resource_map, []string{}) +} + +func (*handler) GroupResources(_ *models.Resource, resources []*models.Resource, resource_map *map[string]*node.ResourceAndNode) []*node.Node { + return []*node.Node{} +} diff --git a/internal/drawio/handlers/application_insights/handler.go b/internal/frontends/drawio/handlers/application_insights/handler.go similarity index 83% rename from internal/drawio/handlers/application_insights/handler.go rename to internal/frontends/drawio/handlers/application_insights/handler.go index fd4ab48..3ac04dc 100644 --- a/internal/drawio/handlers/application_insights/handler.go +++ b/internal/frontends/drawio/handlers/application_insights/handler.go @@ -1,10 +1,10 @@ package application_insights import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/application_security_group/handler.go b/internal/frontends/drawio/handlers/application_security_group/handler.go similarity index 84% rename from internal/drawio/handlers/application_security_group/handler.go rename to internal/frontends/drawio/handlers/application_security_group/handler.go index ef6a967..e3eb5a8 100644 --- a/internal/drawio/handlers/application_security_group/handler.go +++ b/internal/frontends/drawio/handlers/application_security_group/handler.go @@ -1,10 +1,10 @@ package application_security_group import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/bastion/handler.go b/internal/frontends/drawio/handlers/bastion/handler.go similarity index 87% rename from internal/drawio/handlers/bastion/handler.go rename to internal/frontends/drawio/handlers/bastion/handler.go index 8a05604..312b021 100644 --- a/internal/drawio/handlers/bastion/handler.go +++ b/internal/frontends/drawio/handlers/bastion/handler.go @@ -1,10 +1,10 @@ package bastion import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/drawio/handlers/connection/handler.go b/internal/frontends/drawio/handlers/connection/handler.go similarity index 83% rename from internal/drawio/handlers/connection/handler.go rename to internal/frontends/drawio/handlers/connection/handler.go index defe1f2..8d9887e 100644 --- a/internal/drawio/handlers/connection/handler.go +++ b/internal/frontends/drawio/handlers/connection/handler.go @@ -1,10 +1,10 @@ package connection import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/container_registry/handler.go b/internal/frontends/drawio/handlers/container_registry/handler.go similarity index 83% rename from internal/drawio/handlers/container_registry/handler.go rename to internal/frontends/drawio/handlers/container_registry/handler.go index 18b46a1..130de6c 100644 --- a/internal/drawio/handlers/container_registry/handler.go +++ b/internal/frontends/drawio/handlers/container_registry/handler.go @@ -1,10 +1,10 @@ package container_registry import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/cosmos/handler.go b/internal/frontends/drawio/handlers/cosmos/handler.go similarity index 83% rename from internal/drawio/handlers/cosmos/handler.go rename to internal/frontends/drawio/handlers/cosmos/handler.go index a209c0a..ce469f7 100644 --- a/internal/drawio/handlers/cosmos/handler.go +++ b/internal/frontends/drawio/handlers/cosmos/handler.go @@ -1,10 +1,10 @@ package cosmos import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/data_factory/handler.go b/internal/frontends/drawio/handlers/data_factory/handler.go similarity index 93% rename from internal/drawio/handlers/data_factory/handler.go rename to internal/frontends/drawio/handlers/data_factory/handler.go index b461415..307b01a 100644 --- a/internal/drawio/handlers/data_factory/handler.go +++ b/internal/frontends/drawio/handlers/data_factory/handler.go @@ -1,11 +1,11 @@ package data_factory import ( - "cloudsketch/internal/drawio/handlers/diagram" - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/diagram" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/drawio/handlers/data_factory_integration_runtime/handler.go b/internal/frontends/drawio/handlers/data_factory_integration_runtime/handler.go similarity index 80% rename from internal/drawio/handlers/data_factory_integration_runtime/handler.go rename to internal/frontends/drawio/handlers/data_factory_integration_runtime/handler.go index 91c68b1..be422c6 100644 --- a/internal/drawio/handlers/data_factory_integration_runtime/handler.go +++ b/internal/frontends/drawio/handlers/data_factory_integration_runtime/handler.go @@ -1,11 +1,11 @@ package data_factory_integration_runtime import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/handlers/virtual_machine" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/handlers/virtual_machine" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/data_factory_managed_private_endpoint/handler.go b/internal/frontends/drawio/handlers/data_factory_managed_private_endpoint/handler.go similarity index 81% rename from internal/drawio/handlers/data_factory_managed_private_endpoint/handler.go rename to internal/frontends/drawio/handlers/data_factory_managed_private_endpoint/handler.go index 769c745..e919e07 100644 --- a/internal/drawio/handlers/data_factory_managed_private_endpoint/handler.go +++ b/internal/frontends/drawio/handlers/data_factory_managed_private_endpoint/handler.go @@ -1,11 +1,11 @@ package data_factory_managed_private_endpoint import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/handlers/private_endpoint" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/handlers/private_endpoint" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/databricks_workspace/handler.go b/internal/frontends/drawio/handlers/databricks_workspace/handler.go similarity index 83% rename from internal/drawio/handlers/databricks_workspace/handler.go rename to internal/frontends/drawio/handlers/databricks_workspace/handler.go index ffa4e4a..556d282 100644 --- a/internal/drawio/handlers/databricks_workspace/handler.go +++ b/internal/frontends/drawio/handlers/databricks_workspace/handler.go @@ -1,10 +1,10 @@ package databricks_workspace import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/diagram/diagram.go b/internal/frontends/drawio/handlers/diagram/diagram.go similarity index 100% rename from internal/drawio/handlers/diagram/diagram.go rename to internal/frontends/drawio/handlers/diagram/diagram.go diff --git a/internal/drawio/handlers/dns_record/handler.go b/internal/frontends/drawio/handlers/dns_record/handler.go similarity index 92% rename from internal/drawio/handlers/dns_record/handler.go rename to internal/frontends/drawio/handlers/dns_record/handler.go index 1d9ef9c..48b71b7 100644 --- a/internal/drawio/handlers/dns_record/handler.go +++ b/internal/frontends/drawio/handlers/dns_record/handler.go @@ -1,9 +1,9 @@ package dns_record import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/drawio/handlers/express_route_circuit/handler.go b/internal/frontends/drawio/handlers/express_route_circuit/handler.go similarity index 92% rename from internal/drawio/handlers/express_route_circuit/handler.go rename to internal/frontends/drawio/handlers/express_route_circuit/handler.go index 7692211..1adeabb 100644 --- a/internal/drawio/handlers/express_route_circuit/handler.go +++ b/internal/frontends/drawio/handlers/express_route_circuit/handler.go @@ -1,10 +1,10 @@ package express_route_circuit import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/drawio/handlers/express_route_gateway/handler.go b/internal/frontends/drawio/handlers/express_route_gateway/handler.go similarity index 83% rename from internal/drawio/handlers/express_route_gateway/handler.go rename to internal/frontends/drawio/handlers/express_route_gateway/handler.go index e70990a..846c2d9 100644 --- a/internal/drawio/handlers/express_route_gateway/handler.go +++ b/internal/frontends/drawio/handlers/express_route_gateway/handler.go @@ -1,10 +1,10 @@ package express_route_gateway import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/function_app/handler.go b/internal/frontends/drawio/handlers/function_app/handler.go similarity index 92% rename from internal/drawio/handlers/function_app/handler.go rename to internal/frontends/drawio/handlers/function_app/handler.go index f93b485..3d4a1ca 100644 --- a/internal/drawio/handlers/function_app/handler.go +++ b/internal/frontends/drawio/handlers/function_app/handler.go @@ -1,10 +1,10 @@ package function_app import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" "strings" ) diff --git a/internal/frontends/drawio/handlers/host_pool/main.go b/internal/frontends/drawio/handlers/host_pool/main.go new file mode 100644 index 0000000..0622550 --- /dev/null +++ b/internal/frontends/drawio/handlers/host_pool/main.go @@ -0,0 +1,65 @@ +package host_pool + +import ( + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/list" +) + +type handler struct{} + +const ( + TYPE = types.HOST_POOL + IMAGE = images.HOST_POOL + WIDTH = 68 + HEIGHT = 68 +) + +func New() *handler { + return &handler{} +} + +func (*handler) MapResource(resource *models.Resource) *node.Node { + geometry := node.Geometry{ + X: 0, + Y: 0, + Width: WIDTH, + Height: HEIGHT, + } + + link := resource.GetLinkOrDefault() + + return node.NewIcon(IMAGE, resource.Name, &geometry, link) +} + +func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *map[string]*node.ResourceAndNode) *node.Node { + return nil +} + +func (*handler) DrawDependencies(source *models.Resource, targets []*models.Resource, resource_map *map[string]*node.ResourceAndNode) []*node.Arrow { + typeBlacklist := []string{types.SUBSCRIPTION} + + targetResources := list.Map(targets, func(target *models.Resource) *node.ResourceAndNode { + return (*resource_map)[target.Id] + }) + + targetResources = list.Filter(targetResources, func(target *node.ResourceAndNode) bool { + return !list.Contains(typeBlacklist, func(t string) bool { + return target.Resource.Type == t + }) + }) + + sourceNode := (*resource_map)[source.Id].Node + + arrows := list.Fold(targetResources, []*node.Arrow{}, func(target *node.ResourceAndNode, acc []*node.Arrow) []*node.Arrow { + return append(acc, node.NewArrow(sourceNode.Id(), target.Node.Id(), nil)) + }) + + return arrows +} + +func (*handler) GroupResources(_ *models.Resource, resources []*models.Resource, resource_map *map[string]*node.ResourceAndNode) []*node.Node { + return []*node.Node{} +} diff --git a/internal/drawio/handlers/key_vault/handler.go b/internal/frontends/drawio/handlers/key_vault/handler.go similarity index 83% rename from internal/drawio/handlers/key_vault/handler.go rename to internal/frontends/drawio/handlers/key_vault/handler.go index d08fc8a..5f191e7 100644 --- a/internal/drawio/handlers/key_vault/handler.go +++ b/internal/frontends/drawio/handlers/key_vault/handler.go @@ -1,10 +1,10 @@ package key_vault import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/load_balancer/handler.go b/internal/frontends/drawio/handlers/load_balancer/handler.go similarity index 83% rename from internal/drawio/handlers/load_balancer/handler.go rename to internal/frontends/drawio/handlers/load_balancer/handler.go index b4879f7..701bc00 100644 --- a/internal/drawio/handlers/load_balancer/handler.go +++ b/internal/frontends/drawio/handlers/load_balancer/handler.go @@ -1,10 +1,10 @@ package load_balancer import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/load_balancer_frontend/handler.go b/internal/frontends/drawio/handlers/load_balancer_frontend/handler.go similarity index 84% rename from internal/drawio/handlers/load_balancer_frontend/handler.go rename to internal/frontends/drawio/handlers/load_balancer_frontend/handler.go index a3aba95..e1ffe7c 100644 --- a/internal/drawio/handlers/load_balancer_frontend/handler.go +++ b/internal/frontends/drawio/handlers/load_balancer_frontend/handler.go @@ -1,10 +1,10 @@ package load_balancer_frontend import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/log_analytics/handler.go b/internal/frontends/drawio/handlers/log_analytics/handler.go similarity index 83% rename from internal/drawio/handlers/log_analytics/handler.go rename to internal/frontends/drawio/handlers/log_analytics/handler.go index fce3d71..99b47b0 100644 --- a/internal/drawio/handlers/log_analytics/handler.go +++ b/internal/frontends/drawio/handlers/log_analytics/handler.go @@ -1,10 +1,10 @@ package log_analytics import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/logic_app/handler.go b/internal/frontends/drawio/handlers/logic_app/handler.go similarity index 88% rename from internal/drawio/handlers/logic_app/handler.go rename to internal/frontends/drawio/handlers/logic_app/handler.go index 62e04bc..d954560 100644 --- a/internal/drawio/handlers/logic_app/handler.go +++ b/internal/frontends/drawio/handlers/logic_app/handler.go @@ -1,10 +1,10 @@ package logic_app import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/machine_learning_workspace/handler.go b/internal/frontends/drawio/handlers/machine_learning_workspace/handler.go similarity index 84% rename from internal/drawio/handlers/machine_learning_workspace/handler.go rename to internal/frontends/drawio/handlers/machine_learning_workspace/handler.go index 29b959c..8017758 100644 --- a/internal/drawio/handlers/machine_learning_workspace/handler.go +++ b/internal/frontends/drawio/handlers/machine_learning_workspace/handler.go @@ -1,10 +1,10 @@ package machine_learning_workspace import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/nat_gateway/handler.go b/internal/frontends/drawio/handlers/nat_gateway/handler.go similarity index 87% rename from internal/drawio/handlers/nat_gateway/handler.go rename to internal/frontends/drawio/handlers/nat_gateway/handler.go index 23366a4..2d80c5f 100644 --- a/internal/drawio/handlers/nat_gateway/handler.go +++ b/internal/frontends/drawio/handlers/nat_gateway/handler.go @@ -1,10 +1,10 @@ package nat_gateway import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/drawio/handlers/network_interface/handler.go b/internal/frontends/drawio/handlers/network_interface/handler.go similarity index 92% rename from internal/drawio/handlers/network_interface/handler.go rename to internal/frontends/drawio/handlers/network_interface/handler.go index dbb83ea..f79a438 100644 --- a/internal/drawio/handlers/network_interface/handler.go +++ b/internal/frontends/drawio/handlers/network_interface/handler.go @@ -1,10 +1,10 @@ package network_interface import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/drawio/handlers/network_security_group/handler.go b/internal/frontends/drawio/handlers/network_security_group/handler.go similarity index 83% rename from internal/drawio/handlers/network_security_group/handler.go rename to internal/frontends/drawio/handlers/network_security_group/handler.go index 84d6f3b..2cd2e76 100644 --- a/internal/drawio/handlers/network_security_group/handler.go +++ b/internal/frontends/drawio/handlers/network_security_group/handler.go @@ -1,10 +1,10 @@ package network_security_group import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/node/arrow.go b/internal/frontends/drawio/handlers/node/arrow.go similarity index 100% rename from internal/drawio/handlers/node/arrow.go rename to internal/frontends/drawio/handlers/node/arrow.go diff --git a/internal/drawio/handlers/node/common.go b/internal/frontends/drawio/handlers/node/common.go similarity index 98% rename from internal/drawio/handlers/node/common.go rename to internal/frontends/drawio/handlers/node/common.go index e5cfe99..703b5d2 100644 --- a/internal/drawio/handlers/node/common.go +++ b/internal/frontends/drawio/handlers/node/common.go @@ -1,8 +1,8 @@ package node import ( - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" "log" "math" diff --git a/internal/drawio/handlers/node/node.go b/internal/frontends/drawio/handlers/node/node.go similarity index 100% rename from internal/drawio/handlers/node/node.go rename to internal/frontends/drawio/handlers/node/node.go diff --git a/internal/drawio/handlers/node/types.go b/internal/frontends/drawio/handlers/node/types.go similarity index 72% rename from internal/drawio/handlers/node/types.go rename to internal/frontends/drawio/handlers/node/types.go index 298e8a6..15016d3 100644 --- a/internal/drawio/handlers/node/types.go +++ b/internal/frontends/drawio/handlers/node/types.go @@ -1,6 +1,6 @@ package node -import "cloudsketch/internal/drawio/models" +import "cloudsketch/internal/frontends/drawio/models" type Geometry struct { X, Y, Width, Height int diff --git a/internal/drawio/handlers/postgres_sql_server/handler.go b/internal/frontends/drawio/handlers/postgres_sql_server/handler.go similarity index 80% rename from internal/drawio/handlers/postgres_sql_server/handler.go rename to internal/frontends/drawio/handlers/postgres_sql_server/handler.go index 66f8631..11981ee 100644 --- a/internal/drawio/handlers/postgres_sql_server/handler.go +++ b/internal/frontends/drawio/handlers/postgres_sql_server/handler.go @@ -1,11 +1,11 @@ package postgres_sql_server import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/handlers/sql_server" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/handlers/sql_server" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/private_dns_resolver/handler.go b/internal/frontends/drawio/handlers/private_dns_resolver/handler.go similarity index 83% rename from internal/drawio/handlers/private_dns_resolver/handler.go rename to internal/frontends/drawio/handlers/private_dns_resolver/handler.go index ab665b0..7fb9874 100644 --- a/internal/drawio/handlers/private_dns_resolver/handler.go +++ b/internal/frontends/drawio/handlers/private_dns_resolver/handler.go @@ -1,10 +1,10 @@ package private_dns_resolver import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/private_dns_zone/handler.go b/internal/frontends/drawio/handlers/private_dns_zone/handler.go similarity index 91% rename from internal/drawio/handlers/private_dns_zone/handler.go rename to internal/frontends/drawio/handlers/private_dns_zone/handler.go index 8bbdbcb..e1a302b 100644 --- a/internal/drawio/handlers/private_dns_zone/handler.go +++ b/internal/frontends/drawio/handlers/private_dns_zone/handler.go @@ -1,11 +1,11 @@ package private_dns_zone import ( - "cloudsketch/internal/drawio/handlers/diagram" - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/diagram" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/drawio/handlers/private_endpoint/handler.go b/internal/frontends/drawio/handlers/private_endpoint/handler.go similarity index 95% rename from internal/drawio/handlers/private_endpoint/handler.go rename to internal/frontends/drawio/handlers/private_endpoint/handler.go index 63a1cc6..e7d372c 100644 --- a/internal/drawio/handlers/private_endpoint/handler.go +++ b/internal/frontends/drawio/handlers/private_endpoint/handler.go @@ -1,10 +1,10 @@ package private_endpoint import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/drawio/handlers/private_link_service/handler.go b/internal/frontends/drawio/handlers/private_link_service/handler.go similarity index 83% rename from internal/drawio/handlers/private_link_service/handler.go rename to internal/frontends/drawio/handlers/private_link_service/handler.go index 44fc173..c870f26 100644 --- a/internal/drawio/handlers/private_link_service/handler.go +++ b/internal/frontends/drawio/handlers/private_link_service/handler.go @@ -1,10 +1,10 @@ package private_link_service import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/public_ip_address/handler.go b/internal/frontends/drawio/handlers/public_ip_address/handler.go similarity index 83% rename from internal/drawio/handlers/public_ip_address/handler.go rename to internal/frontends/drawio/handlers/public_ip_address/handler.go index d17ddc4..5f0f6d5 100644 --- a/internal/drawio/handlers/public_ip_address/handler.go +++ b/internal/frontends/drawio/handlers/public_ip_address/handler.go @@ -1,10 +1,10 @@ package public_ip_address import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/recovery_service_vault/handler.go b/internal/frontends/drawio/handlers/recovery_service_vault/handler.go similarity index 83% rename from internal/drawio/handlers/recovery_service_vault/handler.go rename to internal/frontends/drawio/handlers/recovery_service_vault/handler.go index 2820ee3..13a8fd7 100644 --- a/internal/drawio/handlers/recovery_service_vault/handler.go +++ b/internal/frontends/drawio/handlers/recovery_service_vault/handler.go @@ -1,10 +1,10 @@ package recovery_service_vault import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/redis/handler.go b/internal/frontends/drawio/handlers/redis/handler.go similarity index 83% rename from internal/drawio/handlers/redis/handler.go rename to internal/frontends/drawio/handlers/redis/handler.go index 3bdf49b..70ef637 100644 --- a/internal/drawio/handlers/redis/handler.go +++ b/internal/frontends/drawio/handlers/redis/handler.go @@ -1,10 +1,10 @@ package redis import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/route_table/handler.go b/internal/frontends/drawio/handlers/route_table/handler.go similarity index 83% rename from internal/drawio/handlers/route_table/handler.go rename to internal/frontends/drawio/handlers/route_table/handler.go index d2f4f4b..1129d9e 100644 --- a/internal/drawio/handlers/route_table/handler.go +++ b/internal/frontends/drawio/handlers/route_table/handler.go @@ -1,10 +1,10 @@ package route_table import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/search_service/handler.go b/internal/frontends/drawio/handlers/search_service/handler.go similarity index 83% rename from internal/drawio/handlers/search_service/handler.go rename to internal/frontends/drawio/handlers/search_service/handler.go index 9ae6f94..cad21ae 100644 --- a/internal/drawio/handlers/search_service/handler.go +++ b/internal/frontends/drawio/handlers/search_service/handler.go @@ -1,10 +1,10 @@ package search_service import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/signalr/handler.go b/internal/frontends/drawio/handlers/signalr/handler.go similarity index 83% rename from internal/drawio/handlers/signalr/handler.go rename to internal/frontends/drawio/handlers/signalr/handler.go index 4c6e5b2..18dacfa 100644 --- a/internal/drawio/handlers/signalr/handler.go +++ b/internal/frontends/drawio/handlers/signalr/handler.go @@ -1,10 +1,10 @@ package signalr import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/sql_database/handler.go b/internal/frontends/drawio/handlers/sql_database/handler.go similarity index 83% rename from internal/drawio/handlers/sql_database/handler.go rename to internal/frontends/drawio/handlers/sql_database/handler.go index 215b7ee..55d0c5b 100644 --- a/internal/drawio/handlers/sql_database/handler.go +++ b/internal/frontends/drawio/handlers/sql_database/handler.go @@ -1,10 +1,10 @@ package sql_database import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/sql_server/handler.go b/internal/frontends/drawio/handlers/sql_server/handler.go similarity index 83% rename from internal/drawio/handlers/sql_server/handler.go rename to internal/frontends/drawio/handlers/sql_server/handler.go index e063c5c..6aafbbd 100644 --- a/internal/drawio/handlers/sql_server/handler.go +++ b/internal/frontends/drawio/handlers/sql_server/handler.go @@ -1,10 +1,10 @@ package sql_server import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/static_web_app/handler.go b/internal/frontends/drawio/handlers/static_web_app/handler.go similarity index 83% rename from internal/drawio/handlers/static_web_app/handler.go rename to internal/frontends/drawio/handlers/static_web_app/handler.go index a3021a0..d9131fe 100644 --- a/internal/drawio/handlers/static_web_app/handler.go +++ b/internal/frontends/drawio/handlers/static_web_app/handler.go @@ -1,10 +1,10 @@ package static_web_app import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/storage_account/handler.go b/internal/frontends/drawio/handlers/storage_account/handler.go similarity index 83% rename from internal/drawio/handlers/storage_account/handler.go rename to internal/frontends/drawio/handlers/storage_account/handler.go index 21b9492..99c1da7 100644 --- a/internal/drawio/handlers/storage_account/handler.go +++ b/internal/frontends/drawio/handlers/storage_account/handler.go @@ -1,10 +1,10 @@ package storage_account import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/subnet/handler.go b/internal/frontends/drawio/handlers/subnet/handler.go similarity index 93% rename from internal/drawio/handlers/subnet/handler.go rename to internal/frontends/drawio/handlers/subnet/handler.go index 891ca3e..e791308 100644 --- a/internal/drawio/handlers/subnet/handler.go +++ b/internal/frontends/drawio/handlers/subnet/handler.go @@ -2,11 +2,11 @@ package subnet import ( "cloudsketch/internal/datastructures/set" - "cloudsketch/internal/drawio/handlers/diagram" - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/diagram" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" "fmt" ) @@ -36,7 +36,7 @@ func (*handler) MapResource(resource *models.Resource) *node.Node { Height: HEIGHT, } - subnetSize := resource.Properties["size"] + subnetSize := resource.Properties["size"][0] name := fmt.Sprintf("%s/%s", resource.Name, subnetSize) diff --git a/internal/drawio/handlers/subscription/handler.go b/internal/frontends/drawio/handlers/subscription/handler.go similarity index 90% rename from internal/drawio/handlers/subscription/handler.go rename to internal/frontends/drawio/handlers/subscription/handler.go index ffb2276..9e57469 100644 --- a/internal/drawio/handlers/subscription/handler.go +++ b/internal/frontends/drawio/handlers/subscription/handler.go @@ -2,11 +2,11 @@ package subscription import ( "cloudsketch/internal/datastructures/set" - "cloudsketch/internal/drawio/handlers/diagram" - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/diagram" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" ) diff --git a/internal/drawio/handlers/user_assigned_identity/handler.go b/internal/frontends/drawio/handlers/user_assigned_identity/handler.go similarity index 83% rename from internal/drawio/handlers/user_assigned_identity/handler.go rename to internal/frontends/drawio/handlers/user_assigned_identity/handler.go index cf18608..e21059a 100644 --- a/internal/drawio/handlers/user_assigned_identity/handler.go +++ b/internal/frontends/drawio/handlers/user_assigned_identity/handler.go @@ -1,10 +1,10 @@ package user_assigned_identity import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/virtual_hub/handler.go b/internal/frontends/drawio/handlers/virtual_hub/handler.go similarity index 83% rename from internal/drawio/handlers/virtual_hub/handler.go rename to internal/frontends/drawio/handlers/virtual_hub/handler.go index b2649a7..0aabf91 100644 --- a/internal/drawio/handlers/virtual_hub/handler.go +++ b/internal/frontends/drawio/handlers/virtual_hub/handler.go @@ -1,10 +1,10 @@ package virtual_hub import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/virtual_machine/handler.go b/internal/frontends/drawio/handlers/virtual_machine/handler.go similarity index 83% rename from internal/drawio/handlers/virtual_machine/handler.go rename to internal/frontends/drawio/handlers/virtual_machine/handler.go index 2e08ed5..82d8243 100644 --- a/internal/drawio/handlers/virtual_machine/handler.go +++ b/internal/frontends/drawio/handlers/virtual_machine/handler.go @@ -1,10 +1,10 @@ package virtual_machine import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/virtual_machine_scale_set/handler.go b/internal/frontends/drawio/handlers/virtual_machine_scale_set/handler.go similarity index 84% rename from internal/drawio/handlers/virtual_machine_scale_set/handler.go rename to internal/frontends/drawio/handlers/virtual_machine_scale_set/handler.go index 4fdeda9..c718871 100644 --- a/internal/drawio/handlers/virtual_machine_scale_set/handler.go +++ b/internal/frontends/drawio/handlers/virtual_machine_scale_set/handler.go @@ -1,10 +1,10 @@ package virtual_machine_scale_set import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/virtual_network/handler.go b/internal/frontends/drawio/handlers/virtual_network/handler.go similarity index 89% rename from internal/drawio/handlers/virtual_network/handler.go rename to internal/frontends/drawio/handlers/virtual_network/handler.go index 116b64f..18d2a89 100644 --- a/internal/drawio/handlers/virtual_network/handler.go +++ b/internal/frontends/drawio/handlers/virtual_network/handler.go @@ -2,11 +2,11 @@ package virtual_network import ( "cloudsketch/internal/datastructures/set" - "cloudsketch/internal/drawio/handlers/diagram" - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/diagram" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" "cloudsketch/internal/list" "fmt" ) @@ -44,7 +44,7 @@ func (*handler) MapResource(resource *models.Resource) *node.Node { return node.NewIcon(IMAGE, resource.Name, &geometry, link) } - name := fmt.Sprintf("%s/%s", resource.Name, vnetSize) + name := fmt.Sprintf("%s/%s", resource.Name, vnetSize[0]) return node.NewIcon(IMAGE, name, &geometry, link) } diff --git a/internal/drawio/handlers/virtual_network_gateway/handler.go b/internal/frontends/drawio/handlers/virtual_network_gateway/handler.go similarity index 83% rename from internal/drawio/handlers/virtual_network_gateway/handler.go rename to internal/frontends/drawio/handlers/virtual_network_gateway/handler.go index ae2e401..d52fea1 100644 --- a/internal/drawio/handlers/virtual_network_gateway/handler.go +++ b/internal/frontends/drawio/handlers/virtual_network_gateway/handler.go @@ -1,10 +1,10 @@ package virtual_network_gateway import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/drawio/handlers/virtual_wan/handler.go b/internal/frontends/drawio/handlers/virtual_wan/handler.go similarity index 83% rename from internal/drawio/handlers/virtual_wan/handler.go rename to internal/frontends/drawio/handlers/virtual_wan/handler.go index 7385d65..0932652 100644 --- a/internal/drawio/handlers/virtual_wan/handler.go +++ b/internal/frontends/drawio/handlers/virtual_wan/handler.go @@ -1,10 +1,10 @@ package virtual_wan import ( - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/images" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/workspace/main.go b/internal/frontends/drawio/handlers/workspace/main.go new file mode 100644 index 0000000..46f77d8 --- /dev/null +++ b/internal/frontends/drawio/handlers/workspace/main.go @@ -0,0 +1,46 @@ +package workspace + +import ( + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/images" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" +) + +type handler struct{} + +const ( + TYPE = types.WORKSPACE + IMAGE = images.WORKSPACE + WIDTH = 68 + HEIGHT = 68 +) + +func New() *handler { + return &handler{} +} + +func (*handler) MapResource(resource *models.Resource) *node.Node { + geometry := node.Geometry{ + X: 0, + Y: 0, + Width: WIDTH, + Height: HEIGHT, + } + + link := resource.GetLinkOrDefault() + + return node.NewIcon(IMAGE, resource.Name, &geometry, link) +} + +func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *map[string]*node.ResourceAndNode) *node.Node { + return nil +} + +func (*handler) DrawDependencies(source *models.Resource, targets []*models.Resource, resource_map *map[string]*node.ResourceAndNode) []*node.Arrow { + return node.DrawDependencyArrowsToTarget(source, targets, resource_map, []string{}) +} + +func (*handler) GroupResources(_ *models.Resource, resources []*models.Resource, resource_map *map[string]*node.ResourceAndNode) []*node.Node { + return []*node.Node{} +} diff --git a/internal/drawio/images/images.go b/internal/frontends/drawio/images/images.go similarity index 94% rename from internal/drawio/images/images.go rename to internal/frontends/drawio/images/images.go index ac454b0..e48bacd 100644 --- a/internal/drawio/images/images.go +++ b/internal/frontends/drawio/images/images.go @@ -5,6 +5,7 @@ const ( APP_SERVICE = "img/lib/azure2/app_services/App_Services.svg" APP_SERVICE_PLAN = "img/lib/azure2/app_services/App_Service_Plans.svg" APPLICATION_GATEWAY = "img/lib/azure2/networking/Application_Gateways.svg" + APPLICATION_GROUP = "img/lib/azure2/compute/Application_Group.svg" APPLICATION_INSIGHTS = "img/lib/azure2/devops/Application_Insights.svg" APPLICATION_SECURITY_GROUP = "img/lib/azure2/security/Application_Security_Groups.svg" BASTION = "img/lib/azure2/networking/Bastions.svg" @@ -18,6 +19,7 @@ const ( EXPRESS_ROUTE_CIRCUIT = "img/lib/azure2/networking/ExpressRoute_Circuits.svg" EXPRESS_ROUTE_GATEWAY = VIRTUAL_NETWORK_GATEWAY FUNCTION_APP = "img/lib/azure2/compute/Function_Apps.svg" + HOST_POOL = "img/lib/azure2/compute/Host_Pools.svg" KEY_VAULT = "img/lib/azure2/security/Key_Vaults.svg" LOAD_BALANCER = "img/lib/azure2/networking/Load_Balancers.svg" LOAD_BALANCER_FRONTEND = PUBLIC_IP_ADDRESS @@ -51,4 +53,5 @@ const ( VIRTUAL_NETWORK = "img/lib/azure2/networking/Virtual_Networks.svg" VIRTUAL_NETWORK_GATEWAY = "img/lib/azure2/networking/Virtual_Network_Gateways.svg" VIRTUAL_WAN = "img/lib/azure2/networking/Virtual_WANs.svg" + WORKSPACE = "img/lib/azure2/compute/Workspaces2.svg" ) diff --git a/internal/drawio/drawio.go b/internal/frontends/drawio/main.go similarity index 73% rename from internal/drawio/drawio.go rename to internal/frontends/drawio/main.go index 28cf91e..1060e9c 100644 --- a/internal/drawio/drawio.go +++ b/internal/frontends/drawio/main.go @@ -4,61 +4,65 @@ import ( "cloudsketch/internal/config" "cloudsketch/internal/datastructures/build_graph" "cloudsketch/internal/datastructures/set" - "cloudsketch/internal/drawio/handlers/ai_services" - "cloudsketch/internal/drawio/handlers/app_service" - "cloudsketch/internal/drawio/handlers/app_service_plan" - "cloudsketch/internal/drawio/handlers/application_gateway" - "cloudsketch/internal/drawio/handlers/application_insights" - "cloudsketch/internal/drawio/handlers/application_security_group" - "cloudsketch/internal/drawio/handlers/bastion" - "cloudsketch/internal/drawio/handlers/connection" - "cloudsketch/internal/drawio/handlers/container_registry" - "cloudsketch/internal/drawio/handlers/cosmos" - "cloudsketch/internal/drawio/handlers/data_factory" - "cloudsketch/internal/drawio/handlers/data_factory_integration_runtime" - "cloudsketch/internal/drawio/handlers/data_factory_managed_private_endpoint" - "cloudsketch/internal/drawio/handlers/databricks_workspace" - "cloudsketch/internal/drawio/handlers/diagram" - "cloudsketch/internal/drawio/handlers/dns_record" - "cloudsketch/internal/drawio/handlers/express_route_circuit" - "cloudsketch/internal/drawio/handlers/express_route_gateway" - "cloudsketch/internal/drawio/handlers/function_app" - "cloudsketch/internal/drawio/handlers/key_vault" - "cloudsketch/internal/drawio/handlers/load_balancer" - "cloudsketch/internal/drawio/handlers/load_balancer_frontend" - "cloudsketch/internal/drawio/handlers/log_analytics" - "cloudsketch/internal/drawio/handlers/logic_app" - "cloudsketch/internal/drawio/handlers/machine_learning_workspace" - "cloudsketch/internal/drawio/handlers/nat_gateway" - "cloudsketch/internal/drawio/handlers/network_interface" - "cloudsketch/internal/drawio/handlers/network_security_group" - "cloudsketch/internal/drawio/handlers/node" - "cloudsketch/internal/drawio/handlers/postgres_sql_server" - "cloudsketch/internal/drawio/handlers/private_dns_resolver" - "cloudsketch/internal/drawio/handlers/private_dns_zone" - "cloudsketch/internal/drawio/handlers/private_endpoint" - "cloudsketch/internal/drawio/handlers/private_link_service" - "cloudsketch/internal/drawio/handlers/public_ip_address" - "cloudsketch/internal/drawio/handlers/recovery_service_vault" - "cloudsketch/internal/drawio/handlers/redis" - "cloudsketch/internal/drawio/handlers/route_table" - "cloudsketch/internal/drawio/handlers/search_service" - "cloudsketch/internal/drawio/handlers/signalr" - "cloudsketch/internal/drawio/handlers/sql_database" - "cloudsketch/internal/drawio/handlers/sql_server" - "cloudsketch/internal/drawio/handlers/static_web_app" - "cloudsketch/internal/drawio/handlers/storage_account" - "cloudsketch/internal/drawio/handlers/subnet" - "cloudsketch/internal/drawio/handlers/subscription" - "cloudsketch/internal/drawio/handlers/user_assigned_identity" - "cloudsketch/internal/drawio/handlers/virtual_hub" - "cloudsketch/internal/drawio/handlers/virtual_machine" - "cloudsketch/internal/drawio/handlers/virtual_machine_scale_set" - "cloudsketch/internal/drawio/handlers/virtual_network" - "cloudsketch/internal/drawio/handlers/virtual_network_gateway" - "cloudsketch/internal/drawio/handlers/virtual_wan" - "cloudsketch/internal/drawio/models" - "cloudsketch/internal/drawio/types" + "cloudsketch/internal/frontends/drawio/handlers/ai_services" + "cloudsketch/internal/frontends/drawio/handlers/app_service" + "cloudsketch/internal/frontends/drawio/handlers/app_service_plan" + "cloudsketch/internal/frontends/drawio/handlers/application_gateway" + "cloudsketch/internal/frontends/drawio/handlers/application_group" + "cloudsketch/internal/frontends/drawio/handlers/application_insights" + "cloudsketch/internal/frontends/drawio/handlers/application_security_group" + "cloudsketch/internal/frontends/drawio/handlers/bastion" + "cloudsketch/internal/frontends/drawio/handlers/connection" + "cloudsketch/internal/frontends/drawio/handlers/container_registry" + "cloudsketch/internal/frontends/drawio/handlers/cosmos" + "cloudsketch/internal/frontends/drawio/handlers/data_factory" + "cloudsketch/internal/frontends/drawio/handlers/data_factory_integration_runtime" + "cloudsketch/internal/frontends/drawio/handlers/data_factory_managed_private_endpoint" + "cloudsketch/internal/frontends/drawio/handlers/databricks_workspace" + "cloudsketch/internal/frontends/drawio/handlers/diagram" + "cloudsketch/internal/frontends/drawio/handlers/dns_record" + "cloudsketch/internal/frontends/drawio/handlers/express_route_circuit" + "cloudsketch/internal/frontends/drawio/handlers/express_route_gateway" + "cloudsketch/internal/frontends/drawio/handlers/function_app" + "cloudsketch/internal/frontends/drawio/handlers/host_pool" + "cloudsketch/internal/frontends/drawio/handlers/key_vault" + "cloudsketch/internal/frontends/drawio/handlers/load_balancer" + "cloudsketch/internal/frontends/drawio/handlers/load_balancer_frontend" + "cloudsketch/internal/frontends/drawio/handlers/log_analytics" + "cloudsketch/internal/frontends/drawio/handlers/logic_app" + "cloudsketch/internal/frontends/drawio/handlers/machine_learning_workspace" + "cloudsketch/internal/frontends/drawio/handlers/nat_gateway" + "cloudsketch/internal/frontends/drawio/handlers/network_interface" + "cloudsketch/internal/frontends/drawio/handlers/network_security_group" + "cloudsketch/internal/frontends/drawio/handlers/node" + "cloudsketch/internal/frontends/drawio/handlers/postgres_sql_server" + "cloudsketch/internal/frontends/drawio/handlers/private_dns_resolver" + "cloudsketch/internal/frontends/drawio/handlers/private_dns_zone" + "cloudsketch/internal/frontends/drawio/handlers/private_endpoint" + "cloudsketch/internal/frontends/drawio/handlers/private_link_service" + "cloudsketch/internal/frontends/drawio/handlers/public_ip_address" + "cloudsketch/internal/frontends/drawio/handlers/recovery_service_vault" + "cloudsketch/internal/frontends/drawio/handlers/redis" + "cloudsketch/internal/frontends/drawio/handlers/route_table" + "cloudsketch/internal/frontends/drawio/handlers/search_service" + "cloudsketch/internal/frontends/drawio/handlers/signalr" + "cloudsketch/internal/frontends/drawio/handlers/sql_database" + "cloudsketch/internal/frontends/drawio/handlers/sql_server" + "cloudsketch/internal/frontends/drawio/handlers/static_web_app" + "cloudsketch/internal/frontends/drawio/handlers/storage_account" + "cloudsketch/internal/frontends/drawio/handlers/subnet" + "cloudsketch/internal/frontends/drawio/handlers/subscription" + "cloudsketch/internal/frontends/drawio/handlers/user_assigned_identity" + "cloudsketch/internal/frontends/drawio/handlers/virtual_hub" + "cloudsketch/internal/frontends/drawio/handlers/virtual_machine" + "cloudsketch/internal/frontends/drawio/handlers/virtual_machine_scale_set" + "cloudsketch/internal/frontends/drawio/handlers/virtual_network" + "cloudsketch/internal/frontends/drawio/handlers/virtual_network_gateway" + "cloudsketch/internal/frontends/drawio/handlers/virtual_wan" + "cloudsketch/internal/frontends/drawio/handlers/workspace" + "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/list" "fmt" "log" @@ -77,6 +81,7 @@ var ( app_service.TYPE: app_service.New(), app_service_plan.TYPE: app_service_plan.New(), application_gateway.TYPE: application_gateway.New(), + application_group.TYPE: application_group.New(), application_insights.TYPE: application_insights.New(), application_security_group.TYPE: application_security_group.New(), bastion.TYPE: bastion.New(), @@ -91,6 +96,7 @@ var ( express_route_circuit.TYPE: express_route_circuit.New(), express_route_gateway.TYPE: express_route_gateway.New(), function_app.TYPE: function_app.New(), + host_pool.TYPE: host_pool.New(), key_vault.TYPE: key_vault.New(), load_balancer.TYPE: load_balancer.New(), load_balancer_frontend.TYPE: load_balancer_frontend.New(), @@ -124,6 +130,7 @@ var ( virtual_network.TYPE: virtual_network.New(), virtual_network_gateway.TYPE: virtual_network_gateway.New(), virtual_wan.TYPE: virtual_wan.New(), + workspace.TYPE: workspace.New(), } ) diff --git a/internal/drawio/models/resource.go b/internal/frontends/drawio/models/resource.go similarity index 100% rename from internal/drawio/models/resource.go rename to internal/frontends/drawio/models/resource.go diff --git a/internal/drawio/types/types.go b/internal/frontends/drawio/types/types.go similarity index 94% rename from internal/drawio/types/types.go rename to internal/frontends/drawio/types/types.go index f6f245c..136e1ea 100644 --- a/internal/drawio/types/types.go +++ b/internal/frontends/drawio/types/types.go @@ -5,6 +5,7 @@ const ( APP_SERVICE = "APP_SERVICE" APP_SERVICE_PLAN = "APP_SERVICE_PLAN" APPLICATION_GATEWAY = "APPLICATION_GATEWAY" + APPLICATION_GROUP = "APPLICATION_GROUP" APPLICATION_INSIGHTS = "APPLICATION_INSIGHTS" APPLICATION_SECURITY_GROUP = "APPLICATION_SECURITY_GROUP" BASTION = "BASTION" @@ -19,6 +20,7 @@ const ( EXPRESS_ROUTE_CIRCUIT = "EXPRESS_ROUTE_CIRCUIT" EXPRESS_ROUTE_GATEWAY = "EXPRESS_ROUTE_GATEWAY" FUNCTION_APP = "FUNCTION_APP" + HOST_POOL = "HOST_POOL" KEY_VAULT = "KEY_VAULT" LOAD_BALANCER = "LOAD_BALANCER" LOAD_BALANCER_FRONTEND = "LOAD_BALANCER_FRONTEND" @@ -52,4 +54,5 @@ const ( VIRTUAL_NETWORK = "VIRTUAL_NETWORK" VIRTUAL_NETWORK_GATEWAY = "VIRTUAL_NETWORK_GATEWAY" VIRTUAL_WAN = "VIRTUAL_WAN" + WORKSPACE = "WORKSPACE" ) diff --git a/internal/providers/azure/handlers/application_group/handler.go b/internal/providers/azure/handlers/application_group/handler.go new file mode 100644 index 0000000..407846d --- /dev/null +++ b/internal/providers/azure/handlers/application_group/handler.go @@ -0,0 +1,48 @@ +package application_group + +import ( + azContext "cloudsketch/internal/providers/azure/context" + "cloudsketch/internal/providers/azure/models" + "context" + + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/desktopvirtualization/armdesktopvirtualization/v2" +) + +type handler struct{} + +func New() *handler { + return &handler{} +} + +func (h *handler) GetResource(ctx *azContext.Context) ([]*models.Resource, error) { + + client, err := armdesktopvirtualization.NewApplicationGroupsClient(ctx.SubscriptionId, ctx.Credentials, nil) + + if err != nil { + return nil, err + } + + applicationGroup, err := client.Get(context.Background(), ctx.ResourceGroupName, ctx.ResourceName, nil) + + if err != nil { + return nil, err + } + + dependsOn := []string{ + *applicationGroup.Properties.HostPoolArmPath, + *applicationGroup.Properties.WorkspaceArmPath, + } + + resource := &models.Resource{ + Id: ctx.ResourceId, + Name: ctx.ResourceName, + Type: *applicationGroup.Type, + DependsOn: dependsOn, + } + + return []*models.Resource{resource}, nil +} + +func (h *handler) PostProcess(resource *models.Resource, resources []*models.Resource) { + +} diff --git a/internal/providers/azure/handlers/host_pool/handler.go b/internal/providers/azure/handlers/host_pool/handler.go new file mode 100644 index 0000000..ff8562c --- /dev/null +++ b/internal/providers/azure/handlers/host_pool/handler.go @@ -0,0 +1,57 @@ +package host_pool + +import ( + azContext "cloudsketch/internal/providers/azure/context" + "cloudsketch/internal/providers/azure/models" + "cloudsketch/internal/providers/azure/types" + "context" + + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/desktopvirtualization/armdesktopvirtualization/v2" +) + +type handler struct{} + +func New() *handler { + return &handler{} +} + +func (h *handler) GetResource(ctx *azContext.Context) ([]*models.Resource, error) { + client, err := armdesktopvirtualization.NewSessionHostsClient(ctx.SubscriptionId, ctx.Credentials, nil) + + if err != nil { + return nil, err + } + + pager := client.NewListPager(ctx.ResourceGroupName, ctx.ResourceName, nil) + + var sessionHosts []*armdesktopvirtualization.SessionHost + + for pager.More() { + resp, err := pager.NextPage(context.Background()) + if err != nil { + return nil, err + } + if resp.SessionHostList.Value != nil { + sessionHosts = append(sessionHosts, resp.SessionHostList.Value...) + } + } + + dependsOn := []string{} + + for _, host := range sessionHosts { + dependsOn = append(dependsOn, *host.Properties.ResourceID) + } + + resource := &models.Resource{ + Id: ctx.ResourceId, + Name: ctx.ResourceName, + Type: types.HOST_POOL, + DependsOn: dependsOn, + } + + return []*models.Resource{resource}, nil +} + +func (h *handler) PostProcess(resource *models.Resource, resources []*models.Resource) { + +} diff --git a/internal/providers/azure/provider.go b/internal/providers/azure/provider.go index 32fad9d..77d5e22 100644 --- a/internal/providers/azure/provider.go +++ b/internal/providers/azure/provider.go @@ -7,11 +7,13 @@ import ( "cloudsketch/internal/marshall" azContext "cloudsketch/internal/providers/azure/context" "cloudsketch/internal/providers/azure/handlers/application_gateway" + "cloudsketch/internal/providers/azure/handlers/application_group" "cloudsketch/internal/providers/azure/handlers/application_insights" "cloudsketch/internal/providers/azure/handlers/bastion" "cloudsketch/internal/providers/azure/handlers/data_factory" "cloudsketch/internal/providers/azure/handlers/express_route_circuit" "cloudsketch/internal/providers/azure/handlers/express_route_gateway" + "cloudsketch/internal/providers/azure/handlers/host_pool" "cloudsketch/internal/providers/azure/handlers/key_vault" "cloudsketch/internal/providers/azure/handlers/load_balancer" "cloudsketch/internal/providers/azure/handlers/nat_gateway" @@ -34,8 +36,8 @@ import ( "log" "strings" - domainModels "cloudsketch/internal/drawio/models" - domainTypes "cloudsketch/internal/drawio/types" + domainModels "cloudsketch/internal/frontends/drawio/models" + domainTypes "cloudsketch/internal/frontends/drawio/types" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" ) @@ -48,10 +50,12 @@ type handler interface { var ( handlers map[string]handler = map[string]handler{ types.APPLICATION_GATEWAY: application_gateway.New(), + types.APPLICATION_GROUP: application_group.New(), types.APPLICATION_INSIGHTS: application_insights.New(), types.DATA_FACTORY: data_factory.New(), types.EXPRESS_ROUTE_CIRCUIT: express_route_circuit.New(), types.EXPRESS_ROUTE_GATEWAY: express_route_gateway.New(), + types.HOST_POOL: host_pool.New(), types.BASTION: bastion.New(), types.KEY_VAULT: key_vault.New(), types.LOAD_BALANCER: load_balancer.New(), @@ -240,6 +244,7 @@ func mapTypeToDomainType(azType string, unhandled_types *set.Set[string]) string types.APP_SERVICE: domainTypes.APP_SERVICE, types.APP_SERVICE_PLAN: domainTypes.APP_SERVICE_PLAN, types.APPLICATION_GATEWAY: domainTypes.APPLICATION_GATEWAY, + types.APPLICATION_GROUP: domainTypes.APPLICATION_GROUP, types.APPLICATION_INSIGHTS: domainTypes.APPLICATION_INSIGHTS, types.APPLICATION_SECURITY_GROUP: domainTypes.APPLICATION_SECURITY_GROUP, types.BASTION: domainTypes.BASTION, @@ -255,6 +260,7 @@ func mapTypeToDomainType(azType string, unhandled_types *set.Set[string]) string types.EXPRESS_ROUTE_CIRCUIT: domainTypes.EXPRESS_ROUTE_CIRCUIT, types.EXPRESS_ROUTE_GATEWAY: domainTypes.EXPRESS_ROUTE_GATEWAY, types.FUNCTION_APP: domainTypes.FUNCTION_APP, + types.HOST_POOL: domainTypes.HOST_POOL, types.KEY_VAULT: domainTypes.KEY_VAULT, types.LOAD_BALANCER: domainTypes.LOAD_BALANCER, types.LOAD_BALANCER_FRONTEND: domainTypes.LOAD_BALANCER_FRONTEND, @@ -287,6 +293,7 @@ func mapTypeToDomainType(azType string, unhandled_types *set.Set[string]) string types.VIRTUAL_NETWORK: domainTypes.VIRTUAL_NETWORK, types.VIRTUAL_NETWORK_GATEWAY: domainTypes.VIRTUAL_NETWORK_GATEWAY, types.VIRTUAL_WAN: domainTypes.VIRTUAL_WAN, + types.WORKSPACE: domainTypes.WORKSPACE, } domainType, ok := domainTypes[azType] diff --git a/internal/providers/azure/types/types.go b/internal/providers/azure/types/types.go index 4d6e1e8..8646987 100644 --- a/internal/providers/azure/types/types.go +++ b/internal/providers/azure/types/types.go @@ -5,6 +5,7 @@ const ( APP_SERVICE = "Cloudsketch/appservice" APP_SERVICE_PLAN = "Microsoft.Web/serverFarms" APPLICATION_GATEWAY = "Microsoft.Network/applicationGateways" + APPLICATION_GROUP = "Microsoft.DesktopVirtualization/applicationgroups" APPLICATION_INSIGHTS = "Microsoft.Insights/components" APPLICATION_SECURITY_GROUP = "Microsoft.Network/applicationSecurityGroups" BASTION = "Microsoft.Network/bastionHosts" @@ -19,6 +20,7 @@ const ( EXPRESS_ROUTE_CIRCUIT = "Microsoft.Network/expressRouteCircuits" EXPRESS_ROUTE_GATEWAY = "Microsoft.Network/expressRouteGateways" FUNCTION_APP = "Cloudsketch/functionapp" + HOST_POOL = "Microsoft.DesktopVirtualization/hostpools" KEY_VAULT = "Microsoft.KeyVault/vaults" LOAD_BALANCER = "Microsoft.Network/loadBalancers" LOAD_BALANCER_FRONTEND = "Microsoft.Network/loadBalancers/frontendIPConfigurations" @@ -53,4 +55,5 @@ const ( VIRTUAL_NETWORK_GATEWAY = "Microsoft.Network/virtualNetworkGateways" VIRTUAL_WAN = "Microsoft.Network/virtualWans" WEB_SITES = "Microsoft.Web/sites" + WORKSPACE = "Microsoft.DesktopVirtualization/workspaces" ) From 2d9939f4370a4df735a47f34dc9cb55f8628d844 Mon Sep 17 00:00:00 2001 From: Frederik Martini Date: Wed, 30 Apr 2025 14:13:00 +0200 Subject: [PATCH 2/9] support more frontends and providers --- .vscode/launch.json | 6 ++- cmd/cloudsketch.go | 34 +++++++++++----- cmd/cmd.go | 40 +++++++++++++++++++ example/example.json | 6 +-- internal/frontends/dot/main.go | 11 ++--- internal/frontends/drawio/main.go | 11 ++--- internal/frontends/frontend.go | 7 ++++ .../providers/azure/{provider.go => main.go} | 0 internal/providers/provider.go | 7 ++++ 9 files changed, 95 insertions(+), 27 deletions(-) create mode 100644 internal/frontends/frontend.go rename internal/providers/azure/{provider.go => main.go} (100%) create mode 100644 internal/providers/provider.go diff --git a/.vscode/launch.json b/.vscode/launch.json index 3c58bc8..fb03b04 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,11 @@ "mode": "auto", "program": "main.go", "args": [ - "${input:subscriptionId}" + "${input:subscriptionId}", + "--frontend", + "drawio", + "--provider", + "azure" ] } ], diff --git a/cmd/cloudsketch.go b/cmd/cloudsketch.go index ce5079b..cd91b83 100644 --- a/cmd/cloudsketch.go +++ b/cmd/cloudsketch.go @@ -1,9 +1,12 @@ package cmd import ( + "cloudsketch/internal/frontends" + "cloudsketch/internal/frontends/dot" "cloudsketch/internal/frontends/drawio" "cloudsketch/internal/frontends/drawio/models" "cloudsketch/internal/marshall" + "cloudsketch/internal/providers" "cloudsketch/internal/providers/azure" "context" "errors" @@ -14,6 +17,16 @@ import ( "github.com/urfave/cli/v3" ) +var ( + frontendmap map[string]frontends.Frontend = map[string]frontends.Frontend{ + "drawio": drawio.New(), + "dot": dot.New(), + } + providermap map[string]providers.Provider = map[string]providers.Provider{ + "azure": azure.NewProvider(), + } +) + func newCloudsketch(_ context.Context, command *cli.Command) error { args := command.Args().Slice() @@ -23,6 +36,13 @@ func newCloudsketch(_ context.Context, command *cli.Command) error { fileOrSubscriptionId := args[0] + f := command.String("frontend") + + p := command.String("provider") + + log.Printf("target frontend is %s\n", f) + log.Printf("target provider is %s\n", p) + // command can either be a subscription id or a file name if strings.HasSuffix(fileOrSubscriptionId, ".json") { // if the file ends in .json, assume its a valid json file that contains previously populated Azure resources @@ -38,29 +58,25 @@ func newCloudsketch(_ context.Context, command *cli.Command) error { outFile := strings.ReplaceAll(file, ".json", ".drawio") - return drawio.New(*resources).WriteDiagram(outFile) + return drawio.New().WriteDiagram(*resources, outFile) } // otherwise treat it as a subscription id subscriptionId := fileOrSubscriptionId - provider := azure.NewProvider() + provider := providermap[p] resources, filename, err := provider.FetchResources(subscriptionId) if err != nil { return err } - /* - filename = fmt.Sprintf("%s.dot", filename) - if err := dot.New(resources).WriteDiagram(filename); err != nil { - return err - }*/ + frontend := frontendmap[f] - filename = fmt.Sprintf("%s.drawio", filename) + filename = fmt.Sprintf("%s.%s", filename, f) - if err := drawio.New(resources).WriteDiagram(filename); err != nil { + if err := frontend.WriteDiagram(resources, filename); err != nil { return err } diff --git a/cmd/cmd.go b/cmd/cmd.go index a679b8c..d4d4bf6 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -1,10 +1,12 @@ package cmd import ( + "cloudsketch/internal/list" "context" "fmt" "log" "os" + "strings" "github.com/urfave/cli/v3" ) @@ -16,6 +18,44 @@ func Execute() { Usage: "Azure to DrawIO", UsageText: fmt.Sprintf("%s ", name), Description: "convert a Azure subscription to a DrawIO diagram", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "frontend", + Usage: "visualization target", + Value: "drawio", + Validator: func(s string) error { + validFrontends := []string{"drawio", "dot"} + + valid := list.Contains(validFrontends, func(validFrontend string) bool { + return s == validFrontend + }) + + if !valid { + return fmt.Errorf("%s is not a valid frontend. Valid target are %s", s, strings.Join(validFrontends, ",")) + } + + return nil + }, + }, + &cli.StringFlag{ + Name: "provider", + Usage: "resource source", + Value: "azure", + Validator: func(s string) error { + validProviders := []string{"azure"} + + valid := list.Contains(validProviders, func(validProvider string) bool { + return s == validProvider + }) + + if !valid { + return fmt.Errorf("%s is not a valid provider. Valid target are %s", s, strings.Join(validProviders, ",")) + } + + return nil + }, + }, + }, Commands: []*cli.Command{ newVersion(), }, diff --git a/example/example.json b/example/example.json index 3dfff9f..b2f55f2 100644 --- a/example/example.json +++ b/example/example.json @@ -16,7 +16,7 @@ "/subscriptions/00000000-0000-0000-0000-000000000000" ], "Properties": { - "size": "21" + "size": ["21"] } }, { @@ -29,7 +29,7 @@ "/subscriptions/00000000-0000-0000-0000-000000000000" ], "Properties": { - "size": "22" + "size": ["22"] } }, { @@ -53,7 +53,7 @@ "/subscriptions/00000000-0000-0000-0000-000000000000" ], "Properties": { - "attachedTo": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.compute/virtualmachines/example-vm" + "attachedTo": ["/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.compute/virtualmachines/example-vm"] } }, { diff --git a/internal/frontends/dot/main.go b/internal/frontends/dot/main.go index 6b02dea..4606c9d 100644 --- a/internal/frontends/dot/main.go +++ b/internal/frontends/dot/main.go @@ -11,13 +11,10 @@ import ( ) type dot struct { - resources []*models.Resource } -func New(resources []*models.Resource) *dot { - return &dot{ - resources: resources, - } +func New() *dot { + return &dot{} } func removeChars(s string) string { @@ -30,8 +27,8 @@ func removeChars(s string) string { return s } -func (d *dot) WriteDiagram(filename string) error { - tasks := list.Map(d.resources, func(r *models.Resource) *build_graph.Task { +func (d *dot) WriteDiagram(resources []*models.Resource, filename string) error { + tasks := list.Map(resources, func(r *models.Resource) *build_graph.Task { return build_graph.NewTask(r.Name, r.DependsOn, []string{}, []string{}, func() {}) }) diff --git a/internal/frontends/drawio/main.go b/internal/frontends/drawio/main.go index 1060e9c..6b99fc1 100644 --- a/internal/frontends/drawio/main.go +++ b/internal/frontends/drawio/main.go @@ -135,13 +135,10 @@ var ( ) type drawio struct { - resources []*models.Resource } -func New(resources []*models.Resource) *drawio { - return &drawio{ - resources: resources, - } +func New() *drawio { + return &drawio{} } func removeBlacklistedHandlers() { @@ -157,11 +154,11 @@ func removeBlacklistedHandlers() { } } -func (d *drawio) WriteDiagram(filename string) error { +func (d *drawio) WriteDiagram(resources []*models.Resource, filename string) error { removeBlacklistedHandlers() // at this point only the Azure resources are known - this function adds the corresponding DrawIO icons - resource_map, err := populateResourceMap(d.resources) + resource_map, err := populateResourceMap(resources) if err != nil { return err diff --git a/internal/frontends/frontend.go b/internal/frontends/frontend.go new file mode 100644 index 0000000..a875c86 --- /dev/null +++ b/internal/frontends/frontend.go @@ -0,0 +1,7 @@ +package frontends + +import "cloudsketch/internal/frontends/drawio/models" + +type Frontend interface { + WriteDiagram(resources []*models.Resource, filename string) error +} diff --git a/internal/providers/azure/provider.go b/internal/providers/azure/main.go similarity index 100% rename from internal/providers/azure/provider.go rename to internal/providers/azure/main.go diff --git a/internal/providers/provider.go b/internal/providers/provider.go new file mode 100644 index 0000000..0fbfd54 --- /dev/null +++ b/internal/providers/provider.go @@ -0,0 +1,7 @@ +package providers + +import "cloudsketch/internal/frontends/drawio/models" + +type Provider interface { + FetchResources(subscriptionId string) ([]*models.Resource, string, error) +} From e90e7b2b2c56183bd75951f2a92b2ea2e79c574e Mon Sep 17 00:00:00 2001 From: Frederik Martini Date: Thu, 1 May 2025 09:33:37 +0200 Subject: [PATCH 3/9] more things --- .gitignore | 1 + .vscode/launch.json | 6 +---- cmd/cloudsketch.go | 47 +++++++++++++++++++++------------- example/example.dot | 11 ++++++++ internal/frontends/dot/main.go | 2 +- 5 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 example/example.dot diff --git a/.gitignore b/.gitignore index 66499dc..e95e8d5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ *.dot !example/example.json !example/example.drawio +!example/example.dot .cloudsketch \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index fb03b04..3c58bc8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,11 +11,7 @@ "mode": "auto", "program": "main.go", "args": [ - "${input:subscriptionId}", - "--frontend", - "drawio", - "--provider", - "azure" + "${input:subscriptionId}" ] } ], diff --git a/cmd/cloudsketch.go b/cmd/cloudsketch.go index cd91b83..6852fbe 100644 --- a/cmd/cloudsketch.go +++ b/cmd/cloudsketch.go @@ -36,35 +36,48 @@ func newCloudsketch(_ context.Context, command *cli.Command) error { fileOrSubscriptionId := args[0] - f := command.String("frontend") + frontendString := command.String("frontend") - p := command.String("provider") + frontend := frontendmap[frontendString] - log.Printf("target frontend is %s\n", f) - log.Printf("target provider is %s\n", p) + providerString := command.String("provider") + + log.Printf("target frontend is %s\n", frontendString) + log.Printf("target provider is %s\n", providerString) // command can either be a subscription id or a file name if strings.HasSuffix(fileOrSubscriptionId, ".json") { // if the file ends in .json, assume its a valid json file that contains previously populated Azure resources - file := fileOrSubscriptionId + return useExistingFile(fileOrSubscriptionId, frontendString, frontend) + } + + // otherwise treat it as a subscription id + return createNewFile(fileOrSubscriptionId, providerString, frontendString, frontend) +} - log.Printf("using existing file %s\n", file) +func useExistingFile(file, frontendString string, frontend frontends.Frontend) error { + log.Printf("using existing file %s\n", file) - resources, err := marshall.UnmarshallResources[[]*models.Resource](file) + resources, err := marshall.UnmarshallResources[[]*models.Resource](file) - if err != nil { - return err - } + if err != nil { + return err + } - outFile := strings.ReplaceAll(file, ".json", ".drawio") + outFile := strings.ReplaceAll(file, ".json", fmt.Sprintf(".%s", frontendString)) - return drawio.New().WriteDiagram(*resources, outFile) + if err := frontend.WriteDiagram(*resources, outFile); err != nil { + return err } - // otherwise treat it as a subscription id - subscriptionId := fileOrSubscriptionId + // execution succesful. Print the output file name + log.Print(outFile) - provider := providermap[p] + return nil +} + +func createNewFile(subscriptionId, providerString, frontendString string, frontend frontends.Frontend) error { + provider := providermap[providerString] resources, filename, err := provider.FetchResources(subscriptionId) @@ -72,9 +85,7 @@ func newCloudsketch(_ context.Context, command *cli.Command) error { return err } - frontend := frontendmap[f] - - filename = fmt.Sprintf("%s.%s", filename, f) + filename = fmt.Sprintf("%s.%s", filename, frontendString) if err := frontend.WriteDiagram(resources, filename); err != nil { return err diff --git a/example/example.dot b/example/example.dot new file mode 100644 index 0000000..41d6dca --- /dev/null +++ b/example/example.dot @@ -0,0 +1,11 @@ +digraph exampleexample { + subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnetsubnetsexamplesnet -> subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnet; + subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnetsubnetsexamplesnet -> subscriptions00000000000000000000000000000000; + subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftcomputevirtualmachinescalesetsexamplevmss -> subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnetsubnetsexamplesnet; + subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftcomputevirtualmachinescalesetsexamplevmss -> subscriptions00000000000000000000000000000000; + subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworknetworkinterfacesexamplenic -> subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnetsubnetsexamplesnet; + subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworknetworkinterfacesexamplenic -> subscriptions00000000000000000000000000000000; + subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftcomputevirtualmachinesexamplevm -> subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworknetworkinterfacesexamplenic; + subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftcomputevirtualmachinesexamplevm -> subscriptions00000000000000000000000000000000; + subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnet -> subscriptions00000000000000000000000000000000; +} \ No newline at end of file diff --git a/internal/frontends/dot/main.go b/internal/frontends/dot/main.go index 4606c9d..45fd92c 100644 --- a/internal/frontends/dot/main.go +++ b/internal/frontends/dot/main.go @@ -29,7 +29,7 @@ func removeChars(s string) string { func (d *dot) WriteDiagram(resources []*models.Resource, filename string) error { tasks := list.Map(resources, func(r *models.Resource) *build_graph.Task { - return build_graph.NewTask(r.Name, r.DependsOn, []string{}, []string{}, func() {}) + return build_graph.NewTask(r.Id, r.DependsOn, []string{}, []string{}, func() {}) }) tasks = list.Map(tasks, func(task *build_graph.Task) *build_graph.Task { From d16db137ef5327d9d03cef8279cd5a3a9d64dedf Mon Sep 17 00:00:00 2001 From: Frederik Martini Date: Thu, 1 May 2025 12:04:08 +0200 Subject: [PATCH 4/9] move models and types --- cmd/cloudsketch.go | 2 +- internal/frontends/dot/main.go | 2 +- internal/frontends/drawio/handlers/ai_services/handler.go | 4 ++-- internal/frontends/drawio/handlers/app_service/handler.go | 4 ++-- .../frontends/drawio/handlers/app_service_plan/handler.go | 4 ++-- .../frontends/drawio/handlers/application_gateway/handler.go | 4 ++-- internal/frontends/drawio/handlers/application_group/main.go | 4 ++-- .../frontends/drawio/handlers/application_insights/handler.go | 4 ++-- .../drawio/handlers/application_security_group/handler.go | 4 ++-- internal/frontends/drawio/handlers/bastion/handler.go | 4 ++-- internal/frontends/drawio/handlers/connection/handler.go | 4 ++-- .../frontends/drawio/handlers/container_registry/handler.go | 4 ++-- internal/frontends/drawio/handlers/cosmos/handler.go | 4 ++-- internal/frontends/drawio/handlers/data_factory/handler.go | 4 ++-- .../handlers/data_factory_integration_runtime/handler.go | 4 ++-- .../handlers/data_factory_managed_private_endpoint/handler.go | 4 ++-- .../frontends/drawio/handlers/databricks_workspace/handler.go | 4 ++-- internal/frontends/drawio/handlers/dns_record/handler.go | 4 ++-- .../drawio/handlers/express_route_circuit/handler.go | 4 ++-- .../drawio/handlers/express_route_gateway/handler.go | 4 ++-- internal/frontends/drawio/handlers/function_app/handler.go | 4 ++-- internal/frontends/drawio/handlers/host_pool/main.go | 4 ++-- internal/frontends/drawio/handlers/key_vault/handler.go | 4 ++-- internal/frontends/drawio/handlers/load_balancer/handler.go | 4 ++-- .../drawio/handlers/load_balancer_frontend/handler.go | 4 ++-- internal/frontends/drawio/handlers/log_analytics/handler.go | 4 ++-- internal/frontends/drawio/handlers/logic_app/handler.go | 4 ++-- .../drawio/handlers/machine_learning_workspace/handler.go | 4 ++-- internal/frontends/drawio/handlers/nat_gateway/handler.go | 4 ++-- .../frontends/drawio/handlers/network_interface/handler.go | 4 ++-- .../drawio/handlers/network_security_group/handler.go | 4 ++-- internal/frontends/drawio/handlers/node/common.go | 4 ++-- internal/frontends/drawio/handlers/node/types.go | 2 +- .../frontends/drawio/handlers/postgres_sql_server/handler.go | 4 ++-- .../frontends/drawio/handlers/private_dns_resolver/handler.go | 4 ++-- .../frontends/drawio/handlers/private_dns_zone/handler.go | 4 ++-- .../frontends/drawio/handlers/private_endpoint/handler.go | 4 ++-- .../frontends/drawio/handlers/private_link_service/handler.go | 4 ++-- .../frontends/drawio/handlers/public_ip_address/handler.go | 4 ++-- .../drawio/handlers/recovery_service_vault/handler.go | 4 ++-- internal/frontends/drawio/handlers/redis/handler.go | 4 ++-- internal/frontends/drawio/handlers/route_table/handler.go | 4 ++-- internal/frontends/drawio/handlers/search_service/handler.go | 4 ++-- internal/frontends/drawio/handlers/signalr/handler.go | 4 ++-- internal/frontends/drawio/handlers/sql_database/handler.go | 4 ++-- internal/frontends/drawio/handlers/sql_server/handler.go | 4 ++-- internal/frontends/drawio/handlers/static_web_app/handler.go | 4 ++-- internal/frontends/drawio/handlers/storage_account/handler.go | 4 ++-- internal/frontends/drawio/handlers/subnet/handler.go | 4 ++-- internal/frontends/drawio/handlers/subscription/handler.go | 4 ++-- .../drawio/handlers/user_assigned_identity/handler.go | 4 ++-- internal/frontends/drawio/handlers/virtual_hub/handler.go | 4 ++-- internal/frontends/drawio/handlers/virtual_machine/handler.go | 4 ++-- .../drawio/handlers/virtual_machine_scale_set/handler.go | 4 ++-- internal/frontends/drawio/handlers/virtual_network/handler.go | 4 ++-- .../drawio/handlers/virtual_network_gateway/handler.go | 4 ++-- internal/frontends/drawio/handlers/virtual_wan/handler.go | 4 ++-- internal/frontends/drawio/handlers/workspace/main.go | 4 ++-- internal/frontends/drawio/main.go | 4 ++-- internal/frontends/frontend.go | 2 +- internal/frontends/{drawio => }/models/resource.go | 0 internal/frontends/{drawio => }/types/types.go | 0 internal/providers/azure/main.go | 4 ++-- internal/providers/provider.go | 2 +- 64 files changed, 119 insertions(+), 119 deletions(-) rename internal/frontends/{drawio => }/models/resource.go (100%) rename internal/frontends/{drawio => }/types/types.go (100%) diff --git a/cmd/cloudsketch.go b/cmd/cloudsketch.go index 6852fbe..b90c267 100644 --- a/cmd/cloudsketch.go +++ b/cmd/cloudsketch.go @@ -4,7 +4,7 @@ import ( "cloudsketch/internal/frontends" "cloudsketch/internal/frontends/dot" "cloudsketch/internal/frontends/drawio" - "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/models" "cloudsketch/internal/marshall" "cloudsketch/internal/providers" "cloudsketch/internal/providers/azure" diff --git a/internal/frontends/dot/main.go b/internal/frontends/dot/main.go index 45fd92c..c4a6f46 100644 --- a/internal/frontends/dot/main.go +++ b/internal/frontends/dot/main.go @@ -3,7 +3,7 @@ package dot import ( "bytes" "cloudsketch/internal/datastructures/build_graph" - "cloudsketch/internal/frontends/drawio/models" + "cloudsketch/internal/frontends/models" "cloudsketch/internal/list" "fmt" "os" diff --git a/internal/frontends/drawio/handlers/ai_services/handler.go b/internal/frontends/drawio/handlers/ai_services/handler.go index 28534b2..552b5bf 100644 --- a/internal/frontends/drawio/handlers/ai_services/handler.go +++ b/internal/frontends/drawio/handlers/ai_services/handler.go @@ -3,8 +3,8 @@ package ai_services import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/app_service/handler.go b/internal/frontends/drawio/handlers/app_service/handler.go index c40e306..0df600d 100644 --- a/internal/frontends/drawio/handlers/app_service/handler.go +++ b/internal/frontends/drawio/handlers/app_service/handler.go @@ -3,8 +3,8 @@ package app_service import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/app_service_plan/handler.go b/internal/frontends/drawio/handlers/app_service_plan/handler.go index 9c91497..651a56a 100644 --- a/internal/frontends/drawio/handlers/app_service_plan/handler.go +++ b/internal/frontends/drawio/handlers/app_service_plan/handler.go @@ -5,8 +5,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/diagram" "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" "log" ) diff --git a/internal/frontends/drawio/handlers/application_gateway/handler.go b/internal/frontends/drawio/handlers/application_gateway/handler.go index 6133dda..86db090 100644 --- a/internal/frontends/drawio/handlers/application_gateway/handler.go +++ b/internal/frontends/drawio/handlers/application_gateway/handler.go @@ -3,8 +3,8 @@ package application_gateway import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/application_group/main.go b/internal/frontends/drawio/handlers/application_group/main.go index b9473ae..8bdc0b5 100644 --- a/internal/frontends/drawio/handlers/application_group/main.go +++ b/internal/frontends/drawio/handlers/application_group/main.go @@ -3,8 +3,8 @@ package application_group import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/application_insights/handler.go b/internal/frontends/drawio/handlers/application_insights/handler.go index 3ac04dc..f78c2cf 100644 --- a/internal/frontends/drawio/handlers/application_insights/handler.go +++ b/internal/frontends/drawio/handlers/application_insights/handler.go @@ -3,8 +3,8 @@ package application_insights import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/application_security_group/handler.go b/internal/frontends/drawio/handlers/application_security_group/handler.go index e3eb5a8..9ca7923 100644 --- a/internal/frontends/drawio/handlers/application_security_group/handler.go +++ b/internal/frontends/drawio/handlers/application_security_group/handler.go @@ -3,8 +3,8 @@ package application_security_group import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/bastion/handler.go b/internal/frontends/drawio/handlers/bastion/handler.go index 312b021..db9a806 100644 --- a/internal/frontends/drawio/handlers/bastion/handler.go +++ b/internal/frontends/drawio/handlers/bastion/handler.go @@ -3,8 +3,8 @@ package bastion import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/connection/handler.go b/internal/frontends/drawio/handlers/connection/handler.go index 8d9887e..6ba8e9a 100644 --- a/internal/frontends/drawio/handlers/connection/handler.go +++ b/internal/frontends/drawio/handlers/connection/handler.go @@ -3,8 +3,8 @@ package connection import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/container_registry/handler.go b/internal/frontends/drawio/handlers/container_registry/handler.go index 130de6c..ef3b26e 100644 --- a/internal/frontends/drawio/handlers/container_registry/handler.go +++ b/internal/frontends/drawio/handlers/container_registry/handler.go @@ -3,8 +3,8 @@ package container_registry import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/cosmos/handler.go b/internal/frontends/drawio/handlers/cosmos/handler.go index ce469f7..232712f 100644 --- a/internal/frontends/drawio/handlers/cosmos/handler.go +++ b/internal/frontends/drawio/handlers/cosmos/handler.go @@ -3,8 +3,8 @@ package cosmos import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/data_factory/handler.go b/internal/frontends/drawio/handlers/data_factory/handler.go index 307b01a..710fa58 100644 --- a/internal/frontends/drawio/handlers/data_factory/handler.go +++ b/internal/frontends/drawio/handlers/data_factory/handler.go @@ -4,8 +4,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/diagram" "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/data_factory_integration_runtime/handler.go b/internal/frontends/drawio/handlers/data_factory_integration_runtime/handler.go index be422c6..9e02872 100644 --- a/internal/frontends/drawio/handlers/data_factory_integration_runtime/handler.go +++ b/internal/frontends/drawio/handlers/data_factory_integration_runtime/handler.go @@ -4,8 +4,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/handlers/virtual_machine" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/data_factory_managed_private_endpoint/handler.go b/internal/frontends/drawio/handlers/data_factory_managed_private_endpoint/handler.go index e919e07..bd40ff4 100644 --- a/internal/frontends/drawio/handlers/data_factory_managed_private_endpoint/handler.go +++ b/internal/frontends/drawio/handlers/data_factory_managed_private_endpoint/handler.go @@ -4,8 +4,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/handlers/private_endpoint" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/databricks_workspace/handler.go b/internal/frontends/drawio/handlers/databricks_workspace/handler.go index 556d282..4b260a4 100644 --- a/internal/frontends/drawio/handlers/databricks_workspace/handler.go +++ b/internal/frontends/drawio/handlers/databricks_workspace/handler.go @@ -3,8 +3,8 @@ package databricks_workspace import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/dns_record/handler.go b/internal/frontends/drawio/handlers/dns_record/handler.go index 48b71b7..94a39c9 100644 --- a/internal/frontends/drawio/handlers/dns_record/handler.go +++ b/internal/frontends/drawio/handlers/dns_record/handler.go @@ -2,8 +2,8 @@ package dns_record import ( "cloudsketch/internal/frontends/drawio/handlers/node" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/express_route_circuit/handler.go b/internal/frontends/drawio/handlers/express_route_circuit/handler.go index 1adeabb..fbec45e 100644 --- a/internal/frontends/drawio/handlers/express_route_circuit/handler.go +++ b/internal/frontends/drawio/handlers/express_route_circuit/handler.go @@ -3,8 +3,8 @@ package express_route_circuit import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/express_route_gateway/handler.go b/internal/frontends/drawio/handlers/express_route_gateway/handler.go index 846c2d9..dbf0551 100644 --- a/internal/frontends/drawio/handlers/express_route_gateway/handler.go +++ b/internal/frontends/drawio/handlers/express_route_gateway/handler.go @@ -3,8 +3,8 @@ package express_route_gateway import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/function_app/handler.go b/internal/frontends/drawio/handlers/function_app/handler.go index 3d4a1ca..779ecf6 100644 --- a/internal/frontends/drawio/handlers/function_app/handler.go +++ b/internal/frontends/drawio/handlers/function_app/handler.go @@ -3,8 +3,8 @@ package function_app import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" "strings" ) diff --git a/internal/frontends/drawio/handlers/host_pool/main.go b/internal/frontends/drawio/handlers/host_pool/main.go index 0622550..56b6a05 100644 --- a/internal/frontends/drawio/handlers/host_pool/main.go +++ b/internal/frontends/drawio/handlers/host_pool/main.go @@ -3,8 +3,8 @@ package host_pool import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/key_vault/handler.go b/internal/frontends/drawio/handlers/key_vault/handler.go index 5f191e7..09bf1ac 100644 --- a/internal/frontends/drawio/handlers/key_vault/handler.go +++ b/internal/frontends/drawio/handlers/key_vault/handler.go @@ -3,8 +3,8 @@ package key_vault import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/load_balancer/handler.go b/internal/frontends/drawio/handlers/load_balancer/handler.go index 701bc00..11f9370 100644 --- a/internal/frontends/drawio/handlers/load_balancer/handler.go +++ b/internal/frontends/drawio/handlers/load_balancer/handler.go @@ -3,8 +3,8 @@ package load_balancer import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/load_balancer_frontend/handler.go b/internal/frontends/drawio/handlers/load_balancer_frontend/handler.go index e1ffe7c..99cb8c0 100644 --- a/internal/frontends/drawio/handlers/load_balancer_frontend/handler.go +++ b/internal/frontends/drawio/handlers/load_balancer_frontend/handler.go @@ -3,8 +3,8 @@ package load_balancer_frontend import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/log_analytics/handler.go b/internal/frontends/drawio/handlers/log_analytics/handler.go index 99b47b0..e9e1e23 100644 --- a/internal/frontends/drawio/handlers/log_analytics/handler.go +++ b/internal/frontends/drawio/handlers/log_analytics/handler.go @@ -3,8 +3,8 @@ package log_analytics import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/logic_app/handler.go b/internal/frontends/drawio/handlers/logic_app/handler.go index d954560..ba84bfa 100644 --- a/internal/frontends/drawio/handlers/logic_app/handler.go +++ b/internal/frontends/drawio/handlers/logic_app/handler.go @@ -3,8 +3,8 @@ package logic_app import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/machine_learning_workspace/handler.go b/internal/frontends/drawio/handlers/machine_learning_workspace/handler.go index 8017758..26318b2 100644 --- a/internal/frontends/drawio/handlers/machine_learning_workspace/handler.go +++ b/internal/frontends/drawio/handlers/machine_learning_workspace/handler.go @@ -3,8 +3,8 @@ package machine_learning_workspace import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/nat_gateway/handler.go b/internal/frontends/drawio/handlers/nat_gateway/handler.go index 2d80c5f..65b707c 100644 --- a/internal/frontends/drawio/handlers/nat_gateway/handler.go +++ b/internal/frontends/drawio/handlers/nat_gateway/handler.go @@ -3,8 +3,8 @@ package nat_gateway import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/network_interface/handler.go b/internal/frontends/drawio/handlers/network_interface/handler.go index f79a438..015220a 100644 --- a/internal/frontends/drawio/handlers/network_interface/handler.go +++ b/internal/frontends/drawio/handlers/network_interface/handler.go @@ -3,8 +3,8 @@ package network_interface import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/network_security_group/handler.go b/internal/frontends/drawio/handlers/network_security_group/handler.go index 2cd2e76..72f50bd 100644 --- a/internal/frontends/drawio/handlers/network_security_group/handler.go +++ b/internal/frontends/drawio/handlers/network_security_group/handler.go @@ -3,8 +3,8 @@ package network_security_group import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/node/common.go b/internal/frontends/drawio/handlers/node/common.go index 703b5d2..8a65d18 100644 --- a/internal/frontends/drawio/handlers/node/common.go +++ b/internal/frontends/drawio/handlers/node/common.go @@ -1,8 +1,8 @@ package node import ( - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" "log" "math" diff --git a/internal/frontends/drawio/handlers/node/types.go b/internal/frontends/drawio/handlers/node/types.go index 15016d3..bbe1310 100644 --- a/internal/frontends/drawio/handlers/node/types.go +++ b/internal/frontends/drawio/handlers/node/types.go @@ -1,6 +1,6 @@ package node -import "cloudsketch/internal/frontends/drawio/models" +import "cloudsketch/internal/frontends/models" type Geometry struct { X, Y, Width, Height int diff --git a/internal/frontends/drawio/handlers/postgres_sql_server/handler.go b/internal/frontends/drawio/handlers/postgres_sql_server/handler.go index 11981ee..3637c10 100644 --- a/internal/frontends/drawio/handlers/postgres_sql_server/handler.go +++ b/internal/frontends/drawio/handlers/postgres_sql_server/handler.go @@ -4,8 +4,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/handlers/sql_server" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/private_dns_resolver/handler.go b/internal/frontends/drawio/handlers/private_dns_resolver/handler.go index 7fb9874..6a00c56 100644 --- a/internal/frontends/drawio/handlers/private_dns_resolver/handler.go +++ b/internal/frontends/drawio/handlers/private_dns_resolver/handler.go @@ -3,8 +3,8 @@ package private_dns_resolver import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/private_dns_zone/handler.go b/internal/frontends/drawio/handlers/private_dns_zone/handler.go index e1a302b..d64c5bd 100644 --- a/internal/frontends/drawio/handlers/private_dns_zone/handler.go +++ b/internal/frontends/drawio/handlers/private_dns_zone/handler.go @@ -4,8 +4,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/diagram" "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/private_endpoint/handler.go b/internal/frontends/drawio/handlers/private_endpoint/handler.go index e7d372c..36780fe 100644 --- a/internal/frontends/drawio/handlers/private_endpoint/handler.go +++ b/internal/frontends/drawio/handlers/private_endpoint/handler.go @@ -3,8 +3,8 @@ package private_endpoint import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/private_link_service/handler.go b/internal/frontends/drawio/handlers/private_link_service/handler.go index c870f26..ac1f466 100644 --- a/internal/frontends/drawio/handlers/private_link_service/handler.go +++ b/internal/frontends/drawio/handlers/private_link_service/handler.go @@ -3,8 +3,8 @@ package private_link_service import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/public_ip_address/handler.go b/internal/frontends/drawio/handlers/public_ip_address/handler.go index 5f0f6d5..0c76d11 100644 --- a/internal/frontends/drawio/handlers/public_ip_address/handler.go +++ b/internal/frontends/drawio/handlers/public_ip_address/handler.go @@ -3,8 +3,8 @@ package public_ip_address import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/recovery_service_vault/handler.go b/internal/frontends/drawio/handlers/recovery_service_vault/handler.go index 13a8fd7..a7b95fd 100644 --- a/internal/frontends/drawio/handlers/recovery_service_vault/handler.go +++ b/internal/frontends/drawio/handlers/recovery_service_vault/handler.go @@ -3,8 +3,8 @@ package recovery_service_vault import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/redis/handler.go b/internal/frontends/drawio/handlers/redis/handler.go index 70ef637..04caeb5 100644 --- a/internal/frontends/drawio/handlers/redis/handler.go +++ b/internal/frontends/drawio/handlers/redis/handler.go @@ -3,8 +3,8 @@ package redis import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/route_table/handler.go b/internal/frontends/drawio/handlers/route_table/handler.go index 1129d9e..91fbeaf 100644 --- a/internal/frontends/drawio/handlers/route_table/handler.go +++ b/internal/frontends/drawio/handlers/route_table/handler.go @@ -3,8 +3,8 @@ package route_table import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/search_service/handler.go b/internal/frontends/drawio/handlers/search_service/handler.go index cad21ae..e7ca0df 100644 --- a/internal/frontends/drawio/handlers/search_service/handler.go +++ b/internal/frontends/drawio/handlers/search_service/handler.go @@ -3,8 +3,8 @@ package search_service import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/signalr/handler.go b/internal/frontends/drawio/handlers/signalr/handler.go index 18dacfa..fbb33a6 100644 --- a/internal/frontends/drawio/handlers/signalr/handler.go +++ b/internal/frontends/drawio/handlers/signalr/handler.go @@ -3,8 +3,8 @@ package signalr import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/sql_database/handler.go b/internal/frontends/drawio/handlers/sql_database/handler.go index 55d0c5b..8d13e04 100644 --- a/internal/frontends/drawio/handlers/sql_database/handler.go +++ b/internal/frontends/drawio/handlers/sql_database/handler.go @@ -3,8 +3,8 @@ package sql_database import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/sql_server/handler.go b/internal/frontends/drawio/handlers/sql_server/handler.go index 6aafbbd..99f7f6d 100644 --- a/internal/frontends/drawio/handlers/sql_server/handler.go +++ b/internal/frontends/drawio/handlers/sql_server/handler.go @@ -3,8 +3,8 @@ package sql_server import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/static_web_app/handler.go b/internal/frontends/drawio/handlers/static_web_app/handler.go index d9131fe..08234cf 100644 --- a/internal/frontends/drawio/handlers/static_web_app/handler.go +++ b/internal/frontends/drawio/handlers/static_web_app/handler.go @@ -3,8 +3,8 @@ package static_web_app import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/storage_account/handler.go b/internal/frontends/drawio/handlers/storage_account/handler.go index 99c1da7..5b25b1d 100644 --- a/internal/frontends/drawio/handlers/storage_account/handler.go +++ b/internal/frontends/drawio/handlers/storage_account/handler.go @@ -3,8 +3,8 @@ package storage_account import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/subnet/handler.go b/internal/frontends/drawio/handlers/subnet/handler.go index e791308..0dd9cbc 100644 --- a/internal/frontends/drawio/handlers/subnet/handler.go +++ b/internal/frontends/drawio/handlers/subnet/handler.go @@ -5,8 +5,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/diagram" "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" "fmt" ) diff --git a/internal/frontends/drawio/handlers/subscription/handler.go b/internal/frontends/drawio/handlers/subscription/handler.go index 9e57469..4f20cee 100644 --- a/internal/frontends/drawio/handlers/subscription/handler.go +++ b/internal/frontends/drawio/handlers/subscription/handler.go @@ -5,8 +5,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/diagram" "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" ) diff --git a/internal/frontends/drawio/handlers/user_assigned_identity/handler.go b/internal/frontends/drawio/handlers/user_assigned_identity/handler.go index e21059a..7daec16 100644 --- a/internal/frontends/drawio/handlers/user_assigned_identity/handler.go +++ b/internal/frontends/drawio/handlers/user_assigned_identity/handler.go @@ -3,8 +3,8 @@ package user_assigned_identity import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/virtual_hub/handler.go b/internal/frontends/drawio/handlers/virtual_hub/handler.go index 0aabf91..a367a3d 100644 --- a/internal/frontends/drawio/handlers/virtual_hub/handler.go +++ b/internal/frontends/drawio/handlers/virtual_hub/handler.go @@ -3,8 +3,8 @@ package virtual_hub import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/virtual_machine/handler.go b/internal/frontends/drawio/handlers/virtual_machine/handler.go index 82d8243..8d5de2a 100644 --- a/internal/frontends/drawio/handlers/virtual_machine/handler.go +++ b/internal/frontends/drawio/handlers/virtual_machine/handler.go @@ -3,8 +3,8 @@ package virtual_machine import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/virtual_machine_scale_set/handler.go b/internal/frontends/drawio/handlers/virtual_machine_scale_set/handler.go index c718871..ed22eb4 100644 --- a/internal/frontends/drawio/handlers/virtual_machine_scale_set/handler.go +++ b/internal/frontends/drawio/handlers/virtual_machine_scale_set/handler.go @@ -3,8 +3,8 @@ package virtual_machine_scale_set import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/virtual_network/handler.go b/internal/frontends/drawio/handlers/virtual_network/handler.go index 18d2a89..2b034c7 100644 --- a/internal/frontends/drawio/handlers/virtual_network/handler.go +++ b/internal/frontends/drawio/handlers/virtual_network/handler.go @@ -5,8 +5,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/diagram" "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" "fmt" ) diff --git a/internal/frontends/drawio/handlers/virtual_network_gateway/handler.go b/internal/frontends/drawio/handlers/virtual_network_gateway/handler.go index d52fea1..24d3325 100644 --- a/internal/frontends/drawio/handlers/virtual_network_gateway/handler.go +++ b/internal/frontends/drawio/handlers/virtual_network_gateway/handler.go @@ -3,8 +3,8 @@ package virtual_network_gateway import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/virtual_wan/handler.go b/internal/frontends/drawio/handlers/virtual_wan/handler.go index 0932652..caac1e5 100644 --- a/internal/frontends/drawio/handlers/virtual_wan/handler.go +++ b/internal/frontends/drawio/handlers/virtual_wan/handler.go @@ -3,8 +3,8 @@ package virtual_wan import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/handlers/workspace/main.go b/internal/frontends/drawio/handlers/workspace/main.go index 46f77d8..4e2ce8e 100644 --- a/internal/frontends/drawio/handlers/workspace/main.go +++ b/internal/frontends/drawio/handlers/workspace/main.go @@ -3,8 +3,8 @@ package workspace import ( "cloudsketch/internal/frontends/drawio/handlers/node" "cloudsketch/internal/frontends/drawio/images" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" ) type handler struct{} diff --git a/internal/frontends/drawio/main.go b/internal/frontends/drawio/main.go index 6b99fc1..6fd374f 100644 --- a/internal/frontends/drawio/main.go +++ b/internal/frontends/drawio/main.go @@ -60,8 +60,8 @@ import ( "cloudsketch/internal/frontends/drawio/handlers/virtual_network_gateway" "cloudsketch/internal/frontends/drawio/handlers/virtual_wan" "cloudsketch/internal/frontends/drawio/handlers/workspace" - "cloudsketch/internal/frontends/drawio/models" - "cloudsketch/internal/frontends/drawio/types" + "cloudsketch/internal/frontends/models" + "cloudsketch/internal/frontends/types" "cloudsketch/internal/list" "fmt" diff --git a/internal/frontends/frontend.go b/internal/frontends/frontend.go index a875c86..2a5089e 100644 --- a/internal/frontends/frontend.go +++ b/internal/frontends/frontend.go @@ -1,6 +1,6 @@ package frontends -import "cloudsketch/internal/frontends/drawio/models" +import "cloudsketch/internal/frontends/models" type Frontend interface { WriteDiagram(resources []*models.Resource, filename string) error diff --git a/internal/frontends/drawio/models/resource.go b/internal/frontends/models/resource.go similarity index 100% rename from internal/frontends/drawio/models/resource.go rename to internal/frontends/models/resource.go diff --git a/internal/frontends/drawio/types/types.go b/internal/frontends/types/types.go similarity index 100% rename from internal/frontends/drawio/types/types.go rename to internal/frontends/types/types.go diff --git a/internal/providers/azure/main.go b/internal/providers/azure/main.go index 77d5e22..d25ff23 100644 --- a/internal/providers/azure/main.go +++ b/internal/providers/azure/main.go @@ -36,8 +36,8 @@ import ( "log" "strings" - domainModels "cloudsketch/internal/frontends/drawio/models" - domainTypes "cloudsketch/internal/frontends/drawio/types" + domainModels "cloudsketch/internal/frontends/models" + domainTypes "cloudsketch/internal/frontends/types" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" ) diff --git a/internal/providers/provider.go b/internal/providers/provider.go index 0fbfd54..dc96a5f 100644 --- a/internal/providers/provider.go +++ b/internal/providers/provider.go @@ -1,6 +1,6 @@ package providers -import "cloudsketch/internal/frontends/drawio/models" +import "cloudsketch/internal/frontends/models" type Provider interface { FetchResources(subscriptionId string) ([]*models.Resource, string, error) From 988e1fbdb52878cfdb154be64a79f6aadd677263 Mon Sep 17 00:00:00 2001 From: Frederik Martini Date: Tue, 6 May 2025 09:45:06 +0200 Subject: [PATCH 5/9] prepare graph move --- internal/frontends/dot/main.go | 2 +- .../handlers/app_service_plan/handler.go | 12 ++-- .../handlers/application_gateway/handler.go | 6 +- .../drawio/handlers/bastion/handler.go | 6 +- .../drawio/handlers/data_factory/handler.go | 2 +- .../drawio/handlers/nat_gateway/handler.go | 6 +- .../handlers/private_dns_zone/handler.go | 2 +- .../handlers/private_endpoint/handler.go | 4 +- .../drawio/handlers/subnet/handler.go | 16 ++--- .../drawio/handlers/subscription/handler.go | 4 +- .../handlers/virtual_network/handler.go | 4 +- internal/frontends/drawio/main.go | 16 ++--- internal/frontends/models/resource.go | 2 +- internal/providers/azure/main.go | 68 ++++++++++++++++--- 14 files changed, 99 insertions(+), 51 deletions(-) diff --git a/internal/frontends/dot/main.go b/internal/frontends/dot/main.go index c4a6f46..610d61d 100644 --- a/internal/frontends/dot/main.go +++ b/internal/frontends/dot/main.go @@ -29,7 +29,7 @@ func removeChars(s string) string { func (d *dot) WriteDiagram(resources []*models.Resource, filename string) error { tasks := list.Map(resources, func(r *models.Resource) *build_graph.Task { - return build_graph.NewTask(r.Id, r.DependsOn, []string{}, []string{}, func() {}) + return build_graph.NewTask(r.Id, list.Map(r.DependsOn, func(r *models.Resource) string { return r.Id }), []string{}, []string{}, func() {}) }) tasks = list.Map(tasks, func(task *build_graph.Task) *build_graph.Task { diff --git a/internal/frontends/drawio/handlers/app_service_plan/handler.go b/internal/frontends/drawio/handlers/app_service_plan/handler.go index 651a56a..df888f0 100644 --- a/internal/frontends/drawio/handlers/app_service_plan/handler.go +++ b/internal/frontends/drawio/handlers/app_service_plan/handler.go @@ -68,7 +68,7 @@ func (*handler) GroupResources(appServicePlan *models.Resource, resources []*mod allAppServicesInSameSubnet := list.Fold(resourcesInAppServicePlan[1:], true, func(resource *node.ResourceAndNode, matches bool) bool { appServiceSubnet := getAppServiceSubnet(resource.Resource, resources) - return matches && appServiceSubnet == firstAppServiceSubnet + return matches && appServiceSubnet.Id == firstAppServiceSubnet.Id }) if !allAppServicesInSameSubnet { @@ -115,14 +115,14 @@ func (*handler) GroupResources(appServicePlan *models.Resource, resources []*mod node.SetIconRelativeTo(appServicePlanNode, box, node.BOTTOM_LEFT) // add an explicit dependency to the subnet - appServicePlan.DependsOn = append(appServicePlan.DependsOn, *firstAppServiceSubnet) + appServicePlan.DependsOn = append(appServicePlan.DependsOn, firstAppServiceSubnet) return []*node.Node{box} } func getResourcesInAppServicePlan(resources []*models.Resource, aspId string, resource_map *map[string]*node.ResourceAndNode) []*node.ResourceAndNode { azResourcesInAsp := list.Filter(resources, func(resource *models.Resource) bool { - return list.Contains(resource.DependsOn, func(dependency string) bool { return dependency == aspId }) + return list.Contains(resource.DependsOn, func(dependency *models.Resource) bool { return dependency.Id == aspId }) }) resourcesInAsp := list.Map(azResourcesInAsp, func(resource *models.Resource) *node.ResourceAndNode { return (*resource_map)[resource.Id] @@ -130,14 +130,14 @@ func getResourcesInAppServicePlan(resources []*models.Resource, aspId string, re return resourcesInAsp } -func getAppServiceSubnet(appService *models.Resource, resources []*models.Resource) *string { +func getAppServiceSubnet(appService *models.Resource, resources []*models.Resource) *models.Resource { for _, dependency := range appService.DependsOn { resource := list.First(resources, func(resource *models.Resource) bool { - return resource.Id == dependency + return resource.Id == dependency.Id }) if resource.Type == types.SUBNET { - return &resource.Id + return resource } } diff --git a/internal/frontends/drawio/handlers/application_gateway/handler.go b/internal/frontends/drawio/handlers/application_gateway/handler.go index 86db090..3644a87 100644 --- a/internal/frontends/drawio/handlers/application_gateway/handler.go +++ b/internal/frontends/drawio/handlers/application_gateway/handler.go @@ -35,8 +35,8 @@ func (*handler) MapResource(resource *models.Resource) *node.Node { } func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *map[string]*node.ResourceAndNode) *node.Node { - publicIps := list.Filter(resource.Resource.DependsOn, func(dependency string) bool { - r, ok := (*resource_map)[dependency] + publicIps := list.Filter(resource.Resource.DependsOn, func(dependency *models.Resource) bool { + r, ok := (*resource_map)[dependency.Id] if !ok { return false @@ -46,7 +46,7 @@ func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *ma }) if len(publicIps) == 1 { - pipResource := (*resource_map)[publicIps[0]] + pipResource := (*resource_map)[publicIps[0].Id] return node.GroupIconsAndSetPosition(resource.Node, pipResource.Node, node.TOP_RIGHT) } diff --git a/internal/frontends/drawio/handlers/bastion/handler.go b/internal/frontends/drawio/handlers/bastion/handler.go index db9a806..1750971 100644 --- a/internal/frontends/drawio/handlers/bastion/handler.go +++ b/internal/frontends/drawio/handlers/bastion/handler.go @@ -35,8 +35,8 @@ func (*handler) MapResource(resource *models.Resource) *node.Node { } func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *map[string]*node.ResourceAndNode) *node.Node { - publicIps := list.Filter(resource.Resource.DependsOn, func(dependency string) bool { - r, ok := (*resource_map)[dependency] + publicIps := list.Filter(resource.Resource.DependsOn, func(dependency *models.Resource) bool { + r, ok := (*resource_map)[dependency.Id] if !ok { return false @@ -46,7 +46,7 @@ func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *ma }) if len(publicIps) == 1 { - pipResource := (*resource_map)[publicIps[0]] + pipResource := (*resource_map)[publicIps[0].Id] return node.GroupIconsAndSetPosition(resource.Node, pipResource.Node, node.TOP_RIGHT) } diff --git a/internal/frontends/drawio/handlers/data_factory/handler.go b/internal/frontends/drawio/handlers/data_factory/handler.go index 710fa58..8790cf7 100644 --- a/internal/frontends/drawio/handlers/data_factory/handler.go +++ b/internal/frontends/drawio/handlers/data_factory/handler.go @@ -105,7 +105,7 @@ func (*handler) GroupResources(dataFactory *models.Resource, resources []*models func getResourcesInDataFactory(resources []*models.Resource, adfId string, resource_map *map[string]*node.ResourceAndNode) []*node.ResourceAndNode { azResourcesInAsp := list.Filter(resources, func(resource *models.Resource) bool { - return list.Contains(resource.DependsOn, func(dependency string) bool { return dependency == adfId }) + return list.Contains(resource.DependsOn, func(dependency *models.Resource) bool { return dependency.Id == adfId }) }) resourcesInAsp := list.Map(azResourcesInAsp, func(resource *models.Resource) *node.ResourceAndNode { return (*resource_map)[resource.Id] diff --git a/internal/frontends/drawio/handlers/nat_gateway/handler.go b/internal/frontends/drawio/handlers/nat_gateway/handler.go index 65b707c..1e14218 100644 --- a/internal/frontends/drawio/handlers/nat_gateway/handler.go +++ b/internal/frontends/drawio/handlers/nat_gateway/handler.go @@ -35,8 +35,8 @@ func (*handler) MapResource(resource *models.Resource) *node.Node { } func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *map[string]*node.ResourceAndNode) *node.Node { - publicIps := list.Filter(resource.Resource.DependsOn, func(dependency string) bool { - r, ok := (*resource_map)[dependency] + publicIps := list.Filter(resource.Resource.DependsOn, func(dependency *models.Resource) bool { + r, ok := (*resource_map)[dependency.Id] if !ok { return false @@ -46,7 +46,7 @@ func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *ma }) if len(publicIps) == 1 { - pipResource := (*resource_map)[publicIps[0]] + pipResource := (*resource_map)[publicIps[0].Id] return node.GroupIconsAndSetPosition(resource.Node, pipResource.Node, node.TOP_RIGHT) } diff --git a/internal/frontends/drawio/handlers/private_dns_zone/handler.go b/internal/frontends/drawio/handlers/private_dns_zone/handler.go index d64c5bd..479d3cc 100644 --- a/internal/frontends/drawio/handlers/private_dns_zone/handler.go +++ b/internal/frontends/drawio/handlers/private_dns_zone/handler.go @@ -83,7 +83,7 @@ func (*handler) GroupResources(privateDNSZone *models.Resource, resources []*mod func getResourcesInPrivateDNSZone(resources []*models.Resource, adfId string, resource_map *map[string]*node.ResourceAndNode) []*node.ResourceAndNode { azResourcesInAsp := list.Filter(resources, func(resource *models.Resource) bool { - return list.Contains(resource.DependsOn, func(dependency string) bool { return dependency == adfId }) + return list.Contains(resource.DependsOn, func(dependency *models.Resource) bool { return dependency.Id == adfId }) }) resourcesInAsp := list.Map(azResourcesInAsp, func(resource *models.Resource) *node.ResourceAndNode { return (*resource_map)[resource.Id] diff --git a/internal/frontends/drawio/handlers/private_endpoint/handler.go b/internal/frontends/drawio/handlers/private_endpoint/handler.go index 36780fe..a3918c9 100644 --- a/internal/frontends/drawio/handlers/private_endpoint/handler.go +++ b/internal/frontends/drawio/handlers/private_endpoint/handler.go @@ -88,7 +88,7 @@ func (*handler) PostProcessIcon(privateEndpoint *node.ResourceAndNode, resource_ func getPrivateEndpointSubnet(resource *models.Resource, resources []*models.Resource) *string { for _, dependency := range resource.DependsOn { resource := list.FirstOrDefault(resources, nil, func(resource *models.Resource) bool { - return resource.Id == dependency + return resource.Id == dependency.Id }) if resource == nil { @@ -108,7 +108,7 @@ func addImplicitDependencyToFunctionApp(privateEndpoint, functionApp *models.Res // resources inside the plan. If the resource this Private Endpoint is attached to, is a function app // an implicit dependency is added to the App Service to reference for _, dependency := range privateEndpoint.DependsOn { - dependentResource := (*resource_map)[dependency] + dependentResource := (*resource_map)[dependency.Id] if dependentResource == nil { continue diff --git a/internal/frontends/drawio/handlers/subnet/handler.go b/internal/frontends/drawio/handlers/subnet/handler.go index 0dd9cbc..efec81d 100644 --- a/internal/frontends/drawio/handlers/subnet/handler.go +++ b/internal/frontends/drawio/handlers/subnet/handler.go @@ -45,9 +45,9 @@ func (*handler) MapResource(resource *models.Resource) *node.Node { return node.NewIcon(IMAGE, name, &geometry, link) } -func getResourcseOfType(resource *models.Resource, resource_map *map[string]*node.ResourceAndNode, typ string) []string { - return list.Filter(resource.DependsOn, func(dependency string) bool { - r, ok := (*resource_map)[dependency] +func getResourcseOfType(resource *models.Resource, resource_map *map[string]*node.ResourceAndNode, typ string) []*models.Resource { + return list.Filter(resource.DependsOn, func(dependency *models.Resource) bool { + r, ok := (*resource_map)[dependency.Id] if !ok { return false @@ -62,7 +62,7 @@ func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *ma routeTables := getResourcseOfType(resource.Resource, resource_map, types.ROUTE_TABLE) if len(routeTables) == 1 { - routeTable := (*resource_map)[routeTables[0]] + routeTable := (*resource_map)[routeTables[0].Id] parentGroup = node.GroupIconsAndSetPosition(resource.Node, routeTable.Node, node.TOP_LEFT) } @@ -70,7 +70,7 @@ func (*handler) PostProcessIcon(resource *node.ResourceAndNode, resource_map *ma networkSecurityGroups := getResourcseOfType(resource.Resource, resource_map, types.NETWORK_SECURITY_GROUP) if len(networkSecurityGroups) == 1 { - networkSecurityGroup := (*resource_map)[networkSecurityGroups[0]] + networkSecurityGroup := (*resource_map)[networkSecurityGroups[0].Id] // other subnets might point to the same NSG. If they do, ignore the merging if snets := resourcesWithReferencesTo(resource_map, networkSecurityGroup.Resource.Id); snets != 1 { @@ -100,8 +100,8 @@ func resourcesWithReferencesTo(resource_map *map[string]*node.ResourceAndNode, r count := 0 for _, v := range *resource_map { - if list.Contains(v.Resource.DependsOn, func(d string) bool { - return d == resourceId + if list.Contains(v.Resource.DependsOn, func(d *models.Resource) bool { + return d.Id == resourceId }) { count++ } @@ -158,7 +158,7 @@ func (*handler) GroupResources(subnet *models.Resource, resources []*models.Reso func getResourcesInSubnet(resources []*models.Resource, subnetId string, resource_map *map[string]*node.ResourceAndNode) []*node.Node { azResourcesInSubnet := list.Filter(resources, func(resource *models.Resource) bool { - return list.Contains(resource.DependsOn, func(dependency string) bool { return dependency == subnetId }) + return list.Contains(resource.DependsOn, func(dependency *models.Resource) bool { return dependency.Id == subnetId }) }) resourcesInSubnet := list.Map(azResourcesInSubnet, func(resource *models.Resource) *node.Node { return (*resource_map)[resource.Id].Node.GetParentOrThis() diff --git a/internal/frontends/drawio/handlers/subscription/handler.go b/internal/frontends/drawio/handlers/subscription/handler.go index 4f20cee..74e0b6c 100644 --- a/internal/frontends/drawio/handlers/subscription/handler.go +++ b/internal/frontends/drawio/handlers/subscription/handler.go @@ -82,8 +82,8 @@ func (*handler) GroupResources(resource *models.Resource, resources []*models.Re func getAllResourcesInSubscription(resourceId string, resources []*models.Resource, resource_map *map[string]*node.ResourceAndNode) []*node.Node { subscriptionResources := list.Filter(resources, func(r *models.Resource) bool { - return list.Contains(r.DependsOn, func(dependency string) bool { - return dependency == resourceId + return list.Contains(r.DependsOn, func(dependency *models.Resource) bool { + return dependency.Id == resourceId }) }) diff --git a/internal/frontends/drawio/handlers/virtual_network/handler.go b/internal/frontends/drawio/handlers/virtual_network/handler.go index 2b034c7..44488ac 100644 --- a/internal/frontends/drawio/handlers/virtual_network/handler.go +++ b/internal/frontends/drawio/handlers/virtual_network/handler.go @@ -98,8 +98,8 @@ func (*handler) GroupResources(vnet *models.Resource, resources []*models.Resour func getAllResourcesInVnet(vnetId string, resources []*models.Resource, resource_map *map[string]*node.ResourceAndNode) []*node.Node { subnets := list.Filter(resources, func(r *models.Resource) bool { - return list.Contains(r.DependsOn, func(dependency string) bool { - return dependency == vnetId + return list.Contains(r.DependsOn, func(dependency *models.Resource) bool { + return dependency.Id == vnetId }) }) diff --git a/internal/frontends/drawio/main.go b/internal/frontends/drawio/main.go index 6fd374f..33df09a 100644 --- a/internal/frontends/drawio/main.go +++ b/internal/frontends/drawio/main.go @@ -208,9 +208,9 @@ func (d *drawio) WriteDiagram(resources []*models.Resource, filename string) err func filterUnknownDependencies(resources []*models.Resource) []*models.Resource { for _, resource := range resources { - resource.DependsOn = list.Filter(resource.DependsOn, func(d string) bool { + resource.DependsOn = list.Filter(resource.DependsOn, func(d *models.Resource) bool { dependency := list.FirstOrDefault(resources, nil, func(r *models.Resource) bool { - return r.Id == d + return r.Id == d.Id }) return dependency != nil @@ -228,7 +228,7 @@ func populateResourceMap(resources []*models.Resource) (*map[string]*node.Resour resources = filterUnknownDependencies(resources) tasks := list.Map(resources, func(r *models.Resource) *build_graph.Task { - return build_graph.NewTask(r.Id, r.DependsOn, []string{}, []string{}, func() { drawResource(r, unhandled_resources, resource_map) }) + return build_graph.NewTask(r.Id, list.Map(r.DependsOn, func(m *models.Resource) string { return m.Id }), []string{}, []string{}, func() { drawResource(r, unhandled_resources, resource_map) }) }) bg, err := build_graph.NewGraph(tasks) @@ -300,18 +300,18 @@ func addDependencies(resource_map *map[string]*node.ResourceAndNode) []*node.Arr log.Fatalf("type %s has not been registered for rendering", resource.Type) } - dependencyIds := list.Filter(resource.DependsOn, func(dependency string) bool { - targetMissing := (*resource_map)[dependency] == nil || (*resource_map)[dependency].Node == nil + dependencyIds := list.Filter(resource.DependsOn, func(dependency *models.Resource) bool { + targetMissing := (*resource_map)[dependency.Id] == nil || (*resource_map)[dependency.Id].Node == nil if targetMissing { - log.Printf("target %s was not drawn, skipping", dependency) + log.Printf("target %s was not drawn, skipping", dependency.Id) return false } return true }) - resources := list.Map(dependencyIds, func(dependency string) *models.Resource { - return (*resource_map)[dependency].Resource + resources := list.Map(dependencyIds, func(dependency *models.Resource) *models.Resource { + return (*resource_map)[dependency.Id].Resource }) arrowsToAdd := f.DrawDependencies(resource, resources, resource_map) diff --git a/internal/frontends/models/resource.go b/internal/frontends/models/resource.go index 400d687..31aba0a 100644 --- a/internal/frontends/models/resource.go +++ b/internal/frontends/models/resource.go @@ -2,7 +2,7 @@ package models type Resource struct { Id, Type, Name string - DependsOn []string + DependsOn []*Resource Properties map[string][]string } diff --git a/internal/providers/azure/main.go b/internal/providers/azure/main.go index d25ff23..212e34a 100644 --- a/internal/providers/azure/main.go +++ b/internal/providers/azure/main.go @@ -2,6 +2,7 @@ package azure import ( "cloudsketch/internal/concurrency" + "cloudsketch/internal/datastructures/build_graph" "cloudsketch/internal/datastructures/set" "cloudsketch/internal/list" "cloudsketch/internal/marshall" @@ -118,7 +119,9 @@ func (h *azureProvider) FetchResources(subscriptionId string) ([]*domainModels.R postProcess(resources) - domainModels, err := mapResources(resources, subscription, ctx) + addDependencyToSubscriptions(resources, subscription) + + domainModels, err := mapToDomainModels(resources, ctx) if err != nil { return nil, "", err @@ -134,6 +137,17 @@ func (h *azureProvider) FetchResources(subscriptionId string) ([]*domainModels.R return domainModels, filename, nil } +func addDependencyToSubscriptions(resources []*models.Resource, subscription *azContext.SubscriptionContext) { + // all resources should have a dependency on the subscription. Except the subscription itself + for _, resource := range resources { + if resource.Id == subscription.ResourceId { + continue + } + + resource.DependsOn = append(resource.DependsOn, subscription.ResourceId) + } +} + func fetchResources(subscription *azContext.SubscriptionContext, ctx *azContext.Context) ([]*models.Resource, error) { resources, err := resource_group.New().Handle(ctx) @@ -195,25 +209,57 @@ func postProcess(resources []*models.Resource) { } } -func mapResources(resources []*models.Resource, subscription *azContext.SubscriptionContext, ctx *azContext.Context) ([]*domainModels.Resource, error) { - // all resources should have a dependency on the subscription. Except the subscription itself +func filterUnknownDependencies(resources []*models.Resource) []*models.Resource { for _, resource := range resources { - if resource.Id == subscription.ResourceId { - continue - } + resource.DependsOn = list.Filter(resource.DependsOn, func(d string) bool { + dependency := list.FirstOrDefault(resources, nil, func(r *models.Resource) bool { + return r.Id == d + }) - resource.DependsOn = append(resource.DependsOn, subscription.ResourceId) + return dependency != nil + }) } + return resources +} + +func mapToDomainModels(resources []*models.Resource, ctx *azContext.Context) ([]*domainModels.Resource, error) { unhandled_types := set.New[string]() + resource_map := &map[string]*models.Resource{} + + // input resources can contain references to resources that do not exist (in other subscriptions for example). These need to be removed + resources = filterUnknownDependencies(resources) + + tasks := list.Map(resources, func(r *models.Resource) *build_graph.Task { + return build_graph.NewTask(r.Id, r.DependsOn, []string{}, []string{}, func() { drawResource(r, resource_map) }) + }) + + bg, err := build_graph.NewGraph(tasks) + + if err != nil { + return nil, fmt.Errorf("error during construction of dependency graph: %+v", err) + } + + for _, task := range tasks { + bg.Resolve(task) + } + domainResources := list.Map(resources, func(r *models.Resource) *domainModels.Resource { - return mapToDomainResource(r, ctx.TenantId, unhandled_types) + return mapToDomainResource(r, ctx.TenantId, unhandled_types, resources, resource_map) }) return domainResources, nil } -func mapToDomainResource(resource *models.Resource, tenantId string, unhandled_types *set.Set[string]) *domainModels.Resource { +func drawResource(resource *models.Resource, resource_map *map[string]*models.Resource) { + if (*resource_map)[resource.Id] != nil { + // resource already registered + return + } + (*resource_map)[resource.Id] = resource +} + +func mapToDomainResource(resource *models.Resource, tenantId string, unhandled_types *set.Set[string], resources []*models.Resource, resource_map *map[string]*models.Resource) *domainModels.Resource { properties := resource.Properties if properties == nil { @@ -223,12 +269,14 @@ func mapToDomainResource(resource *models.Resource, tenantId string, unhandled_t link := generateAzurePortalLink(resource, tenantId) properties["link"] = []string{link} + //TODO: do something clever with the BG + // Azure is not consistent regarding casing. Ensure all id's are lowercase return &domainModels.Resource{ Id: strings.ToLower(resource.Id), Type: mapTypeToDomainType(resource.Type, unhandled_types), Name: resource.Name, - DependsOn: list.Map(resource.DependsOn, strings.ToLower), + DependsOn: []*domainModels.Resource{}, //list.Map(resource.DependsOn, strings.ToLower), Properties: properties, } } From 86ccdea9d4ec1467da6fe2e5fbbc62cbbe71f1bb Mon Sep 17 00:00:00 2001 From: Frederik Martini Date: Tue, 6 May 2025 12:45:55 +0200 Subject: [PATCH 6/9] resolveinverse --- .../datastructures/build_graph/build_graph.go | 38 +++++++++---- internal/frontends/drawio/main.go | 2 +- internal/providers/azure/main.go | 55 +++++++++++++------ 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/internal/datastructures/build_graph/build_graph.go b/internal/datastructures/build_graph/build_graph.go index b948cc6..8cd056a 100644 --- a/internal/datastructures/build_graph/build_graph.go +++ b/internal/datastructures/build_graph/build_graph.go @@ -9,8 +9,8 @@ import ( type Build_graph struct { Tasks []*Task - Graph map[*Task][]*Task - Inverse_graph map[*Task][]*Task + Graph map[string][]*Task + Inverse_graph map[string][]*Task } func NewGraph(tasks []*Task) (*Build_graph, error) { @@ -45,9 +45,9 @@ func NewTask(label string, references, inputs, outputs []string, action func()) } } -func buildGraph(tasks []*Task) (map[*Task][]*Task, map[*Task][]*Task, error) { - graph := map[*Task][]*Task{} - inverse_graph := map[*Task][]*Task{} +func buildGraph(tasks []*Task) (map[string][]*Task, map[string][]*Task, error) { + graph := map[string][]*Task{} + inverse_graph := map[string][]*Task{} // sort tasks lowest amount of dependencies first sort.Slice(tasks, func(i, j int) bool { @@ -60,9 +60,9 @@ func buildGraph(tasks []*Task) (map[*Task][]*Task, map[*Task][]*Task, error) { } for _, task := range tasks { - _, ok := graph[task] + _, ok := graph[task.Label] if !ok { - graph[task] = []*Task{} + graph[task.Label] = []*Task{} } for _, reference := range task.References { @@ -74,22 +74,36 @@ func buildGraph(tasks []*Task) (map[*Task][]*Task, map[*Task][]*Task, error) { return nil, nil, fmt.Errorf("an unknown task was referenced %s", reference) } - graph[task] = append(graph[task], dependentTask) + graph[task.Label] = append(graph[task.Label], dependentTask) - _, ok := inverse_graph[task] + _, ok := inverse_graph[task.Label] if !ok { - inverse_graph[task] = []*Task{} + inverse_graph[task.Label] = []*Task{} } - inverse_graph[dependentTask] = append(inverse_graph[dependentTask], task) + inverse_graph[dependentTask.Label] = append(inverse_graph[dependentTask.Label], task) } } return graph, inverse_graph, nil } +func (g *Build_graph) ResolveInverse(t *Task) { + e := g.Inverse_graph[t.Label] + + for _, ref := range e { + // recursively resolve the tasks dependencies + g.ResolveInverse(ref) + } + + // when the task has no dependencies it can be resolved + t.Action() +} + func (g *Build_graph) Resolve(t *Task) { - for _, ref := range g.Inverse_graph[t] { + e := g.Graph[t.Label] + + for _, ref := range e { // recursively resolve the tasks dependencies g.Resolve(ref) } diff --git a/internal/frontends/drawio/main.go b/internal/frontends/drawio/main.go index 33df09a..5f4ea7e 100644 --- a/internal/frontends/drawio/main.go +++ b/internal/frontends/drawio/main.go @@ -238,7 +238,7 @@ func populateResourceMap(resources []*models.Resource) (*map[string]*node.Resour } for _, task := range tasks { - bg.Resolve(task) + bg.ResolveInverse(task) } return resource_map, nil diff --git a/internal/providers/azure/main.go b/internal/providers/azure/main.go index 212e34a..8f354ee 100644 --- a/internal/providers/azure/main.go +++ b/internal/providers/azure/main.go @@ -121,6 +121,11 @@ func (h *azureProvider) FetchResources(subscriptionId string) ([]*domainModels.R addDependencyToSubscriptions(resources, subscription) + resources = normalize(resources) + + // input resources can contain references to resources that do not exist (in other subscriptions for example). These need to be removed + resources = filterUnknownDependencies(resources) + domainModels, err := mapToDomainModels(resources, ctx) if err != nil { @@ -137,6 +142,18 @@ func (h *azureProvider) FetchResources(subscriptionId string) ([]*domainModels.R return domainModels, filename, nil } +func normalize(resources []*models.Resource) []*models.Resource { + return list.Map(resources, func(resource *models.Resource) *models.Resource { + return &models.Resource{ + Id: strings.ToLower(resource.Id), // Azure is not consistent regarding casing. Ensure all id's are lowercase + Type: resource.Type, + Name: resource.Name, + DependsOn: list.Map(resource.DependsOn, strings.ToLower), + Properties: resource.Properties, + } + }) +} + func addDependencyToSubscriptions(resources []*models.Resource, subscription *azContext.SubscriptionContext) { // all resources should have a dependency on the subscription. Except the subscription itself for _, resource := range resources { @@ -225,13 +242,10 @@ func filterUnknownDependencies(resources []*models.Resource) []*models.Resource func mapToDomainModels(resources []*models.Resource, ctx *azContext.Context) ([]*domainModels.Resource, error) { unhandled_types := set.New[string]() - resource_map := &map[string]*models.Resource{} - - // input resources can contain references to resources that do not exist (in other subscriptions for example). These need to be removed - resources = filterUnknownDependencies(resources) + resource_map := &map[string]*domainModels.Resource{} tasks := list.Map(resources, func(r *models.Resource) *build_graph.Task { - return build_graph.NewTask(r.Id, r.DependsOn, []string{}, []string{}, func() { drawResource(r, resource_map) }) + return build_graph.NewTask(r.Id, list.Map(r.DependsOn, strings.ToLower), []string{}, []string{}, func() { mapToDomainResource(r, ctx.TenantId, unhandled_types, resource_map) }) }) bg, err := build_graph.NewGraph(tasks) @@ -244,22 +258,20 @@ func mapToDomainModels(resources []*models.Resource, ctx *azContext.Context) ([] bg.Resolve(task) } - domainResources := list.Map(resources, func(r *models.Resource) *domainModels.Resource { - return mapToDomainResource(r, ctx.TenantId, unhandled_types, resources, resource_map) - }) + domainResources := []*domainModels.Resource{} + for _, v := range *resource_map { + domainResources = append(domainResources, v) + } return domainResources, nil } -func drawResource(resource *models.Resource, resource_map *map[string]*models.Resource) { +func mapToDomainResource(resource *models.Resource, tenantId string, unhandled_types *set.Set[string], resource_map *map[string]*domainModels.Resource) { if (*resource_map)[resource.Id] != nil { // resource already registered return } - (*resource_map)[resource.Id] = resource -} -func mapToDomainResource(resource *models.Resource, tenantId string, unhandled_types *set.Set[string], resources []*models.Resource, resource_map *map[string]*models.Resource) *domainModels.Resource { properties := resource.Properties if properties == nil { @@ -269,15 +281,22 @@ func mapToDomainResource(resource *models.Resource, tenantId string, unhandled_t link := generateAzurePortalLink(resource, tenantId) properties["link"] = []string{link} - //TODO: do something clever with the BG + dependencies := list.Map(resource.DependsOn, func(d string) *domainModels.Resource { + return (*resource_map)[d] + }) + + if list.Contains(dependencies, func(d *domainModels.Resource) bool { + return d == nil + }) { + panic("dependency was nil") + } - // Azure is not consistent regarding casing. Ensure all id's are lowercase - return &domainModels.Resource{ - Id: strings.ToLower(resource.Id), + (*resource_map)[resource.Id] = &domainModels.Resource{ + Id: resource.Id, Type: mapTypeToDomainType(resource.Type, unhandled_types), Name: resource.Name, - DependsOn: []*domainModels.Resource{}, //list.Map(resource.DependsOn, strings.ToLower), - Properties: properties, + DependsOn: dependencies, + Properties: resource.Properties, } } From 784560ec23530478e1bfd771caf6c7c6025b0113 Mon Sep 17 00:00:00 2001 From: Frederik Martini Date: Wed, 7 May 2025 15:39:56 +0200 Subject: [PATCH 7/9] implement dot frontend --- cmd/cloudsketch.go | 107 ++++++++++--- example/example.dot | 18 +-- example/example.drawio | 26 ++-- internal/frontends/dot/main.go | 9 +- .../handlers/network_interface/handler.go | 16 +- internal/frontends/drawio/main.go | 17 --- internal/providers/azure/main.go | 143 ++++++------------ internal/providers/provider.go | 4 +- internal/providers/resource.go | 7 + 9 files changed, 186 insertions(+), 161 deletions(-) create mode 100644 internal/providers/resource.go diff --git a/cmd/cloudsketch.go b/cmd/cloudsketch.go index b90c267..4c5e969 100644 --- a/cmd/cloudsketch.go +++ b/cmd/cloudsketch.go @@ -1,10 +1,12 @@ package cmd import ( + "cloudsketch/internal/datastructures/build_graph" "cloudsketch/internal/frontends" "cloudsketch/internal/frontends/dot" "cloudsketch/internal/frontends/drawio" - "cloudsketch/internal/frontends/models" + frontendModels "cloudsketch/internal/frontends/models" + "cloudsketch/internal/list" "cloudsketch/internal/marshall" "cloudsketch/internal/providers" "cloudsketch/internal/providers/azure" @@ -45,54 +47,119 @@ func newCloudsketch(_ context.Context, command *cli.Command) error { log.Printf("target frontend is %s\n", frontendString) log.Printf("target provider is %s\n", providerString) + var resources []*providers.Resource + var filename string + // command can either be a subscription id or a file name if strings.HasSuffix(fileOrSubscriptionId, ".json") { // if the file ends in .json, assume its a valid json file that contains previously populated Azure resources - return useExistingFile(fileOrSubscriptionId, frontendString, frontend) - } + existingResources, existingFilename, err := useExistingFile(fileOrSubscriptionId, frontendString) - // otherwise treat it as a subscription id - return createNewFile(fileOrSubscriptionId, providerString, frontendString, frontend) -} + if err != nil { + return err + } -func useExistingFile(file, frontendString string, frontend frontends.Frontend) error { - log.Printf("using existing file %s\n", file) + resources = existingResources + filename = existingFilename + } else { + // otherwise treat it as a subscription id + existingResources, existingFilename, err := createNewFile(fileOrSubscriptionId, providerString, frontendString) + + if err != nil { + return err + } - resources, err := marshall.UnmarshallResources[[]*models.Resource](file) + resources = existingResources + filename = existingFilename + } + + frontendResources, err := mapToDomainModels(resources) if err != nil { return err } - outFile := strings.ReplaceAll(file, ".json", fmt.Sprintf(".%s", frontendString)) - - if err := frontend.WriteDiagram(*resources, outFile); err != nil { + if err := frontend.WriteDiagram(frontendResources, filename); err != nil { return err } // execution succesful. Print the output file name - log.Print(outFile) + log.Print(filename) return nil } -func createNewFile(subscriptionId, providerString, frontendString string, frontend frontends.Frontend) error { +func useExistingFile(file, frontendString string) ([]*providers.Resource, string, error) { + log.Printf("using existing file %s\n", file) + + resources, err := marshall.UnmarshallResources[[]*providers.Resource](file) + + if err != nil { + return nil, "", err + } + + outFile := strings.ReplaceAll(file, ".json", fmt.Sprintf(".%s", frontendString)) + + return *resources, outFile, nil +} + +func createNewFile(subscriptionId, providerString, frontendString string) ([]*providers.Resource, string, error) { provider := providermap[providerString] resources, filename, err := provider.FetchResources(subscriptionId) if err != nil { - return err + return nil, "", err } + // cache resources for next run + err = marshall.MarshallResources(fmt.Sprintf("%s.json", filename), resources) + filename = fmt.Sprintf("%s.%s", filename, frontendString) - if err := frontend.WriteDiagram(resources, filename); err != nil { - return err + return resources, filename, err +} + +func mapToDomainModels(resources []*providers.Resource) ([]*frontendModels.Resource, error) { + resource_map := &map[string]*frontendModels.Resource{} + + tasks := list.Map(resources, func(r *providers.Resource) *build_graph.Task { + return build_graph.NewTask(r.Id, r.DependsOn, []string{}, []string{}, func() { addDependenciesFromIds(r, resource_map) }) + }) + + bg, err := build_graph.NewGraph(tasks) + + if err != nil { + return nil, fmt.Errorf("error during construction of dependency graph: %+v", err) } - // execution succesful. Print the output file name - log.Print(filename) + for _, task := range tasks { + bg.Resolve(task) + } - return nil + domainResources := []*frontendModels.Resource{} + for _, v := range *resource_map { + domainResources = append(domainResources, v) + } + + return domainResources, nil +} + +func addDependenciesFromIds(resource *providers.Resource, resource_map *map[string]*frontendModels.Resource) { + if (*resource_map)[resource.Id] != nil { + // resource already registered + return + } + + dependencies := list.Map(resource.DependsOn, func(d string) *frontendModels.Resource { + return (*resource_map)[d] + }) + + (*resource_map)[resource.Id] = &frontendModels.Resource{ + Id: resource.Id, + Type: resource.Type, + Name: resource.Name, + DependsOn: dependencies, + Properties: resource.Properties, + } } diff --git a/example/example.dot b/example/example.dot index 41d6dca..5d83c3b 100644 --- a/example/example.dot +++ b/example/example.dot @@ -1,11 +1,11 @@ digraph exampleexample { - subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnetsubnetsexamplesnet -> subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnet; - subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnetsubnetsexamplesnet -> subscriptions00000000000000000000000000000000; - subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftcomputevirtualmachinescalesetsexamplevmss -> subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnetsubnetsexamplesnet; - subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftcomputevirtualmachinescalesetsexamplevmss -> subscriptions00000000000000000000000000000000; - subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworknetworkinterfacesexamplenic -> subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnetsubnetsexamplesnet; - subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworknetworkinterfacesexamplenic -> subscriptions00000000000000000000000000000000; - subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftcomputevirtualmachinesexamplevm -> subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworknetworkinterfacesexamplenic; - subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftcomputevirtualmachinesexamplevm -> subscriptions00000000000000000000000000000000; - subscriptions00000000000000000000000000000000resourcegroupsexampleresourcegroupprovidersmicrosoftnetworkvirtualnetworksexamplevnet -> subscriptions00000000000000000000000000000000; + examplevm -> examplenic; + examplevm -> examplesubscription; + examplesnet -> examplevnet; + examplesnet -> examplesubscription; + examplevmss -> examplesnet; + examplevmss -> examplesubscription; + examplenic -> examplesnet; + examplenic -> examplesubscription; + examplevnet -> examplesubscription; } \ No newline at end of file diff --git a/example/example.drawio b/example/example.drawio index 3027dc6..e6abc21 100644 --- a/example/example.drawio +++ b/example/example.drawio @@ -1,37 +1,37 @@ - + - + - + - + - + - - + + - + - + - + - - + + - + diff --git a/internal/frontends/dot/main.go b/internal/frontends/dot/main.go index 610d61d..6b38814 100644 --- a/internal/frontends/dot/main.go +++ b/internal/frontends/dot/main.go @@ -29,7 +29,7 @@ func removeChars(s string) string { func (d *dot) WriteDiagram(resources []*models.Resource, filename string) error { tasks := list.Map(resources, func(r *models.Resource) *build_graph.Task { - return build_graph.NewTask(r.Id, list.Map(r.DependsOn, func(r *models.Resource) string { return r.Id }), []string{}, []string{}, func() {}) + return build_graph.NewTask(r.Name, list.Map(r.DependsOn, func(r *models.Resource) string { return r.Name }), []string{}, []string{}, func() {}) }) tasks = list.Map(tasks, func(task *build_graph.Task) *build_graph.Task { @@ -48,6 +48,13 @@ func (d *dot) WriteDiagram(resources []*models.Resource, filename string) error } graphName := removeChars(strings.ReplaceAll(filename, ".dot", "")) + + // directory + if strings.Contains("/", graphName) { + s := strings.Split(graphName, "/") + graphName = s[len(s)-1] + } + content := ToDotFile(bg, graphName) f, err := os.Create(filename) diff --git a/internal/frontends/drawio/handlers/network_interface/handler.go b/internal/frontends/drawio/handlers/network_interface/handler.go index 015220a..c1f32fb 100644 --- a/internal/frontends/drawio/handlers/network_interface/handler.go +++ b/internal/frontends/drawio/handlers/network_interface/handler.go @@ -35,7 +35,13 @@ func (*handler) MapResource(resource *models.Resource) *node.Node { } func (*handler) PostProcessIcon(nic *node.ResourceAndNode, resource_map *map[string]*node.ResourceAndNode) *node.Node { - attachedTo, ok := (*resource_map)[nic.Resource.Properties["attachedTo"][0]] + attachedToIds, ok := nic.Resource.Properties["attachedTo"] + + if !ok { + return nil + } + + attachedTo, ok := (*resource_map)[attachedToIds[0]] // dont draw NICs if they are attached to a blacklisted resource if !ok || isBlacklistedResource(attachedTo.Resource.Type) { @@ -72,7 +78,13 @@ func getNICsPointingToResource(resource_map *map[string]*node.ResourceAndNode, a continue } - if v.Resource.Properties["attachedTo"][0] != attachedResource.Id { + attachedTo, ok := v.Resource.Properties["attachedTo"] + + if !ok { + continue + } + + if attachedTo[0] != attachedResource.Id { continue } diff --git a/internal/frontends/drawio/main.go b/internal/frontends/drawio/main.go index 5f4ea7e..85b964a 100644 --- a/internal/frontends/drawio/main.go +++ b/internal/frontends/drawio/main.go @@ -206,27 +206,10 @@ func (d *drawio) WriteDiagram(resources []*models.Resource, filename string) err return dgrm.Write(filename) } -func filterUnknownDependencies(resources []*models.Resource) []*models.Resource { - for _, resource := range resources { - resource.DependsOn = list.Filter(resource.DependsOn, func(d *models.Resource) bool { - dependency := list.FirstOrDefault(resources, nil, func(r *models.Resource) bool { - return r.Id == d.Id - }) - - return dependency != nil - }) - } - - return resources -} - func populateResourceMap(resources []*models.Resource) (*map[string]*node.ResourceAndNode, error) { resource_map := &map[string]*node.ResourceAndNode{} unhandled_resources := set.New[string]() - // input resources can contain references to resources that do not exist (in other subscriptions for example). These need to be removed - resources = filterUnknownDependencies(resources) - tasks := list.Map(resources, func(r *models.Resource) *build_graph.Task { return build_graph.NewTask(r.Id, list.Map(r.DependsOn, func(m *models.Resource) string { return m.Id }), []string{}, []string{}, func() { drawResource(r, unhandled_resources, resource_map) }) }) diff --git a/internal/providers/azure/main.go b/internal/providers/azure/main.go index 8f354ee..bfacf18 100644 --- a/internal/providers/azure/main.go +++ b/internal/providers/azure/main.go @@ -2,10 +2,10 @@ package azure import ( "cloudsketch/internal/concurrency" - "cloudsketch/internal/datastructures/build_graph" "cloudsketch/internal/datastructures/set" "cloudsketch/internal/list" "cloudsketch/internal/marshall" + "cloudsketch/internal/providers" azContext "cloudsketch/internal/providers/azure/context" "cloudsketch/internal/providers/azure/handlers/application_gateway" "cloudsketch/internal/providers/azure/handlers/application_group" @@ -37,7 +37,6 @@ import ( "log" "strings" - domainModels "cloudsketch/internal/frontends/models" domainTypes "cloudsketch/internal/frontends/types" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" @@ -81,7 +80,7 @@ func NewProvider() *azureProvider { return &azureProvider{} } -func (h *azureProvider) FetchResources(subscriptionId string) ([]*domainModels.Resource, string, error) { +func (h *azureProvider) FetchResources(subscriptionId string) ([]*providers.Resource, string, error) { credentials, err := azidentity.NewDefaultAzureCredential(nil) if err != nil { @@ -103,12 +102,12 @@ func (h *azureProvider) FetchResources(subscriptionId string) ([]*domainModels.R filename := fmt.Sprintf("%s_%s", subscription.Name, subscription.Id) filenameWithSuffix := fmt.Sprintf("%s.json", filename) - cachedResources, ok := marshall.UnmarshalIfExists[[]*domainModels.Resource](filenameWithSuffix) + cachedResources, ok := marshall.UnmarshalIfExists[[]*models.Resource](filenameWithSuffix) if ok { log.Printf("using existing file %s\n", filenameWithSuffix) - return *cachedResources, filename, nil + return mapToProviderModel(*cachedResources), filename, nil } resources, err := fetchResources(subscription, ctx) @@ -121,39 +120,51 @@ func (h *azureProvider) FetchResources(subscriptionId string) ([]*domainModels.R addDependencyToSubscriptions(resources, subscription) - resources = normalize(resources) + resources = normalize(resources, ctx.TenantId, set.New[string]()) // input resources can contain references to resources that do not exist (in other subscriptions for example). These need to be removed resources = filterUnknownDependencies(resources) - domainModels, err := mapToDomainModels(resources, ctx) - - if err != nil { - return nil, "", err - } - - // cache resources for next run - err = marshall.MarshallResources(filenameWithSuffix, domainModels) - - if err != nil { - return nil, "", err - } + return mapToProviderModel(resources), filename, nil +} - return domainModels, filename, nil +func mapToProviderModel(resources []*models.Resource) []*providers.Resource { + return list.Map(resources, func(m *models.Resource) *providers.Resource { + return &providers.Resource{ + Id: m.Id, + Name: m.Name, + Type: m.Type, + DependsOn: m.DependsOn, + Properties: m.Properties, + } + }) } -func normalize(resources []*models.Resource) []*models.Resource { +func normalize(resources []*models.Resource, tenantId string, unhandled_types *set.Set[string]) []*models.Resource { return list.Map(resources, func(resource *models.Resource) *models.Resource { return &models.Resource{ Id: strings.ToLower(resource.Id), // Azure is not consistent regarding casing. Ensure all id's are lowercase - Type: resource.Type, + Type: mapTypeToDomainType(resource.Type, unhandled_types), Name: resource.Name, DependsOn: list.Map(resource.DependsOn, strings.ToLower), - Properties: resource.Properties, + Properties: linkOrDefault(resource, tenantId), } }) } +func linkOrDefault(resource *models.Resource, tenantId string) map[string][]string { + properties := resource.Properties + + if properties == nil { + properties = map[string][]string{} + } + + link := generateAzurePortalLink(resource, tenantId) + properties["link"] = []string{link} + + return properties +} + func addDependencyToSubscriptions(resources []*models.Resource, subscription *azContext.SubscriptionContext) { // all resources should have a dependency on the subscription. Except the subscription itself for _, resource := range resources { @@ -226,80 +237,6 @@ func postProcess(resources []*models.Resource) { } } -func filterUnknownDependencies(resources []*models.Resource) []*models.Resource { - for _, resource := range resources { - resource.DependsOn = list.Filter(resource.DependsOn, func(d string) bool { - dependency := list.FirstOrDefault(resources, nil, func(r *models.Resource) bool { - return r.Id == d - }) - - return dependency != nil - }) - } - - return resources -} - -func mapToDomainModels(resources []*models.Resource, ctx *azContext.Context) ([]*domainModels.Resource, error) { - unhandled_types := set.New[string]() - resource_map := &map[string]*domainModels.Resource{} - - tasks := list.Map(resources, func(r *models.Resource) *build_graph.Task { - return build_graph.NewTask(r.Id, list.Map(r.DependsOn, strings.ToLower), []string{}, []string{}, func() { mapToDomainResource(r, ctx.TenantId, unhandled_types, resource_map) }) - }) - - bg, err := build_graph.NewGraph(tasks) - - if err != nil { - return nil, fmt.Errorf("error during construction of dependency graph: %+v", err) - } - - for _, task := range tasks { - bg.Resolve(task) - } - - domainResources := []*domainModels.Resource{} - for _, v := range *resource_map { - domainResources = append(domainResources, v) - } - - return domainResources, nil -} - -func mapToDomainResource(resource *models.Resource, tenantId string, unhandled_types *set.Set[string], resource_map *map[string]*domainModels.Resource) { - if (*resource_map)[resource.Id] != nil { - // resource already registered - return - } - - properties := resource.Properties - - if properties == nil { - properties = map[string][]string{} - } - - link := generateAzurePortalLink(resource, tenantId) - properties["link"] = []string{link} - - dependencies := list.Map(resource.DependsOn, func(d string) *domainModels.Resource { - return (*resource_map)[d] - }) - - if list.Contains(dependencies, func(d *domainModels.Resource) bool { - return d == nil - }) { - panic("dependency was nil") - } - - (*resource_map)[resource.Id] = &domainModels.Resource{ - Id: resource.Id, - Type: mapTypeToDomainType(resource.Type, unhandled_types), - Name: resource.Name, - DependsOn: dependencies, - Properties: resource.Properties, - } -} - func generateAzurePortalLink(resource *models.Resource, tenant string) string { // https://portal.azure.com/#@/resource/ return fmt.Sprintf("https://portal.azure.com/#@%s/resource%s", tenant, resource.Id) @@ -379,3 +316,17 @@ func mapTypeToDomainType(azType string, unhandled_types *set.Set[string]) string return domainType } + +func filterUnknownDependencies(resources []*models.Resource) []*models.Resource { + for _, resource := range resources { + resource.DependsOn = list.Filter(resource.DependsOn, func(d string) bool { + dependency := list.FirstOrDefault(resources, nil, func(r *models.Resource) bool { + return r.Id == d + }) + + return dependency != nil + }) + } + + return resources +} diff --git a/internal/providers/provider.go b/internal/providers/provider.go index dc96a5f..bd5d959 100644 --- a/internal/providers/provider.go +++ b/internal/providers/provider.go @@ -1,7 +1,5 @@ package providers -import "cloudsketch/internal/frontends/models" - type Provider interface { - FetchResources(subscriptionId string) ([]*models.Resource, string, error) + FetchResources(subscriptionId string) ([]*Resource, string, error) } diff --git a/internal/providers/resource.go b/internal/providers/resource.go new file mode 100644 index 0000000..8c3b47d --- /dev/null +++ b/internal/providers/resource.go @@ -0,0 +1,7 @@ +package providers + +type Resource struct { + Id, Type, Name string + DependsOn []string + Properties map[string][]string +} From 48a220b1272a211ad0791d6062b8a5aabe3fb270 Mon Sep 17 00:00:00 2001 From: fremartini Date: Wed, 7 May 2025 17:06:45 +0200 Subject: [PATCH 8/9] remove resourcegroup from example --- example/example.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/example/example.json b/example/example.json index b2f55f2..432d77c 100644 --- a/example/example.json +++ b/example/example.json @@ -3,7 +3,6 @@ "Id": "/subscriptions/00000000-0000-0000-0000-000000000000", "Type": "SUBSCRIPTION", "Name": "example-subscription", - "ResourceGroup": "", "DependsOn": null, "Properties": null }, @@ -11,32 +10,33 @@ "Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.network/virtualnetworks/example-vnet", "Type": "VIRTUAL_NETWORK", "Name": "example-vnet", - "ResourceGroup": "", "DependsOn": [ "/subscriptions/00000000-0000-0000-0000-000000000000" ], "Properties": { - "size": ["21"] + "size": [ + "21" + ] } }, { "Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.network/virtualnetworks/example-vnet/subnets/example-snet", "Type": "SUBNET", "Name": "example-snet", - "ResourceGroup": "", "DependsOn": [ "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.network/virtualnetworks/example-vnet", "/subscriptions/00000000-0000-0000-0000-000000000000" ], "Properties": { - "size": ["22"] + "size": [ + "22" + ] } }, { "Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.compute/virtualmachinescalesets/example-vmss", "Type": "VIRTUAL_MACHINE_SCALE_SET", "Name": "example-vmss", - "ResourceGroup": "", "DependsOn": [ "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.network/virtualnetworks/example-vnet/subnets/example-snet", "/subscriptions/00000000-0000-0000-0000-000000000000" @@ -47,20 +47,20 @@ "Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.network/networkinterfaces/example-nic", "Type": "NETWORK_INTERFACE", "Name": "example-nic", - "ResourceGroup": "", "DependsOn": [ "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.network/virtualnetworks/example-vnet/subnets/example-snet", "/subscriptions/00000000-0000-0000-0000-000000000000" ], "Properties": { - "attachedTo": ["/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.compute/virtualmachines/example-vm"] + "attachedTo": [ + "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.compute/virtualmachines/example-vm" + ] } }, { "Id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.compute/virtualmachines/example-vm", "Type": "VIRTUAL_MACHINE", "Name": "example-vm", - "ResourceGroup": "", "DependsOn": [ "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-resource-group/providers/microsoft.network/networkinterfaces/example-nic", "/subscriptions/00000000-0000-0000-0000-000000000000" From 88d21084723154bf91f5b79e3ee099c484384d3c Mon Sep 17 00:00:00 2001 From: Frederik Martini Date: Fri, 9 May 2025 13:37:32 +0200 Subject: [PATCH 9/9] refactor --- cmd/cloudsketch.go | 18 ++++++++++---- cmd/cmd.go | 40 +++++++++++++------------------ internal/frontends/dot/main.go | 15 +++++++++++- internal/frontends/drawio/main.go | 1 + 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/cmd/cloudsketch.go b/cmd/cloudsketch.go index 4c5e969..0d082c4 100644 --- a/cmd/cloudsketch.go +++ b/cmd/cloudsketch.go @@ -40,10 +40,20 @@ func newCloudsketch(_ context.Context, command *cli.Command) error { frontendString := command.String("frontend") - frontend := frontendmap[frontendString] + frontend, ok := frontendmap[frontendString] + + if !ok { + return fmt.Errorf("unknown frontend %s", frontendString) + } providerString := command.String("provider") + provider, ok := providermap[providerString] + + if !ok { + return fmt.Errorf("unknown frontend %s", frontendString) + } + log.Printf("target frontend is %s\n", frontendString) log.Printf("target provider is %s\n", providerString) @@ -63,7 +73,7 @@ func newCloudsketch(_ context.Context, command *cli.Command) error { filename = existingFilename } else { // otherwise treat it as a subscription id - existingResources, existingFilename, err := createNewFile(fileOrSubscriptionId, providerString, frontendString) + existingResources, existingFilename, err := createNewFile(fileOrSubscriptionId, frontendString, provider) if err != nil { return err @@ -103,9 +113,7 @@ func useExistingFile(file, frontendString string) ([]*providers.Resource, string return *resources, outFile, nil } -func createNewFile(subscriptionId, providerString, frontendString string) ([]*providers.Resource, string, error) { - provider := providermap[providerString] - +func createNewFile(subscriptionId, frontendString string, provider providers.Provider) ([]*providers.Resource, string, error) { resources, filename, err := provider.FetchResources(subscriptionId) if err != nil { diff --git a/cmd/cmd.go b/cmd/cmd.go index d4d4bf6..373e4bf 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -23,36 +23,16 @@ func Execute() { Name: "frontend", Usage: "visualization target", Value: "drawio", - Validator: func(s string) error { - validFrontends := []string{"drawio", "dot"} - - valid := list.Contains(validFrontends, func(validFrontend string) bool { - return s == validFrontend - }) - - if !valid { - return fmt.Errorf("%s is not a valid frontend. Valid target are %s", s, strings.Join(validFrontends, ",")) - } - - return nil + Validator: func(frontend string) error { + return isValidInput([]string{"drawio", "dot"}, frontend) }, }, &cli.StringFlag{ Name: "provider", Usage: "resource source", Value: "azure", - Validator: func(s string) error { - validProviders := []string{"azure"} - - valid := list.Contains(validProviders, func(validProvider string) bool { - return s == validProvider - }) - - if !valid { - return fmt.Errorf("%s is not a valid provider. Valid target are %s", s, strings.Join(validProviders, ",")) - } - - return nil + Validator: func(provider string) error { + return isValidInput([]string{"azure"}, provider) }, }, }, @@ -66,3 +46,15 @@ func Execute() { log.Fatal(err) } } + +func isValidInput(validInputs []string, input string) error { + valid := list.Contains(validInputs, func(validProvider string) bool { + return input == validProvider + }) + + if !valid { + return fmt.Errorf("%s is not a valid value. Valid target are %s", input, strings.Join(validInputs, ",")) + } + + return nil +} diff --git a/internal/frontends/dot/main.go b/internal/frontends/dot/main.go index 6b38814..3811af9 100644 --- a/internal/frontends/dot/main.go +++ b/internal/frontends/dot/main.go @@ -18,6 +18,7 @@ func New() *dot { } func removeChars(s string) string { + // dot format does not allow certain characters r := []string{"-", "_", "/", "."} for _, c := range r { @@ -47,7 +48,7 @@ func (d *dot) WriteDiagram(resources []*models.Resource, filename string) error return err } - graphName := removeChars(strings.ReplaceAll(filename, ".dot", "")) + graphName := graphName(filename) // directory if strings.Contains("/", graphName) { @@ -70,6 +71,18 @@ func (d *dot) WriteDiagram(resources []*models.Resource, filename string) error return err } +func graphName(filename string) string { + graphName := removeChars(strings.ReplaceAll(filename, ".dot", "")) + + // directory + if strings.Contains("/", graphName) { + s := strings.Split(graphName, "/") + graphName = s[len(s)-1] + } + + return graphName +} + func ToDotFile(g *build_graph.Build_graph, name string) string { var buffer bytes.Buffer diff --git a/internal/frontends/drawio/main.go b/internal/frontends/drawio/main.go index 85b964a..219501d 100644 --- a/internal/frontends/drawio/main.go +++ b/internal/frontends/drawio/main.go @@ -220,6 +220,7 @@ func populateResourceMap(resources []*models.Resource) (*map[string]*node.Resour return nil, fmt.Errorf("error during construction of dependency graph: %+v", err) } + // ensure all resources that depend on this have been draw for _, task := range tasks { bg.ResolveInverse(task) }