Skip to content

Commit d5e5d8d

Browse files
authored
ACR - Update PSRepositoryInfo.APIVersion to replace acr with ContainerRegistry (#1589)
1 parent ed6da24 commit d5e5d8d

12 files changed

+55
-45
lines changed

src/code/FindHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
956956
// After retrieving all packages find their dependencies
957957
if (_includeDependencies)
958958
{
959-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.v3)
959+
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V3)
960960
{
961961
_cmdletPassedIn.WriteWarning("Installing dependencies is not currently supported for V3 server protocol repositories. The package will be installed without installing dependencies.");
962962
yield break;

src/code/InstallHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private List<PSResourceInfo> ProcessRepositories(
315315
}
316316

317317
repositoryNamesToSearch.Add(repoName);
318-
if ((currentRepository.ApiVersion == PSRepositoryInfo.APIVersion.v3) && (!installDepsForRepo))
318+
if ((currentRepository.ApiVersion == PSRepositoryInfo.APIVersion.V3) && (!installDepsForRepo))
319319
{
320320
_cmdletPassedIn.WriteWarning("Installing dependencies is not currently supported for V3 server protocol repositories. The package will be installed without installing dependencies.");
321321
installDepsForRepo = true;
@@ -598,7 +598,7 @@ private List<PSResourceInfo> InstallPackages(
598598

599599
if (!skipDependencyCheck)
600600
{
601-
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.v3)
601+
if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V3)
602602
{
603603
_cmdletPassedIn.WriteWarning("Installing dependencies is not currently supported for V3 server protocol repositories. The package will be installed without installing dependencies.");
604604
}

src/code/PSRepositoryInfo.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public sealed class PSRepositoryInfo
1515

1616
public enum APIVersion
1717
{
18-
unknown,
19-
v2,
20-
v3,
21-
local,
22-
nugetServer,
23-
acr
18+
Unknown,
19+
V2,
20+
V3,
21+
Local,
22+
NugetServer,
23+
ContainerRegistry
2424
}
2525

2626
#endregion

src/code/PublishPSResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ out string[] _
494494

495495
string repositoryUri = repository.Uri.AbsoluteUri;
496496

497-
if (repository.ApiVersion == PSRepositoryInfo.APIVersion.acr)
497+
if (repository.ApiVersion == PSRepositoryInfo.APIVersion.ContainerRegistry)
498498
{
499499
ACRServerAPICalls acrServer = new ACRServerAPICalls(repository, this, _networkCredential, userAgentString);
500500

src/code/RegisterPSResourceRepository.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,12 @@ private PSRepositoryInfo RepoValidationHelper(Hashtable repo)
339339

340340
if (repo.ContainsKey("ApiVersion") &&
341341
(repo["ApiVersion"] == null || String.IsNullOrEmpty(repo["ApiVersion"].ToString()) ||
342-
!(repo["ApiVersion"].ToString().Equals("local") || repo["ApiVersion"].ToString().Equals("v2") ||
343-
repo["ApiVersion"].ToString().Equals("v3") || repo["ApiVersion"].ToString().Equals("nugetServer") || repo["ApiVersion"].ToString().Equals("unknown"))))
342+
!(repo["ApiVersion"].ToString().Equals("Local", StringComparison.OrdinalIgnoreCase) || repo["ApiVersion"].ToString().Equals("V2", StringComparison.OrdinalIgnoreCase) ||
343+
repo["ApiVersion"].ToString().Equals("V3", StringComparison.OrdinalIgnoreCase) || repo["ApiVersion"].ToString().Equals("NugetServer", StringComparison.OrdinalIgnoreCase) ||
344+
repo["ApiVersion"].ToString().Equals("Unknown", StringComparison.OrdinalIgnoreCase))))
344345
{
345346
WriteError(new ErrorRecord(
346-
new PSInvalidOperationException("Repository ApiVersion must be either 'local', 'v2', 'v3', 'nugetServer' or 'unknown'"),
347+
new PSInvalidOperationException("Repository ApiVersion must be either 'Local', 'V2', 'V3', 'NugetServer', 'ContainRegistry' or 'Unknown'"),
347348
"IncorrectApiVersionForRepositoriesParameterSetRegistration",
348349
ErrorCategory.InvalidArgument,
349350
this));

src/code/RepositorySettings.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
using System.IO;
88
using System.Linq;
99
using System.Management.Automation;
10-
using System.Security.Cryptography;
11-
using System.Text;
1210
using System.Xml;
1311
using System.Xml.Linq;
1412
using static Microsoft.PowerShell.PSResourceGet.UtilClasses.PSRepositoryInfo;
@@ -63,7 +61,7 @@ public static void CheckRepositoryStore()
6361

6462
// Add PSGallery to the newly created store
6563
Uri psGalleryUri = new Uri(PSGalleryRepoUri);
66-
Add(PSGalleryRepoName, psGalleryUri, DefaultPriority, DefaultTrusted, repoCredentialInfo: null, PSRepositoryInfo.APIVersion.v2, force: false);
64+
Add(PSGalleryRepoName, psGalleryUri, DefaultPriority, DefaultTrusted, repoCredentialInfo: null, PSRepositoryInfo.APIVersion.V2, force: false);
6765
}
6866

6967
// Open file (which should exist now), if cannot/is corrupted then throw error
@@ -416,15 +414,15 @@ public static PSRepositoryInfo Update(string repoName, Uri repoUri, int repoPrio
416414
}
417415

418416
// Update APIVersion if necessary
419-
PSRepositoryInfo.APIVersion resolvedAPIVersion = PSRepositoryInfo.APIVersion.unknown;
417+
PSRepositoryInfo.APIVersion resolvedAPIVersion = PSRepositoryInfo.APIVersion.Unknown;
420418
if (apiVersion != null)
421419
{
422420
resolvedAPIVersion = (PSRepositoryInfo.APIVersion)apiVersion;
423421
node.Attribute("APIVersion").Value = resolvedAPIVersion.ToString();
424422
}
425423
else
426424
{
427-
resolvedAPIVersion = (PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value);
425+
resolvedAPIVersion = (PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value, ignoreCase: true);
428426
}
429427

430428

@@ -531,7 +529,7 @@ public static List<PSRepositoryInfo> Remove(string[] repoNames, out string[] err
531529
Int32.Parse(node.Attribute("Priority").Value),
532530
Boolean.Parse(node.Attribute("Trusted").Value),
533531
repoCredentialInfo,
534-
(PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value)));
532+
(PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value, ignoreCase: true)));
535533

