Skip to content

Commit 107cc7f

Browse files
committed
Added firewall mgmt pips. Also show peered vnets
1 parent 76f23cd commit 107cc7f

File tree

12 files changed

+95
-34
lines changed

12 files changed

+95
-34
lines changed

.idea/.idea.AzureDiagrams/.idea/projectSettingsUpdater.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AzureDiagramGenerator/AzureDiagramGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Azure.Identity" Version="1.12.0" />
15+
<PackageReference Include="Azure.Identity" Version="1.13.2" />
1616
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
1717
</ItemGroup>
1818

AzureDiagramGenerator/DrawIo/AzureResourceDrawer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ private static string DrawSimpleRectangleNode(Node node, string type, string nam
7272
parent = ((CustomUserData)node.ClusterParent.UserData).Id;
7373

7474
var text = name;
75-
if (images.Length == 0 && !string.IsNullOrEmpty(type)) text += $"&lt;br/&gt;({type})";
75+
//if (images.Length == 0 && !string.IsNullOrEmpty(type)) text += $"&lt;br/&gt;({type})";
76+
if (!string.IsNullOrEmpty(type)) text += $"&lt;br/&gt;({type})";
7677

7778
var container =
7879
@$"<mxCell id=""{id}"" value=""{text}"" style=""rounded=0;whiteSpace=wrap;html=1;fillColor={backgroundColour};verticalAlign={textAlignment.ToString().ToLowerInvariant()}"" vertex=""1"" parent=""{parent}"">

AzureDiagramGenerator/DrawIo/AzureResourceNodeBuilder.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,20 @@ public IEnumerable<Edge> CreateEdges(
5252
else
5353
{
5454
var from = nodes[fromResource]
55-
.Single(x => ((CustomUserData)x.UserData).Id == fromResource.InternalId);
56-
var to = nodes[toResource].Single(x => ((CustomUserData)x.UserData).Id == toResource.InternalId);
57-
yield return AzureResourceDrawer.CreateSimpleEdge(link.From, link.To, from, to, link.Details,
55+
.Where(x => ((CustomUserData)x.UserData).Id == fromResource.InternalId).ToArray();
56+
57+
if (from.Count() > 1)
58+
{
59+
throw new InvalidOperationException($"Multiple nodes representing {fromResource.Id} were found.");
60+
}
61+
62+
var to = nodes[toResource].Where(x => ((CustomUserData)x.UserData).Id == toResource.InternalId).ToArray();
63+
if (to.Count() > 1)
64+
{
65+
throw new InvalidOperationException($"Multiple nodes representing {toResource.Id} were found.");
66+
}
67+
68+
yield return AzureResourceDrawer.CreateSimpleEdge(link.From, link.To, from.Single(), to.Single(), link.Details,
5869
link.Plane, isLinkVisible, link.IsTwoWay);
5970
}
6071
}

AzureDiagrams/AzureDiagrams.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
<ItemGroup>
1010
<PackageReference Include="AutomaticGraphLayout" Version="1.1.12" />
11-
<PackageReference Include="Azure.Identity" Version="1.12.0" />
12-
<PackageReference Include="Microsoft.Identity.Client" Version="4.62.0" />
11+
<PackageReference Include="Azure.Identity" Version="1.13.2" />
12+
<PackageReference Include="Microsoft.Identity.Client" Version="4.67.2" />
1313
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1414
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
1515
</ItemGroup>

AzureDiagrams/Resources/ContainerApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace AzureDiagrams.Resources;
99
internal class ContainerApp : AzureResource, ICanBeAccessedViaAHostName
1010
{
1111
public string ContainerAppEnvironmentId { get; set; } = default!;
12-
public override string Image => "img/lib/azure2/compute/Container_Instances.svg";
12+
public override string Image => "img/lib/azure2/other/Worker_Container_App.svg";
1313

1414
public string IngressFqdn { get; private set; } = default!;
1515

AzureDiagrams/Resources/ContainerAppEnvironment.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
namespace AzureDiagrams.Resources;
66

7-
internal class ContainerAppEnvironment : AzureResource, ICanWriteToLogAnalyticsWorkspaces
7+
internal class ContainerAppEnvironment : AzureResource, ICanWriteToLogAnalyticsWorkspaces, ICanInjectIntoASubnet
88
{
9-
public override string Image => "img/lib/mscae/Kubernetes_Services.svg";
9+
private string[] _subnets;
10+
public override string Image => "img/lib/azure2/other/Container_App_Environments.svg";
1011
public string? LogAnalyticsCustomerId { get; private set; }
1112

1213
public bool DoYouWriteTo(string customerId)
@@ -21,13 +22,24 @@ public void CreateFlowBackToMe(LogAnalyticsWorkspace workspace)
2122

2223
public override Task Enrich(JObject full, Dictionary<string, JObject?> additionalResources)
2324
{
24-
LogAnalyticsCustomerId = full["properties"]!["appLogsConfiguration"]?["logAnalyticsConfiguration"]
25-
?.Value<string>("customerId");
25+
var jToken = full["properties"]!
26+
["appLogsConfiguration"]?
27+
["logAnalyticsConfiguration"];
28+
29+
jToken = jToken?.Type == JTokenType.Null ? null : jToken;
30+
31+
LogAnalyticsCustomerId = jToken?.Value<string>("customerId");
32+
33+
var subnet = full["properties"]!["vnetConfiguration"]?.Value<string>("infrastructureSubnetId");
34+
_subnets = subnet != null ? [subnet] : [];
35+
2636
return base.Enrich(full, additionalResources);
2737
}
2838

2939
public void DiscoveredContainerApp(ContainerApp containerApp)
3040
{
3141
OwnsResource(containerApp);
3242
}
43+
44+
public string[] SubnetIdsIAmInjectedInto => _subnets;
3345
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using Newtonsoft.Json.Linq;
45

@@ -7,13 +8,15 @@ namespace AzureDiagrams.Resources;
78
public class Firewall : AzureResource, ICanInjectIntoASubnet, ICanExposePublicIPAddresses
89
{
910
private IpConfigurations _ipConfigurations = default!;
11+
private IpConfigurations _mgmtIpConfigurations = default!;
1012
public override string Image => "img/lib/azure2/networking/Firewalls.svg";
1113

1214
public override Task Enrich(JObject full, Dictionary<string, JObject?> additionalResources)
1315
{
1416
_ipConfigurations = new IpConfigurations(full);
17+
_mgmtIpConfigurations = new IpConfigurations(full, "managementIpConfiguration");
1518
return base.Enrich(full, additionalResources);
1619
}
17-
public string[] PublicIpAddresses => _ipConfigurations.PublicIpAddresses;
18-
public string[] SubnetIdsIAmInjectedInto => _ipConfigurations.SubnetAttachments;
20+
public string[] PublicIpAddresses => _ipConfigurations.PublicIpAddresses.Concat(_mgmtIpConfigurations.PublicIpAddresses).ToArray();
21+
public string[] SubnetIdsIAmInjectedInto => _ipConfigurations.SubnetAttachments; //technically there may be another subnet associated - the mgmt one. But I can only really display one on the diagram without overcomplicating things.
1922
}

AzureDiagrams/Resources/IpConfigurations.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,39 @@ public static IpConfigurations ForPrivateEndpoint(string ipAddress, string subne
2222

2323
public IpConfigurations(JObject jObject, string propertyName = "ipConfigurations")
2424
{
25-
PublicIpAddresses = jObject["properties"]![propertyName]?
25+
var ipConfigurations = jObject["properties"]![propertyName];
26+
if (ipConfigurations?.Type == JTokenType.Object)
27+
{
28+
ipConfigurations = new JArray(ipConfigurations);
29+
}
30+
31+
PublicIpAddresses = ipConfigurations?
2632
.Select(x =>
2733
x["properties"]!["publicIPAddress"] != null
2834
? x["properties"]!["publicIPAddress"]!.Value<string>("id")!.ToLowerInvariant()
2935
: null)
3036
.Where(x => x != null)
3137
.Select(x => x!.ToLowerInvariant())
32-
.ToArray() ?? Array.Empty<string>();
38+
.ToArray() ?? [];
3339

34-
PrivateIpAddresses = jObject["properties"]![propertyName]?
40+
PrivateIpAddresses = ipConfigurations?
3541
.Select(x => x["properties"]!.Value<string>("privateIPAddress"))
3642
.Where(x => x != null)
3743
.Select(x => x!)
38-
.ToArray() ?? Array.Empty<string>();
44+
.ToArray() ?? [];
3945

40-
SubnetAttachments = jObject["properties"]![propertyName]?
46+
SubnetAttachments = ipConfigurations?
4147
.Select(x => x["properties"]!["subnet"]?.Value<string>("id")!.ToLowerInvariant())
4248
.Where(x => x != null)
4349
.Select(x => x!)
44-
.ToArray() ?? Array.Empty<string>();
50+
.ToArray() ?? [];
4551

46-
HostNames = jObject["properties"]![propertyName]?
52+
HostNames = ipConfigurations?
4753
.SelectMany(x =>
4854
x["properties"]!["privateLinkConnectionProperties"]?["fqdns"]?.Values<string>() ??
4955
Array.Empty<string>())
5056
.Select(x => x!.ToLowerInvariant())
51-
.ToArray() ?? Array.Empty<string>();
57+
.ToArray() ?? [];
5258
}
5359

5460
public string[] PrivateIpAddresses { get; set; }

AzureDiagrams/Resources/LoadBalancer.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ public class LoadBalancer : AzureResource, ICanInjectIntoASubnet, ICanExposePubl
1919
public override Task Enrich(JObject full, Dictionary<string, JObject?> additionalResources)
2020
{
2121
_frontendIpConfigurations = new IpConfigurations(full, "frontendIPConfigurations");
22-
_backendNics = full["properties"]!["backendAddressPools"]!.SelectMany(x =>
23-
x["properties"]!["loadBalancerBackendAddresses"]?.Select(
24-
lbba => lbba["properties"]!["networkInterfaceIPConfiguration"]?.Value<string>("id")!) ??
25-
Array.Empty<string>())
26-
.Select(x => string.Join('/', x.Split("/")[0..^2]))
27-
.ToArray();
22+
_backendNics =
23+
full["properties"]!
24+
["backendAddressPools"]!
25+
.SelectMany(x =>
26+
x["properties"]!["loadBalancerBackendAddresses"]?
27+
.Select(lbba =>
28+
lbba["properties"]!
29+
["networkInterfaceIPConfiguration"]?
30+
.Value<string>("id") ?? null) ?? Array.Empty<string>()
31+
)
32+
.Where(x => x != null)
33+
.Select(x => string.Join('/', x.Split("/")[0..^2])
34+
)
35+
.ToArray();
2836

2937
return base.Enrich(full, additionalResources);
3038
}

0 commit comments

Comments
 (0)