Skip to content

Commit 32a9689

Browse files
authored
Improve export of Event Grid and Firewall Policies Azure#2774 (Azure#2775)
1 parent da3906a commit 32a9689

File tree

2 files changed

+85
-4
lines changed

2 files changed

+85
-4
lines changed

docs/CHANGELOG-v1.md

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers
3232

3333
## Unreleased
3434

35+
What's changed since pre-release v1.35.0-B0055:
36+
37+
- General improvements:
38+
- Improved export of in-flight data for Event Grid and Azure Firewall Policies by @BernieWhite.
39+
[#2774](https://github.com/Azure/PSRule.Rules.Azure/issues/2774)
40+
3541
## v1.35.0-B0055 (pre-release)
3642

3743
What's changed since pre-release v1.35.0-B0030:

src/PSRule.Rules.Azure/Pipeline/Export/ResourceExportVisitor.cs

+79-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ internal sealed class ResourceExportVisitor
4343
private const string PROPERTY_SECURITYPOLICIES = "securityPolicies";
4444
private const string PROPERTY_CONTAINERS = "containers";
4545
private const string PROPERTY_SHARES = "shares";
46+
private const string PROPERTY_TOPICS = "topics";
4647

4748
private const string TYPE_CONTAINERSERVICE_MANAGEDCLUSTERS = "Microsoft.ContainerService/managedClusters";
4849
private const string TYPE_CONTAINERREGISTRY_REGISTRIES = "Microsoft.ContainerRegistry/registries";
@@ -73,6 +74,11 @@ internal sealed class ResourceExportVisitor
7374
private const string TYPE_SERVICEBUS_NAMESPACE = "Microsoft.ServiceBus/namespaces";
7475
private const string TYPE_VISUALSTUDIO_ACCOUNT = "Microsoft.VisualStudio/account";
7576
private const string TYPE_DEVCENTER_PROJECT = "Microsoft.DevCenter/projects";
77+
private const string TYPE_NETWORK_FIREWALLPOLICY = "Microsoft.Network/firewallPolicies";
78+
private const string TYPE_NETWORK_VIRTUALHUB = "Microsoft.Network/virtualHubs";
79+
private const string TYPE_EVENTGRID_TOPIC = "Microsoft.EventGrid/topics";
80+
private const string TYPE_EVENTGRID_DOMAIN = "Microsoft.EventGrid/domains";
81+
private const string TYPE_EVENTGRID_NAMESPACE = "Microsoft.EventGrid/namespaces";
7682

7783
private const string PROVIDERTYPE_DIAGNOSTICSETTINGS = "/providers/microsoft.insights/diagnosticSettings";
7884
private const string PROVIDERTYPE_ROLEASSIGNMENTS = "/providers/Microsoft.Authorization/roleAssignments";
@@ -91,6 +97,8 @@ internal sealed class ResourceExportVisitor
9197
private const string APIVERSION_2016_09_01 = "2016-09-01";
9298
private const string APIVERSION_2017_12_01 = "2017-12-01";
9399
private const string APIVERSION_2021_05_01_PREVIEW = "2021-05-01-preview";
100+
private const string APIVERSION_2021_06_01_PREVIEW = "2021-06-01-preview";
101+
private const string APIVERSION_2021_08_27 = "2021-08-27";
94102
private const string APIVERSION_2021_11_01 = "2021-11-01";
95103
private const string APIVERSION_2022_07_01 = "2022-07-01";
96104
private const string APIVERSION_2022_08_01 = "2022-08-01";
@@ -104,6 +112,7 @@ internal sealed class ResourceExportVisitor
104112
private const string APIVERSION_2023_06_30 = "2023-06-30";
105113
private const string APIVERSION_2023_01_01_PREVIEW = "2023-01-01-preview";
106114
private const string APIVERSION_2023_03_01_PREVIEW = "2023-03-01-preview";
115+
private const string APIVERSION_2023_12_15_PREVIEW = "2023-12-15-preview";
107116

108117
private readonly ProviderData _ProviderData;
109118

@@ -186,7 +195,12 @@ await VisitSubscription(resourceContext, resource, resourceType, resourceId) ||
186195
await VisitDataExplorerCluster(resourceContext, resource, resourceType, resourceId) ||
187196
await VisitEventHubNamespace(resourceContext, resource, resourceType, resourceId) ||
188197
await VisitServiceBusNamespace(resourceContext, resource, resourceType, resourceId) ||
198+
await VisitEventGridTopic(resourceContext, resource, resourceType, resourceId) ||
199+
await VisitEventGridDomain(resourceContext, resource, resourceType, resourceId) ||
200+
await VisitEventGridNamespace(resourceContext, resource, resourceType, resourceId) ||
189201
await VisitDevCenterProject(resourceContext, resource, resourceType, resourceId) ||
202+
await VisitFirewallPolicy(resourceContext, resource, resourceType, resourceId) ||
203+
await VisitVirtualHub(resourceContext, resource, resourceType, resourceId) ||
190204
VisitNetworkConnection(resource, resourceType);
191205
}
192206