536534
// Remove item from file
537535
node.Remove();
@@ -661,7 +659,7 @@ public static List<PSRepositoryInfo> Read(string[] repoNames, out string[] error
661659
Int32.Parse(repo.Attribute("Priority").Value),
662660
Boolean.Parse(repo.Attribute("Trusted").Value),
663661
thisCredentialInfo,
664-
(PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), repo.Attribute("APIVersion").Value));
662+
(PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), repo.Attribute("APIVersion").Value, ignoreCase: true));
665663

666664
foundRepos.Add(currentRepoItem);
667665
}
@@ -765,7 +763,7 @@ public static List<PSRepositoryInfo> Read(string[] repoNames, out string[] error
765763
Int32.Parse(node.Attribute("Priority").Value),
766764
Boolean.Parse(node.Attribute("Trusted").Value),
767765
thisCredentialInfo,
768-
(PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value));
766+
(PSRepositoryInfo.APIVersion)Enum.Parse(typeof(PSRepositoryInfo.APIVersion), node.Attribute("APIVersion").Value, ignoreCase: true));
769767

770768
foundRepos.Add(currentRepoItem);
771769
}
@@ -823,30 +821,30 @@ private static PSRepositoryInfo.APIVersion GetRepoAPIVersion(Uri repoUri)
823821
if (repoUri.AbsoluteUri.EndsWith("/v2", StringComparison.OrdinalIgnoreCase))
824822
{
825823
// Scenario: V2 server protocol repositories (i.e PSGallery)
826-
return PSRepositoryInfo.APIVersion.v2;
824+
return PSRepositoryInfo.APIVersion.V2;
827825
}
828826
else if (repoUri.AbsoluteUri.EndsWith("/index.json", StringComparison.OrdinalIgnoreCase))
829827
{
830828
// Scenario: V3 server protocol repositories (i.e NuGet.org, Azure Artifacts (ADO), Artifactory, Github Packages, MyGet.org)
831-
return PSRepositoryInfo.APIVersion.v3;
829+
return PSRepositoryInfo.APIVersion.V3;
832830
}
833831
else if (repoUri.AbsoluteUri.EndsWith("/nuget", StringComparison.OrdinalIgnoreCase))
834832
{
835833
// Scenario: ASP.Net application feed created with NuGet.Server to host packages
836-
return PSRepositoryInfo.APIVersion.nugetServer;
834+
return PSRepositoryInfo.APIVersion.NugetServer;
837835
}
838836
else if (repoUri.Scheme.Equals(Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase) || repoUri.Scheme.Equals("temp", StringComparison.OrdinalIgnoreCase))
839837
{
840838
// repositories with Uri Scheme "temp" may have PSPath Uri's like: "Temp:\repo" and we should consider them as local repositories.
841-
return PSRepositoryInfo.APIVersion.local;
839+
return PSRepositoryInfo.APIVersion.Local;
842840
}
843841
else if (repoUri.AbsoluteUri.EndsWith(".azurecr.io") || repoUri.AbsoluteUri.EndsWith(".azurecr.io/"))
844842
{
845-
return PSRepositoryInfo.APIVersion.acr;
843+
return PSRepositoryInfo.APIVersion.ContainerRegistry;
846844
}
847845
else
848846
{
849-
return PSRepositoryInfo.APIVersion.unknown;
847+
return PSRepositoryInfo.APIVersion.Unknown;
850848
}
851849
}
852850

