Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 2e68fb4

Browse files
authored
Allows TagExtractor to pull more than 100 tags. (#359)
* Allows TagExtractor to pull more than 100 tags. * Refactored changes as recommended by RupengLiu.
1 parent 008aef1 commit 2e68fb4

File tree

1 file changed

+38
-28
lines changed
  • src/APIM_ARMTemplate/apimtemplate/Extractor/EntityExtractors

1 file changed

+38
-28
lines changed

src/APIM_ARMTemplate/apimtemplate/Extractor/EntityExtractors/TagExtractor.cs

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

99
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extract
1010
{
11-
public class TagExtractor: EntityExtractor
11+
public class TagExtractor : EntityExtractor
1212
{
13-
public async Task<string> GetTagsAsync(string ApiManagementName, string ResourceGroupName)
13+
public async Task<string> GetTagsAsync(string ApiManagementName, string ResourceGroupName, int skipNumOfRecords )
1414
{
1515
(string azToken, string azSubId) = await auth.GetAccessToken();
1616

17-
string requestUrl = string.Format("{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/Tags?api-version={4}",
18-
baseUrl, azSubId, ResourceGroupName, ApiManagementName, GlobalConstants.APIVersion);
17+
string requestUrl = string.Format("{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/Tags?$skip={4}&api-version={5}",
18+
baseUrl, azSubId, ResourceGroupName, ApiManagementName, skipNumOfRecords, GlobalConstants.APIVersion);
1919

2020
return await CallApiManagementAsync(azToken, requestUrl);
2121
}
@@ -28,7 +28,7 @@ public async Task<Template> GenerateTagsTemplateAsync(string apimname, string re
2828

2929
// isolate tag and api operation associations in the case of a single api extraction
3030
var apiOperationTagResources = apiTemplateResources.Where(resource => resource.type == ResourceTypeConstants.APIOperationTag);
31-
31+
3232
// isolate tag and api associations in the case of a single api extraction
3333
var apiTagResources = apiTemplateResources.Where(resource => resource.type == ResourceTypeConstants.APITag);
3434

@@ -41,34 +41,44 @@ public async Task<Template> GenerateTagsTemplateAsync(string apimname, string re
4141
List<TemplateResource> templateResources = new List<TemplateResource>();
4242

4343
// pull all named values (Tags) for service
44-
string Tags = await GetTagsAsync(apimname, resourceGroup);
45-
JObject oTags = JObject.Parse(Tags);
44+
JObject oTags = new JObject();
45+
int skipNumOfTags = 0;
4646

47-
foreach (var extractedTag in oTags["value"])
47+
do
4848
{
49-
string TagName = ((JValue)extractedTag["name"]).Value.ToString();
50-
51-
// convert returned named value to template resource class
52-
TagTemplateResource TagTemplateResource = JsonConvert.DeserializeObject<TagTemplateResource>(extractedTag.ToString());
53-
TagTemplateResource.name = $"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{TagName}')]";
54-
TagTemplateResource.type = ResourceTypeConstants.Tag;
55-
TagTemplateResource.apiVersion = GlobalConstants.APIVersion;
56-
TagTemplateResource.scale = null;
57-
58-
// only extract the tag if this is a full extraction,
59-
// or in the case of a single api, if it is found in tags associated with the api operations
60-
// or if it is found in tags associated with the api
61-
// or if it is found in tags associated with the products associated with the api
62-
if (singleApiName == null
63-
|| apiOperationTagResources.Any(t => t.name.Contains($"/{TagName}'"))
64-
|| apiTagResources.Any(t => t.name.Contains($"/{TagName}'"))
65-
|| (productAPIResources.Any(t => t.name.Contains($"/{singleApiName}"))
66-
&& productTagResources.Any(t => t.name.Contains($"/{TagName}'"))))
49+
string Tags = await GetTagsAsync(apimname, resourceGroup, skipNumOfTags);
50+
oTags = JObject.Parse(Tags);
51+
52+
foreach (var extractedTag in oTags["value"])
6753
{
68-
Console.WriteLine("'{0}' Tag found", TagName);
69-
templateResources.Add(TagTemplateResource);
54+
string TagName = ((JValue)extractedTag["name"]).Value.ToString();
55+
56+
// convert returned named value to template resource class
57+
TagTemplateResource TagTemplateResource = JsonConvert.DeserializeObject<TagTemplateResource>(extractedTag.ToString());
58+
TagTemplateResource.name = $"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{TagName}')]";
59+
TagTemplateResource.type = ResourceTypeConstants.Tag;
60+
TagTemplateResource.apiVersion = GlobalConstants.APIVersion;
61+
TagTemplateResource.scale = null;
62+
63+
// only extract the tag if this is a full extraction,
64+
// or in the case of a single api, if it is found in tags associated with the api operations
65+
// or if it is found in tags associated with the api
66+
// or if it is found in tags associated with the products associated with the api
67+
if (singleApiName == null
68+
|| apiOperationTagResources.Any(t => t.name.Contains($"/{TagName}'"))
69+
|| apiTagResources.Any(t => t.name.Contains($"/{TagName}'"))
70+
|| (productAPIResources.Any(t => t.name.Contains($"/{singleApiName}"))
71+
&& productTagResources.Any(t => t.name.Contains($"/{TagName}'"))))
72+
{
73+
Console.WriteLine("'{0}' Tag found", TagName);
74+
templateResources.Add(TagTemplateResource);
75+
}
7076
}
77+
78+
skipNumOfTags += GlobalConstants.NumOfRecords;
7179
}
80+
while (oTags["nextLink"] != null);
81+
7282

7383
armTemplate.resources = templateResources.ToArray();
7484
return armTemplate;

0 commit comments

Comments
 (0)