@@ -54,6 +54,8 @@ internal class ContainerRegistryServerAPICalls : ServerApiCall
5454
5555 const string containerRegistryRepositoryListTemplate = "https://{0}/v2/_catalog" ; // 0 - registry
5656
57+ private string _cachedContainterRegistryToken = null ;
58+
5759 #endregion
5860
5961 #region Constructor
@@ -68,6 +70,8 @@ public ContainerRegistryServerAPICalls(PSRepositoryInfo repository, PSCmdlet cmd
6870 Credentials = networkCredential
6971 } ;
7072
73+ _cachedContainterRegistryToken = null ;
74+
7175 _sessionClient = new HttpClient ( handler ) ;
7276 _sessionClient . Timeout = TimeSpan . FromMinutes ( 10 ) ;
7377 _sessionClient . DefaultRequestHeaders . TryAddWithoutValidation ( "User-Agent" , userAgentString ) ;
@@ -384,6 +388,12 @@ internal string GetContainerRegistryAccessToken(bool needCatalogAccess, out Erro
384388 string tenantID = string . Empty ;
385389 errRecord = null ;
386390
391+ if ( ! string . IsNullOrEmpty ( _cachedContainterRegistryToken ) )
392+ {
393+ _cmdletPassedIn . WriteVerbose ( "Using cached container registry access token." ) ;
394+ return _cachedContainterRegistryToken ;
395+ }
396+
387397 var repositoryCredentialInfo = Repository . CredentialInfo ;
388398 if ( repositoryCredentialInfo != null )
389399 {
@@ -445,6 +455,9 @@ internal string GetContainerRegistryAccessToken(bool needCatalogAccess, out Erro
445455 return null ;
446456 }
447457
458+ _cmdletPassedIn . WriteVerbose ( "Container registry access token retrieved." ) ;
459+ _cachedContainterRegistryToken = containerRegistryAccessToken ;
460+
448461 return containerRegistryAccessToken ;
449462 }
450463
@@ -739,7 +752,7 @@ internal Hashtable GetContainerRegistryMetadata(string packageName, string exact
739752 {
740753 using ( JsonDocument metadataJSONDoc = JsonDocument . Parse ( serverPkgInfo . Metadata ) )
741754 {
742- string pkgVersionString = String . Empty ;
755+ string pkgVersionString = String . Empty ;
743756 JsonElement rootDom = metadataJSONDoc . RootElement ;
744757
745758 if ( rootDom . TryGetProperty ( "ModuleVersion" , out JsonElement pkgVersionElement ) )
0 commit comments