src/code/ResponseUtilFactory.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ public static ResponseUtil GetResponseUtil(PSRepositoryInfo repository)
1414

1515
switch (repoApiVersion)
1616
{
17-
case PSRepositoryInfo.APIVersion.v2:
17+
case PSRepositoryInfo.APIVersion.V2:
1818
currentResponseUtil = new V2ResponseUtil(repository);
1919
break;
2020

21-
case PSRepositoryInfo.APIVersion.v3:
21+
case PSRepositoryInfo.APIVersion.V3:
2222
currentResponseUtil = new V3ResponseUtil(repository);
2323
break;
2424

25-
case PSRepositoryInfo.APIVersion.local:
25+
case PSRepositoryInfo.APIVersion.Local:
2626
currentResponseUtil = new LocalResponseUtil(repository);
2727
break;
2828

29-
case PSRepositoryInfo.APIVersion.nugetServer:
29+
case PSRepositoryInfo.APIVersion.NugetServer:
3030
currentResponseUtil = new NuGetServerResponseUtil(repository);
3131
break;
3232

33-
case PSRepositoryInfo.APIVersion.acr:
33+
case PSRepositoryInfo.APIVersion.ContainerRegistry:
3434
currentResponseUtil = new ACRResponseUtil(repository);
3535
break;
3636

37-
case PSRepositoryInfo.APIVersion.unknown:
37+
case PSRepositoryInfo.APIVersion.Unknown:
3838
break;
3939
}
4040

src/code/ServerFactory.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,27 @@ public static ServerApiCall GetServer(PSRepositoryInfo repository, PSCmdlet cmdl
4343

4444
switch (repoApiVersion)
4545
{
46-
case PSRepositoryInfo.APIVersion.v2:
46+
case PSRepositoryInfo.APIVersion.V2:
4747
currentServer = new V2ServerAPICalls(repository, cmdletPassedIn, networkCredential, userAgentString);
4848
break;
4949

50-
case PSRepositoryInfo.APIVersion.v3:
50+
case PSRepositoryInfo.APIVersion.V3:
5151
currentServer = new V3ServerAPICalls(repository, cmdletPassedIn, networkCredential, userAgentString);
5252
break;
5353

54-
case PSRepositoryInfo.APIVersion.local:
54+
case PSRepositoryInfo.APIVersion.Local:
5555
currentServer = new LocalServerAPICalls(repository, cmdletPassedIn, networkCredential);
5656
break;
5757

58-
case PSRepositoryInfo.APIVersion.nugetServer:
58+
case PSRepositoryInfo.APIVersion.NugetServer:
5959
currentServer = new NuGetServerAPICalls(repository, cmdletPassedIn, networkCredential, userAgentString);
6060
break;
6161

62-
case PSRepositoryInfo.APIVersion.acr:
62+
case PSRepositoryInfo.APIVersion.ContainerRegistry:
6363
currentServer = new ACRServerAPICalls(repository, cmdletPassedIn, networkCredential, userAgentString);
6464
break;
6565

66-
case PSRepositoryInfo.APIVersion.unknown:
66+
case PSRepositoryInfo.APIVersion.Unknown:
6767
break;
6868
}
6969

test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
1818
if ($usingAzAuth)
1919
{
2020
Write-Verbose -Verbose "Using Az module for authentication"
21-
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'acr' -Uri $ACRRepoUri -Verbose
21+
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'ContainerRegistry' -Uri $ACRRepoUri -Verbose
2222
}
2323
else
2424
{
2525
$psCredInfo = New-Object Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo ("SecretStore", "$env:TENANTID")
26-
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'acr' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose
26+
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'ContainerRegistry' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose
2727
}
2828
}
2929

test/InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ Describe 'Test Install-PSResource for ACR scenarios' -tags 'CI' {
1919

2020
if ($usingAzAuth)
2121
{
22-
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'acr' -Uri $ACRRepoUri -Verbose
22+
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'ContainerRegistry' -Uri $ACRRepoUri -Verbose
2323
}
2424
else
2525
{
2626
$psCredInfo = New-Object Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo ("SecretStore", "$env:TENANTID")
27-
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'acr' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose
27+
Register-PSResourceRepository -Name $ACRRepoName -ApiVersion 'ContainerRegistry' -Uri $ACRRepoUri -CredentialInfo $psCredInfo -Verbose
2828
}
2929
}
3030

0 commit comments

Comments
 (0)