@@ -332,7 +332,7 @@ private Stream InstallVersion(
332332 return null ;
333333 }
334334
335- string containerRegistryAccessToken = GetContainerRegistryAccessToken ( needCatalogAccess : false , out errRecord ) ;
335+ string containerRegistryAccessToken = GetContainerRegistryAccessToken ( needCatalogAccess : false , isPushOperation : false , out errRecord ) ;
336336 if ( errRecord != null )
337337 {
338338 return null ;
@@ -380,7 +380,7 @@ private Stream InstallVersion(
380380 /// If no credential provided at registration then, check if the ACR endpoint can be accessed without a token. If not, try using Azure.Identity to get the az access token, then ACR refresh token and then ACR access token.
381381 /// Note: Access token can be empty if the repository is unauthenticated
382382 /// </summary>
383- internal string GetContainerRegistryAccessToken ( bool needCatalogAccess , out ErrorRecord errRecord )
383+ internal string GetContainerRegistryAccessToken ( bool needCatalogAccess , bool isPushOperation , out ErrorRecord errRecord )
384384 {
385385 _cmdletPassedIn . WriteDebug ( "In ContainerRegistryServerAPICalls::GetContainerRegistryAccessToken()" ) ;
386386 string accessToken = string . Empty ;
@@ -408,7 +408,10 @@ internal string GetContainerRegistryAccessToken(bool needCatalogAccess, out Erro
408408 }
409409 else
410410 {
411- bool isRepositoryUnauthenticated = IsContainerRegistryUnauthenticated ( Repository . Uri . ToString ( ) , needCatalogAccess , out errRecord , out accessToken ) ;
411+ // A container registry repository is determined to be unauthenticated if it allows anonymous pull access. However, push operations always require authentication.
412+ bool isRepositoryUnauthenticated = isPushOperation ? false : IsContainerRegistryUnauthenticated ( Repository . Uri . ToString ( ) , needCatalogAccess , out errRecord , out accessToken ) ;
413+ _cmdletPassedIn . WriteInformation ( $ "Value of isRepositoryUnauthenticated: { isRepositoryUnauthenticated } ", new string [ ] { "PSRGContainerRegistryUnauthenticatedCheck" } ) ;
414+
412415 _cmdletPassedIn . WriteDebug ( $ "Is repository unauthenticated: { isRepositoryUnauthenticated } ") ;
413416
414417 if ( errRecord != null )
@@ -1330,7 +1333,7 @@ internal bool PushNupkgContainerRegistry(
13301333
13311334 // Get access token (includes refresh tokens)
13321335 _cmdletPassedIn . WriteVerbose ( $ "Get access token for container registry server.") ;
1333- var containerRegistryAccessToken = GetContainerRegistryAccessToken ( needCatalogAccess : false , out errRecord ) ;
1336+ var containerRegistryAccessToken = GetContainerRegistryAccessToken ( needCatalogAccess : false , isPushOperation : true , out errRecord ) ;
13341337 if ( errRecord != null )
13351338 {
13361339 return false ;
@@ -1795,7 +1798,7 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
17951798 string packageNameLowercase = packageName . ToLower ( ) ;
17961799
17971800 string packageNameForFind = PrependMARPrefix ( packageNameLowercase ) ;
1798- string containerRegistryAccessToken = GetContainerRegistryAccessToken ( needCatalogAccess : false , out errRecord ) ;
1801+ string containerRegistryAccessToken = GetContainerRegistryAccessToken ( needCatalogAccess : false , isPushOperation : false , out errRecord ) ;
17991802 if ( errRecord != null )
18001803 {
18011804 return emptyHashResponses ;
@@ -1907,7 +1910,7 @@ private FindResults FindPackages(string packageName, bool includePrerelease, out
19071910 {
19081911 _cmdletPassedIn . WriteDebug ( "In ContainerRegistryServerAPICalls::FindPackages()" ) ;
19091912 errRecord = null ;
1910- string containerRegistryAccessToken = GetContainerRegistryAccessToken ( needCatalogAccess : true , out errRecord ) ;
1913+ string containerRegistryAccessToken = GetContainerRegistryAccessToken ( needCatalogAccess : true , isPushOperation : false , out errRecord ) ;
19111914 if ( errRecord != null )
19121915 {
19131916 return emptyResponseResults ;
0 commit comments