Skip to content

Commit 2a92c2e

Browse files
authored
Fix Get-AzTag pagination (Azure#22099)
* Fix Get-AzTag pagination * renamed page to pageOfTags
1 parent f56df77 commit 2a92c2e

File tree

7 files changed

+314
-10
lines changed

7 files changed

+314
-10
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
using Xunit.Abstractions;
18+
19+
namespace Microsoft.Azure.Commands.Resources.Test.ScenarioTests
20+
{
21+
public class TagPaginationTests : ResourcesTestRunner
22+
{
23+
public TagPaginationTests(ITestOutputHelper output) : base(output)
24+
{
25+
}
26+
27+
[Fact]
28+
[Trait(Category.AcceptanceType, Category.CheckIn)]
29+
public void ListTagWithPagination()
30+
{
31+
// Note: due to the large amount of tags needed to trigger pagination,
32+
// the recording of this test case is edited manually.
33+
// Please do not record it.
34+
TestRunner.RunTestScript("Test-ListTagWithPagination");
35+
}
36+
37+
[Fact]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void ListTagWithoutPagination()
40+
{
41+
// Note: due to the large amount of tags needed to trigger pagination,
42+
// the recording of this test case is edited manually.
43+
// Please do not record it.
44+
TestRunner.RunTestScript("Test-ListTagWithoutPagination");
45+
}
46+
}
47+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
function Test-ListTagWithPagination
16+
{
17+
$tag = Get-AzTag
18+
Assert-AreEqual 63 $tag.Length
19+
# there are two pages of tags in the test data, each has 32 tags, 1 overlapping
20+
21+
Assert-AreEqual "tag1" $tag[0].Name
22+
Assert-AreEqual "tag63" $tag[-1].Name
23+
}
24+
25+
function Test-ListTagWithoutPagination
26+
{
27+
$tag = Get-AzTag
28+
29+
Assert-AreEqual 32 $tag.Length
30+
31+
Assert-AreEqual "tag1" $tag[0].Name
32+
Assert-AreEqual "tag32" $tag[-1].Name
33+
}

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.TagPaginationTests/ListTagWithPagination.json

Lines changed: 134 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/tagNames?api-version=2021-04-01",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvOWUyMjNkYmUtMzM5OS00ZTE5LTg4ZWItMDk3NWYwMmFjODdmL3RhZ05hbWVzP2FwaS12ZXJzaW9uPTIwMjEtMDQtMDE=",
6+
"RequestMethod": "GET",
7+
"RequestHeaders": {
8+
"x-ms-client-request-id": [
9+
"1fad1592-6650-4fdd-ae63-d44851e16812"
10+
],
11+
"Accept-Language": [
12+
"en-US"
13+
],
14+
"User-Agent": [
15+
"FxVersion/4.700.22.55902",
16+
"OSName/Windows",
17+
"OSVersion/Microsoft.Windows.10.0.22621",
18+
"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient/3.17.3.0"
19+
]
20+
},
21+
"RequestBody": "",
22+
"ResponseHeaders": {
23+
"Cache-Control": [
24+
"no-cache"
25+
],
26+
"Pragma": [
27+
"no-cache"
28+
],
29+
"x-ms-ratelimit-remaining-subscription-reads": [
30+
"11999"
31+
],
32+
"x-ms-request-id": [
33+
"324f369e-949e-4a23-b78f-eda543acb7cd"
34+
],
35+
"x-ms-correlation-request-id": [
36+
"324f369e-949e-4a23-b78f-eda543acb7cd"
37+
],
38+
"x-ms-routing-request-id": [
39+
"SOUTHEASTASIA:20230605T130353Z:324f369e-949e-4a23-b78f-eda543acb7cd"
40+
],
41+
"Strict-Transport-Security": [
42+
"max-age=31536000; includeSubDomains"
43+
],
44+
"X-Content-Type-Options": [
45+
"nosniff"
46+
],
47+
"Date": [
48+
"Mon, 05 Jun 2023 13:03:52 GMT"
49+
],
50+
"Content-Type": [
51+
"application/json; charset=utf-8"
52+
],
53+
"Expires": [
54+
"-1"
55+
],
56+
"Content-Length": [
57+
"4866"
58+
],
59+
"Retry-After": [
60+
"0"
61+
]
62+
},
63+
"ResponseBody": "{\"value\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag1\",\"tagName\":\"tag1\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag1/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag2\",\"tagName\":\"tag2\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag2/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag3\",\"tagName\":\"tag3\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag3/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag4\",\"tagName\":\"tag4\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag4/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag5\",\"tagName\":\"tag5\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag5/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag6\",\"tagName\":\"tag6\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag6/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag7\",\"tagName\":\"tag7\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag7/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag8\",\"tagName\":\"tag8\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag8/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag9\",\"tagName\":\"tag9\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag9/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag10\",\"tagName\":\"tag10\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag10/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag11\",\"tagName\":\"tag11\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag11/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag12\",\"tagName\":\"tag12\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag12/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag13\",\"tagName\":\"tag13\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag13/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag14\",\"tagName\":\"tag14\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag14/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag15\",\"tagName\":\"tag15\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag15/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag16\",\"tagName\":\"tag16\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag16/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag17\",\"tagName\":\"tag17\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag17/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag18\",\"tagName\":\"tag18\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag18/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag19\",\"tagName\":\"tag19\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag19/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag20\",\"tagName\":\"tag20\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag20/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag21\",\"tagName\":\"tag21\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag21/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag22\",\"tagName\":\"tag22\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag22/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag23\",\"tagName\":\"tag23\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag23/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag24\",\"tagName\":\"tag24\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag24/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag25\",\"tagName\":\"tag25\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag25/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag26\",\"tagName\":\"tag26\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag26/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag27\",\"tagName\":\"tag27\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag27/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag28\",\"tagName\":\"tag28\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag28/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag29\",\"tagName\":\"tag29\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag29/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag30\",\"tagName\":\"tag30\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag30/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag31\",\"tagName\":\"tag31\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag31/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]},{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag32\",\"tagName\":\"tag32\",\"count\":{\"type\":\"Total\",\"value\":10},\"values\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/tagNames/tag32/tagValues/tagValue1\",\"tagValue\":\"tagValue1\",\"count\":{\"type\":\"Total\",\"value\":2}}]}]}",
64+
"StatusCode": 200
65+
}
66+
],
67+
"Names": {},
68+
"Variables": {
69+
"SubscriptionId": "9e223dbe-3399-4e19-88eb-0975f02ac87f"
70+
}
71+
}

