From e3b700666cf2b9ac2240e9d8cd5563aa4a02a003 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Fri, 20 Dec 2024 14:59:29 -0500 Subject: [PATCH 1/3] Parse out ModuleList for dependencies if it exists in metadata --- src/code/PSResourceInfo.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/code/PSResourceInfo.cs b/src/code/PSResourceInfo.cs index 0e14f6ce9..db88bfa8a 100644 --- a/src/code/PSResourceInfo.cs +++ b/src/code/PSResourceInfo.cs @@ -970,13 +970,18 @@ public static bool TryConvertFromContainerRegistryJson( { metadata["Dependencies"] = ParseContainerRegistryDependencies(requiredModulesElement, out errorMsg).ToArray(); } + if (string.Equals(packageName, "Az", StringComparison.OrdinalIgnoreCase) || packageName.StartsWith("Az.", StringComparison.OrdinalIgnoreCase)) { - if (rootDom.TryGetProperty("PrivateData", out JsonElement privateDataElement) && privateDataElement.TryGetProperty("PSData", out JsonElement psDataElement)) + if (rootDom.TryGetProperty("ModuleList", out JsonElement moduleListDepsElement)) + { + metadata["Dependencies"] = ParseContainerRegistryDependencies(moduleListDepsElement, out errorMsg).ToArray(); + } + else if (rootDom.TryGetProperty("PrivateData", out JsonElement privateDataElement) && privateDataElement.TryGetProperty("PSData", out JsonElement psDataElement)) { - if (psDataElement.TryGetProperty("ModuleList", out JsonElement moduleListDepsElement)) + if (psDataElement.TryGetProperty("ModuleList", out JsonElement privateDataModuleListDepsElement)) { - metadata["Dependencies"] = ParseContainerRegistryDependencies(moduleListDepsElement, out errorMsg).ToArray(); + metadata["Dependencies"] = ParseContainerRegistryDependencies(privateDataModuleListDepsElement, out errorMsg).ToArray(); } } } From 861384b965ea686cecfac07f25e320dd4deac56c Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Mon, 6 Jan 2025 10:45:20 -0500 Subject: [PATCH 2/3] add tests for finding dependency of Az module from ACR and MAR --- .../FindPSResourceContainerRegistryServer.Tests.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 index b15833980..c821a7003 100644 --- a/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 @@ -227,6 +227,12 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { $res.Version | Should -Be "1.0.0" $res.Type.ToString() | Should -Be "Script" } + + It "Should find resource with dependency, given Name and Version" { + $res = Find-PSResource -Name "Az.Storage" -Version "8.0.0" -Repository $ACRRepoName + $res.Dependencies.Length | Should -Be 1 + $res.Dependencies[0].Name | Should -Be "Az.Accounts" + } } Describe 'Test Find-PSResource for MAR Repository' -tags 'CI' { @@ -245,4 +251,10 @@ Describe 'Test Find-PSResource for MAR Repository' -tags 'CI' { $res.Name | Should -Be "Az.Accounts" $res.Version | Should -Be "3.0.4" } + + It "Should find resource and its dependency given specific Name and Version" { + $res = Find-PSResource -Name "Az.Storage" -Version "8.0.0" -Repository "MAR" + $res.Dependencies.Length | Should -Be 1 + $res.Dependencies[0].Name | Should -Be "Az.Accounts" + } } From e71733c478ae18a25646e5e7112db736b1dda02b Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Mon, 6 Jan 2025 14:19:35 -0500 Subject: [PATCH 3/3] remove temporary test prefix for MAR and update package version we're looking for --- .../FindPSResourceContainerRegistryServer.Tests.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 index c821a7003..b7ffdfb8e 100644 --- a/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 @@ -237,19 +237,17 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { Describe 'Test Find-PSResource for MAR Repository' -tags 'CI' { BeforeAll { - [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", "azure-powershell/"); Register-PSResourceRepository -Name "MAR" -Uri "https://mcr.microsoft.com" -ApiVersion "ContainerRegistry" } AfterAll { - [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", $null); Unregister-PSResourceRepository -Name "MAR" } It "Should find resource given specific Name, Version null" { $res = Find-PSResource -Name "Az.Accounts" -Repository "MAR" $res.Name | Should -Be "Az.Accounts" - $res.Version | Should -Be "3.0.4" + $res.Version | Should -Be "4.0.0" } It "Should find resource and its dependency given specific Name and Version" {