Skip to content

Commit

Permalink
Bugfix for ContainerRegistry repository to parse out dependencies fro…
Browse files Browse the repository at this point in the history
…m metadata (#1766)
  • Loading branch information
anamnavi authored Jan 7, 2025
1 parent 3e23ecb commit 1d825a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/code/PSResourceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,22 +227,32 @@ 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' {
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" {
$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"
}
}

0 comments on commit 1d825a3

Please sign in to comment.