src/Resources/Resources.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Az.ManagedServiceIdentity",
4545
EndProject
4646
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Resources.Sdk", "Resources.Sdk\Resources.Sdk.csproj", "{C7AEFB98-2F58-4F71-92FE-593F6B8868B6}"
4747
EndProject
48+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssemblyLoading", "..\Accounts\AssemblyLoading\AssemblyLoading.csproj", "{6886DE74-7EC6-48C6-A510-2740A8947414}"
49+
EndProject
4850
Global
4951
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5052
Debug|Any CPU = Debug|Any CPU
@@ -131,6 +133,10 @@ Global
131133
{C7AEFB98-2F58-4F71-92FE-593F6B8868B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
132134
{C7AEFB98-2F58-4F71-92FE-593F6B8868B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
133135
{C7AEFB98-2F58-4F71-92FE-593F6B8868B6}.Release|Any CPU.Build.0 = Release|Any CPU
136+
{6886DE74-7EC6-48C6-A510-2740A8947414}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
137+
{6886DE74-7EC6-48C6-A510-2740A8947414}.Debug|Any CPU.Build.0 = Debug|Any CPU
138+
{6886DE74-7EC6-48C6-A510-2740A8947414}.Release|Any CPU.ActiveCfg = Release|Any CPU
139+
{6886DE74-7EC6-48C6-A510-2740A8947414}.Release|Any CPU.Build.0 = Release|Any CPU
134140
EndGlobalSection
135141
GlobalSection(SolutionProperties) = preSolution
136142
HideSolutionNode = FALSE

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Fixed the incorrect behavior of pagination for `Get-AzTag`
2223
* Updated API version to 2022-09-01
2324

2425
## Version 6.7.0

src/Resources/Tags/Client/TagsClient.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,32 @@ public TagsClient()
6666

6767
public List<PSTag> ListTags()
6868
{
69-
var result = ResourceManagementClient.Tags.List();
70-
List<PSTag> tags = new List<PSTag>();
71-
72-
do
69+
var result = new List<TagDetails>();
70+
var pageOfTags = ResourceManagementClient.Tags.List();
71+
AddOrMergeTags(result, pageOfTags);
72+
while (!string.IsNullOrEmpty(pageOfTags.NextPageLink))
7373
{
74-
result.Where(t => !t.TagName.StartsWith(ExecludedTagPrefix)).ForEach(t => tags.Add(t.ToPSTag()));
74+
pageOfTags = ResourceManagementClient.Tags.ListNext(pageOfTags.NextPageLink);
75+
AddOrMergeTags(result, pageOfTags);
76+
}
77+
return new List<PSTag>(result.Select(t => t.ToPSTag()));
78+
}
7579

76-
if (!string.IsNullOrEmpty(result.NextPageLink))
80+
private void AddOrMergeTags(List<TagDetails> results, IEnumerable<TagDetails> tags)
81+
{
82+
tags.Where(t => !t.TagName.StartsWith(ExecludedTagPrefix)).ForEach(t =>
83+
{
84+
var tagNameFound = results.FirstOrDefault(pst => pst.TagName.Equals(t.TagName, StringComparison.OrdinalIgnoreCase));
85+
if (tagNameFound != null)
7786
{
78-
result = ResourceManagementClient.Tags.ListNext(result.NextPageLink);
87+
// tag name already in previous page, merge instead of add
88+
tagNameFound.Values = new List<TagValue>(tagNameFound.Values.Concat(t.Values));
7989
}
80-
} while (!string.IsNullOrEmpty(result.NextPageLink));
81-
82-
return tags;
90+
else
91+
{
92+
results.Add(t);
93+
}
94+
});
8395
}
8496

8597
public PSTag GetTag(string tag)

0 commit comments

Comments
 (0)