diff --git a/src/AppConfiguration/AppConfiguration/ChangeLog.md b/src/AppConfiguration/AppConfiguration/ChangeLog.md index c13b4333d7da..61639cec550c 100644 --- a/src/AppConfiguration/AppConfiguration/ChangeLog.md +++ b/src/AppConfiguration/AppConfiguration/ChangeLog.md @@ -18,6 +18,8 @@ - Additional information about change #1 --> ## Upcoming Release +* Fixed GitHub issue #23731 'Problem with Get-AzAppConfigurationKeyValue when more that 100 records are present' + - Fixed `NextLink` property to give absolute URI, allowing subsequent pages of results to be retrieved. ## Version 2.0.0 * 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). diff --git a/src/AppConfiguration/AppConfigurationdata.Autorest/custom/GetAzAppConfigurationKeyValue_Get.cs b/src/AppConfiguration/AppConfigurationdata.Autorest/custom/GetAzAppConfigurationKeyValue_Get.cs new file mode 100644 index 000000000000..8ce7eae12624 --- /dev/null +++ b/src/AppConfiguration/AppConfigurationdata.Autorest/custom/GetAzAppConfigurationKeyValue_Get.cs @@ -0,0 +1,38 @@ +namespace Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Cmdlets +{ + using static Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Runtime.Extensions; + using Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Runtime.PowerShell; + using System; + using System.Net.Http; + using System.Threading.Tasks; + + /// Custom partial implementation to fix pagination with relative @nextLink URLs + public partial class GetAzAppConfigurationKeyValue_Get + { + /// + /// Override the onOk hook to implement custom pagination logic that handles relative @nextLink URLs + /// + /// the raw response message as an global::System.Net.Http.HttpResponseMessage. + /// the body result as a Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Models.IKeyValueListResult from the remote call + /// Determines if the rest of the onOk processing should be processed, or if the method should return instantly. + partial void overrideOnOk(global::System.Net.Http.HttpResponseMessage responseMessage, global::System.Threading.Tasks.Task response, ref global::System.Threading.Tasks.Task returnNow) + { + var result = response.GetAwaiter().GetResult(); + if (!string.IsNullOrEmpty(result.NextLink) && responseMessage?.RequestMessage != null) + { + // Check if nextLink is relative and convert to absolute + if (!Uri.IsWellFormedUriString(result.NextLink, UriKind.Absolute)) + { + var baseUri = new Uri(responseMessage.RequestMessage.RequestUri.GetLeftPart(UriPartial.Authority)); + var absoluteUri = new Uri(baseUri, result.NextLink); + + // Modify the result's NextLink + if (result is Microsoft.Azure.PowerShell.Cmdlets.AppConfigurationdata.Models.KeyValueListResult mutableResult) + { + mutableResult.NextLink = absoluteUri.ToString(); + } + } + } + } + } +} \ No newline at end of file diff --git a/src/AppConfiguration/AppConfigurationdata.Autorest/test/AzAppConfigurationKeyValue.Tests.ps1 b/src/AppConfiguration/AppConfigurationdata.Autorest/test/AzAppConfigurationKeyValue.Tests.ps1 index 9cf0171b4cab..d8f133305a2c 100644 --- a/src/AppConfiguration/AppConfigurationdata.Autorest/test/AzAppConfigurationKeyValue.Tests.ps1 +++ b/src/AppConfiguration/AppConfigurationdata.Autorest/test/AzAppConfigurationKeyValue.Tests.ps1 @@ -28,4 +28,9 @@ Describe 'Get-AzAppConfigurationKeyValue' -Tag 'LiveOnly' { Get-AzAppConfigurationKeyValue -Endpoint $env.endpoint } | Should -Not -Throw } -} + + It 'List returns all paged results' { + $allResults = Get-AzAppConfigurationKeyValue -Endpoint $env:endpoint -Key '*' + $allResults.Count | Should -BeGreaterThan 100 + } +} \ No newline at end of file