Skip to content

Commit 32595ba

Browse files
authored
Merge pull request #338 from zcarroll4/extractor-filter-out-subscriptions
Extractor filter out subscriptions
2 parents ffb2509 + 44a1314 commit 32595ba

File tree

6 files changed

+39
-12
lines changed

6 files changed

+39
-12
lines changed

configuration.extractor.yaml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
# More information about workspaces can be found here https://learn.microsoft.com/en-us/azure/api-management/workspaces-overview
44

55
apiNames:
6-
- api1
7-
- api2
6+
- apiName1
7+
- apiName2
8+
9+
backendNames:
10+
- backendName1
11+
- backendName2
12+
13+
diagnosticNames:
14+
- diagnosticName1
15+
- diagnosticName2
816

917
loggerNames:
1018
- loggerName1
@@ -15,13 +23,13 @@
1523
- namedValueName2
1624

1725
productNames:
18-
- productName2
26+
- productName1
1927
- productName2
2028

21-
backendNames:
22-
- backend1
23-
- backend2
29+
subscriptionNames:
30+
- subscriptionName1
31+
- subscriptionName2
2432

2533
tagNames:
26-
- tag1
27-
- tag2
34+
- tagName1
35+
- tagName2

docs/apiops/7-additionalTopics/apiops-7-1-content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ nav_order: 1
1212
| tools/.github/workflows/ | Github actions for running the extractor and publisher tools |
1313
| tools/code | Source code for the extractor and publisher tools |
1414
| tools/utils/create_pull_request.sh | Script to allow the Azure Devops extractor pipeline to create a Git Pull Request. Not required if using Github actions |
15-
| configuration.extractor.yaml | A sample yaml extractor configuration file to signal to the extractor to extract select apis, backends, products, tags, loggers,and namedvalues. This is an optional parameter and will only come into play if you want different teams to manage different apis, tags, etc.. You typically will have one configuration per team. Note: You can call the file whatever you want as long as you reference the right file within your extractor pipeline. On a side note since the introduction of Workspaces we believe they are the better solution compared to using this file, but we are keeping the support as not everyone will be able to use workspaces. |
15+
| configuration.extractor.yaml | A sample yaml extractor configuration file to signal to the extractor to extract select apis, backends, products, tags, loggers, diagnostics, subscriptions, and namedvalues. This is an optional parameter and will only come into play if you want different teams to manage different apis, tags, etc.. You typically will have one configuration per team. Note: You can call the file whatever you want as long as you reference the right file within your extractor pipeline. On a side note since the introduction of Workspaces we believe they are the better solution compared to using this file, but we are keeping the support as not everyone will be able to use workspaces. |
1616
| configuration.[env].yaml | A sample yaml publisher configuration file to override configuration when running the publisher to promote across different environments (e.g. configuration.prod.yaml for prod environment). Although its optional parameter, you are expected to provide a unique file for each environment as usually different environments have different values (e.g. namevalue). For example if you have a QA environment you would provide another file called configuration.qa.yaml which would have qa specific configuration. Note: You can call the file whatever you want as long as you reference the right file within your publisher pipeline. Also note that if you don't pass the target instance name in the pipelines themselves then you have to pass it as part of the configuration file itself |
1717
| sample-artifacts-folder | Sample output from the extractor tool. The publisher tool expects this structure and can automatically push changes back to Azure |

tools/code/extractor/Extractor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public record Parameters
2727
public IEnumerable<string>? ProductNamesToExport { get; init; }
2828
public IEnumerable<string>? BackendNamesToExport { get; init; }
2929
public IEnumerable<string>? TagNamesToExport { get; init; }
30+
public IEnumerable<string>? SubscriptionNamesToExport { get; init; }
3031
}
31-
32+
3233
private readonly Parameters parameters;
3334

