@@ -43,7 +43,7 @@ internal class ContainerRegistryServerAPICalls : ServerApiCall
4343 const string containerRegistryOAuthTokenUrlTemplate = "https://{0}/oauth2/token" ; // 0 - registry
4444 const string containerRegistryManifestUrlTemplate = "https://{0}/v2/{1}/manifests/{2}" ; // 0 - registry, 1 - repo(modulename), 2 - tag(version)
4545 const string containerRegistryBlobDownloadUrlTemplate = "https://{0}/v2/{1}/blobs/{2}" ; // 0 - registry, 1 - repo(modulename), 2 - layer digest
46- const string containerRegistryFindImageVersionUrlTemplate = "https://{0}/acr/v1/ {1}/_tags{2} " ; // 0 - registry, 1 - repo(modulename), 2 - /tag(version )
46+ const string containerRegistryFindImageVersionUrlTemplate = "https://{0}/v2/ {1}/tags/list " ; // 0 - registry, 1 - repo(modulename)
4747 const string containerRegistryStartUploadTemplate = "https://{0}/v2/{1}/blobs/uploads/" ; // 0 - registry, 1 - packagename
4848 const string containerRegistryEndUploadTemplate = "https://{0}{1}&digest=sha256:{2}" ; // 0 - registry, 1 - location, 2 - digest
4949
@@ -413,6 +413,7 @@ internal string GetContainerRegistryAccessToken(out ErrorRecord errRecord)
413413 else
414414 {
415415 _cmdletPassedIn . WriteVerbose ( "Repository is unauthenticated" ) ;
416+ return null ;
416417 }
417418 }
418419
@@ -572,27 +573,19 @@ internal async Task<HttpContent> GetContainerRegistryBlobAsync(string packageNam
572573 /// </summary>
573574 internal JObject FindContainerRegistryImageTags ( string packageName , string version , string containerRegistryAccessToken , out ErrorRecord errRecord )
574575 {
575- /* response returned looks something like:
576- * "registry": "myregistry.azurecr.io"
577- * "imageName": "hello-world"
578- * "tags": [
579- * {
580- * ""name"": ""1.0.0"",
581- * ""digest"": ""sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a"",
582- * ""createdTime"": ""2023-12-23T18:06:48.9975733Z"",
583- * ""lastUpdateTime"": ""2023-12-23T18:06:48.9975733Z"",
584- * ""signed"": false,
585- * ""changeableAttributes"": {
586- * ""deleteEnabled"": true,
587- * ""writeEnabled"": true,
588- * ""readEnabled"": true,
589- * ""listEnabled"": true
590- * }
591- * }]
592- */
576+ /*
577+ {
578+ "name": "<name>",
579+ "tags": [
580+ "<tag1>",
581+ "<tag2>",
582+ "<tag3>"
583+ ]
584+ }
585+ */
593586 _cmdletPassedIn . WriteDebug ( "In ContainerRegistryServerAPICalls::FindContainerRegistryImageTags()" ) ;
594587 string resolvedVersion = string . Equals ( version , "*" , StringComparison . OrdinalIgnoreCase ) ? null : $ "/{ version } ";
595- string findImageUrl = string . Format ( containerRegistryFindImageVersionUrlTemplate , Registry , packageName , resolvedVersion ) ;
588+ string findImageUrl = string . Format ( containerRegistryFindImageVersionUrlTemplate , Registry , packageName ) ;
596589 var defaultHeaders = GetDefaultHeaders ( containerRegistryAccessToken ) ;
597590 return GetHttpResponseJObjectUsingDefaultHeaders ( findImageUrl , HttpMethod . Get , defaultHeaders , out errRecord ) ;
598591 }
@@ -1664,51 +1657,36 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
16641657
16651658 foreach ( var pkgVersionTagInfo in allPkgVersions )
16661659 {
1667- using ( JsonDocument pkgVersionEntry = JsonDocument . Parse ( pkgVersionTagInfo . ToString ( ) ) )
1660+ string pkgVersionString = pkgVersionTagInfo . ToString ( ) ;
1661+ // determine if the package version that is a repository tag is a valid NuGetVersion
1662+ if ( ! NuGetVersion . TryParse ( pkgVersionString , out NuGetVersion pkgVersion ) )
16681663 {
1669- JsonElement rootDom = pkgVersionEntry . RootElement ;
1670- if ( ! rootDom . TryGetProperty ( "name" , out JsonElement pkgVersionElement ) )
1671- {
1672- errRecord = new ErrorRecord (
1673- new InvalidOrEmptyResponse ( $ "Response does not contain version element ('name') for package '{ packageName } ' in '{ Repository . Name } '.") ,
1674- "FindNameFailure" ,
1675- ErrorCategory . InvalidResult ,
1676- this ) ;
1677-
1678- return null ;
1679- }
1680-
1681- string pkgVersionString = pkgVersionElement . ToString ( ) ;
1682- // determine if the package version that is a repository tag is a valid NuGetVersion
1683- if ( ! NuGetVersion . TryParse ( pkgVersionString , out NuGetVersion pkgVersion ) )
1684- {
1685- errRecord = new ErrorRecord (
1686- new ArgumentException ( $ "Version { pkgVersionString } to be parsed from metadata is not a valid NuGet version.") ,
1687- "FindNameFailure" ,
1688- ErrorCategory . InvalidArgument ,
1689- this ) ;
1664+ errRecord = new ErrorRecord (
1665+ new ArgumentException ( $ "Version { pkgVersionString } to be parsed from metadata is not a valid NuGet version.") ,
1666+ "FindNameFailure" ,
1667+ ErrorCategory . InvalidArgument ,
1668+ this ) ;
16901669
1691- return null ;
1692- }
1670+ return null ;
1671+ }
16931672
1694- _cmdletPassedIn . WriteDebug ( $ "'{ packageName } ' version parsed as '{ pkgVersion } '") ;
1673+ _cmdletPassedIn . WriteDebug ( $ "'{ packageName } ' version parsed as '{ pkgVersion } '") ;
16951674
1696- if ( isSpecificVersionSearch )
1675+ if ( isSpecificVersionSearch )
1676+ {
1677+ if ( pkgVersion . ToNormalizedString ( ) == specificVersion . ToNormalizedString ( ) )
16971678 {
1698- if ( pkgVersion . ToNormalizedString ( ) == specificVersion . ToNormalizedString ( ) )
1699- {
1700- // accounts for FindVersion() scenario
1701- sortedPkgs . Add ( pkgVersion , pkgVersionString ) ;
1702- break ;
1703- }
1679+ // accounts for FindVersion() scenario
1680+ sortedPkgs . Add ( pkgVersion , pkgVersionString ) ;
1681+ break ;
17041682 }
1705- else
1683+ }
1684+ else
1685+ {
1686+ if ( versionRange . Satisfies ( pkgVersion ) && ( ! pkgVersion . IsPrerelease || includePrerelease ) )
17061687 {
1707- if ( versionRange . Satisfies ( pkgVersion ) && ( ! pkgVersion . IsPrerelease || includePrerelease ) )
1708- {
1709- // accounts for FindVersionGlobbing() and FindName() scenario
1710- sortedPkgs . Add ( pkgVersion , pkgVersionString ) ;
1711- }
1688+ // accounts for FindVersionGlobbing() and FindName() scenario
1689+ sortedPkgs . Add ( pkgVersion , pkgVersionString ) ;
17121690 }
17131691 }
17141692 }
0 commit comments