Skip to content

Commit e503809

Browse files
[App Configuration] : Handle pagination of Get-AzAppConfigurationKeyValue (#28840)
1 parent fffa52d commit e503809

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/AppConfiguration/AppConfiguration/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed GitHub issue #23731 'Problem with Get-AzAppConfigurationKeyValue when more that 100 records are present'
22+
- Fixed `NextLink` property to give absolute URI, allowing subsequent pages of results to be retrieved.
2123

2224
## Version 2.0.0
2325
* Introduced various new features by upgrading code generator. Please see detail [here](https://github.com/Azure/azure-powershell/blob/main/documentation/Autorest-powershell-v4-new-features.md).
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Cmdlets
2+
{
3+
using static Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Runtime.Extensions;
4+
using Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Runtime.PowerShell;
5+
using System;
6+
using System.Net.Http;
7+
using System.Threading.Tasks;
8+
9+
/// <summary>Custom partial implementation to fix pagination with relative @nextLink URLs</summary>
10+
public partial class GetAzAppConfigurationKeyValue_Get
11+
{
12+
/// <summary>
13+
/// Override the onOk hook to implement custom pagination logic that handles relative @nextLink URLs
14+
/// </summary>
15+
/// <param name="responseMessage">the raw response message as an global::System.Net.Http.HttpResponseMessage.</param>
16+
/// <param name="response">the body result as a <see cref="Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Models.IKeyValueListResult">Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Models.IKeyValueListResult</see> from the remote call</param>
17+
/// <param name="returnNow">Determines if the rest of the onOk processing should be processed, or if the method should return instantly.</param>
18+
partial void overrideOnOk(global::System.Net.Http.HttpResponseMessage responseMessage, global::System.Threading.Tasks.Task<Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Models.IKeyValueListResult> response, ref global::System.Threading.Tasks.Task<bool> returnNow)
19+
{
20+
var result = response.GetAwaiter().GetResult();
21+
if (!string.IsNullOrEmpty(result.NextLink) && responseMessage?.RequestMessage != null)
22+
{
23+
// Check if nextLink is relative and convert to absolute
24+
if (!Uri.IsWellFormedUriString(result.NextLink, UriKind.Absolute))
25+
{
26+
var baseUri = new Uri(responseMessage.RequestMessage.RequestUri.GetLeftPart(UriPartial.Authority));
27+
var absoluteUri = new Uri(baseUri, result.NextLink);
28+
29+
// Modify the result's NextLink
30+
if (result is Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Models.KeyValueListResult mutableResult)
31+
{
32+
mutableResult.NextLink = absoluteUri.ToString();
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}

src/AppConfiguration/AppConfigurationdata.Autorest/test/AzAppConfigurationKeyValue.Tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ Describe 'Get-AzAppConfigurationKeyValue' -Tag 'LiveOnly' {
2828
Get-AzAppConfigurationKeyValue -Endpoint $env.endpoint
2929
} | Should -Not -Throw
3030
}
31-
}
31+
32+
It 'List returns all paged results' {
33+
$allResults = Get-AzAppConfigurationKeyValue -Endpoint $env:endpoint -Key '*'
34+
$allResults.Count | Should -BeGreaterThan 100
35+
}
36+
}

0 commit comments

Comments
 (0)