@@ -242,8 +256,8 @@ private static async Task<bool> VisitServiceBusNamespace(ResourceContext context
242256
if (!string.Equals(resourceType, TYPE_SERVICEBUS_NAMESPACE, StringComparison.OrdinalIgnoreCase))
243257
return false;
244258

245-
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "queues", "2021-06-01-preview"));
246-
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "topics", "2021-06-01-preview"));
259+
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "queues", APIVERSION_2021_06_01_PREVIEW));
260+
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, PROPERTY_TOPICS, APIVERSION_2021_06_01_PREVIEW));
247261
return true;
248262
}
249263

@@ -252,7 +266,49 @@ private static async Task<bool> VisitEventHubNamespace(ResourceContext context,
252266
if (!string.Equals(resourceType, TYPE_EVENTHUB_NAMESPACE, StringComparison.OrdinalIgnoreCase))
253267
return false;
254268

255-
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "eventhubs", "2021-11-01"));
269+
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "eventhubs", APIVERSION_2021_11_01));
270+
return true;
271+
}
272+
273+
private static async Task<bool> VisitEventGridTopic(ResourceContext context, JObject resource, string resourceType, string resourceId)
274+
{
275+
if (!string.Equals(resourceType, TYPE_EVENTGRID_TOPIC, StringComparison.OrdinalIgnoreCase))
276+
return false;
277+
278+
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "eventSubscriptions", APIVERSION_2023_12_15_PREVIEW));
279+
return true;
280+
}
281+
282+
private static async Task<bool> VisitEventGridDomain(ResourceContext context, JObject resource, string resourceType, string resourceId)
283+
{
284+
if (!string.Equals(resourceType, TYPE_EVENTGRID_DOMAIN, StringComparison.OrdinalIgnoreCase))
285+
return false;
286+
287+
var topics = await GetSubResourcesByType(context, resourceId, PROPERTY_TOPICS, APIVERSION_2023_12_15_PREVIEW);
288+
foreach (var topic in topics)
289+
{
290+
if (topic.TryStringProperty(PROPERTY_ID, out var topicId))
291+
AddSubResource(topic, await GetSubResourcesByType(context, topicId, "eventSubscriptions", APIVERSION_2023_12_15_PREVIEW));
292+
}
293+
294+
AddSubResource(resource, topics);
295+
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "eventSubscriptions", APIVERSION_2023_12_15_PREVIEW));
296+
return true;
297+
}
298+
299+
private static async Task<bool> VisitEventGridNamespace(ResourceContext context, JObject resource, string resourceType, string resourceId)
300+
{
301+
if (!string.Equals(resourceType, TYPE_EVENTGRID_NAMESPACE, StringComparison.OrdinalIgnoreCase))
302+
return false;
303+
304+
var topics = await GetSubResourcesByType(context, resourceId, PROPERTY_TOPICS, APIVERSION_2023_12_15_PREVIEW);
305+
foreach (var topic in topics)
306+
{
307+
if (topic.TryStringProperty(PROPERTY_ID, out var topicId))
308+
AddSubResource(topic, await GetSubResourcesByType(context, topicId, "eventSubscriptions", APIVERSION_2023_12_15_PREVIEW));
309+
}
310+
311+
AddSubResource(resource, topics);
256312
return true;
257313
}
258314

@@ -267,8 +323,27 @@ private static async Task<bool> VisitDevCenterProject(ResourceContext context, J
267323
if (pool.TryStringProperty(PROPERTY_ID, out var poolId))
268324
AddSubResource(pool, await GetSubResourcesByType(context, poolId, "schedules", APIVERSION_2023_04_01));
269325
}
326+
270327
AddSubResource(resource, pools);
328+
return true;
329+
}
330+
331+
private static async Task<bool> VisitFirewallPolicy(ResourceContext context, JObject resource, string resourceType, string resourceId)
332+
{
333+
if (!string.Equals(resourceType, TYPE_NETWORK_FIREWALLPOLICY, StringComparison.OrdinalIgnoreCase))
334+
return false;
335+
336+
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "ruleCollectionGroups", APIVERSION_2023_04_01));
337+
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "signatureOverrides", APIVERSION_2023_04_01));
338+
return true;
339+
}
340+
341+
private static async Task<bool> VisitVirtualHub(ResourceContext context, JObject resource, string resourceType, string resourceId)
342+
{
343+
if (!string.Equals(resourceType, TYPE_NETWORK_VIRTUALHUB, StringComparison.OrdinalIgnoreCase))
344+
return false;
271345

346+
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "routingIntent", APIVERSION_2023_04_01));
272347
return true;
273348
}
274349

@@ -277,7 +352,7 @@ private static async Task<bool> VisitDataExplorerCluster(ResourceContext context
277352
if (!string.Equals(resourceType, TYPE_KUSTO_CLUSTER, StringComparison.OrdinalIgnoreCase))
278353
return false;
279354

280-
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "databases", "2021-08-27"));
355+
AddSubResource(resource, await GetSubResourcesByType(context, resourceId, "databases", APIVERSION_2021_08_27));
281356
return true;
282357
}
283358

0 commit comments

Comments
 (0)