3435
public Extractor(Parameters parameters)
@@ -76,6 +77,7 @@ await Service.Export(parameters.ServiceDirectory,
7677
parameters.ProductNamesToExport,
7778
parameters.BackendNamesToExport,
7879
parameters.TagNamesToExport,
80+
parameters.SubscriptionNamesToExport,
7981
parameters.ListRestResources,
8082
parameters.GetRestResource,
8183
parameters.DownloadResource,

tools/code/extractor/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private static Extractor.Parameters GetExtractorParameters(IServiceProvider prov
189189
ProductNamesToExport = GetProductNamesToExport(configuration),
190190
BackendNamesToExport = GetBackendNamesToExport(configuration),
191191
TagNamesToExport = GetTagNamesToExport(configuration),
192+
SubscriptionNamesToExport = GetSubscriptionNamesToExport(configuration),
192193
DefaultApiSpecification = GetApiSpecification(configuration),
193194
ApplicationLifetime = provider.GetRequiredService<IHostApplicationLifetime>(),
194195
DownloadResource = provider.GetRequiredService<DownloadResource>(),
@@ -242,6 +243,12 @@ private static Extractor.Parameters GetExtractorParameters(IServiceProvider prov
242243
?.Get<IEnumerable<string>>();
243244
}
244245

246+
private static IEnumerable<string>? GetSubscriptionNamesToExport(IConfiguration configuration)
247+
{
248+
return configuration.TryGetSection("subscriptionNames")
249+
?.Get<IEnumerable<string>>();
250+
}
251+
245252
private static DefaultApiSpecification GetApiSpecification(IConfiguration configuration)
246253
{
247254
var configurationFormat = configuration.TryGetValue("API_SPECIFICATION_FORMAT")

tools/code/extractor/Service.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static async ValueTask Export(
1919
IEnumerable<string>? productNamesToExport,
2020
IEnumerable<string>? backendNamesToExport,
2121
IEnumerable<string>? tagNamesToExport,
22+
IEnumerable<string>? subscriptionNamesToExport,
2223
ListRestResources listRestResources,
2324
GetRestResource getRestResource,
2425
DownloadResource downloadResource,
@@ -59,6 +60,6 @@ public static async ValueTask Export(
5960
await Api.ExportAll(serviceDirectory, serviceUri, defaultSpecification, apiNamesToExport, listRestResources, getRestResource, downloadResource, logger, cancellationToken);
6061

6162
logger.LogInformation("Exporting subscriptions...");
62-
await Subscription.ExportAll(serviceDirectory, serviceUri, listRestResources, getRestResource, logger, cancellationToken);
63+
await Subscription.ExportAll(serviceDirectory, serviceUri, listRestResources, getRestResource, logger, subscriptionNamesToExport, cancellationToken);
6364
}
6465
}

tools/code/extractor/Subscription.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using common;
22
using Microsoft.Extensions.Logging;
3+
using System;
34
using System.Collections.Generic;
45
using System.Linq;
56
using System.Threading;
@@ -9,9 +10,11 @@ namespace extractor
910
{
1011
internal class Subscription
1112
{
12-
public static async ValueTask ExportAll(ServiceDirectory serviceDirectory, ServiceUri serviceUri, ListRestResources listRestResources, GetRestResource getRestResource, ILogger logger, CancellationToken cancellationToken)
13+
public static async ValueTask ExportAll(ServiceDirectory serviceDirectory, ServiceUri serviceUri, ListRestResources listRestResources, GetRestResource getRestResource, ILogger logger, IEnumerable<string>? subscriptionNamesToExport, CancellationToken cancellationToken)
1314
{
1415
await List(serviceUri, listRestResources, cancellationToken)
16+
// Filter out diagnostics that should not be exported
17+
.Where(subscriptionName => ShouldExport(subscriptionName, subscriptionNamesToExport))
1518
.ForEachParallel(async subscriptionName => await Export(serviceDirectory, serviceUri, subscriptionName, getRestResource, logger, cancellationToken),
1619
cancellationToken);
1720
}
@@ -24,6 +27,12 @@ private static IAsyncEnumerable<SubscriptionName> List(ServiceUri serviceUri, Li
2427
.Select(name => new SubscriptionName(name));
2528
}
2629

30+
private static bool ShouldExport(SubscriptionName subscriptionName, IEnumerable<string>? subscriptionNamesToExport)
31+
{
32+
return subscriptionNamesToExport is null
33+
|| subscriptionNamesToExport.Any(subscriptionNameToExport => subscriptionNameToExport.Equals(subscriptionName.ToString(), StringComparison.OrdinalIgnoreCase));
34+
}
35+
2736
private static async ValueTask Export(ServiceDirectory serviceDirectory, ServiceUri serviceUri, SubscriptionName subscriptionName, GetRestResource getRestResource, ILogger logger, CancellationToken cancellationToken)
2837
{
2938
var subscriptionsDirectory = new SubscriptionsDirectory(serviceDirectory);

0 commit comments

Comments
 (0)