@@ -50,7 +50,6 @@ internal enum CallerCmdlet
5050 private string pathToModuleDirToPublish = string . Empty ;
5151 private string pathToNupkgToPublish = string . Empty ;
5252 private ResourceType resourceType = ResourceType . None ;
53- private NetworkCredential _networkCredential ;
5453 string userAgentString = UserAgentInfo . UserAgentString ( ) ;
5554 private bool _isNupkgPathSpecified = false ;
5655 private Hashtable dependencies ;
@@ -381,15 +380,15 @@ internal void PushResource(string Repository, string modulePrefix, bool SkipDepe
381380 }
382381
383382 // Set network credentials via passed in credentials, AzArtifacts CredentialProvider, or SecretManagement.
384- _networkCredential = repository . SetNetworkCredentials ( _networkCredential , _cmdletPassedIn ) ;
383+ var networkCredential = repository . SetNetworkCredentials ( _networkCredential , _cmdletPassedIn ) ;
385384
386385 // Check if dependencies already exist within the repo if:
387386 // 1) the resource to publish has dependencies and
388387 // 2) the -SkipDependenciesCheck flag is not passed in
389388 if ( dependencies != null && ! SkipDependenciesCheck )
390389 {
391390 // If error gets thrown, exit process record
392- if ( ! CheckDependenciesExist ( dependencies , repository . Name ) )
391+ if ( ! CheckDependenciesExist ( dependencies , repository . Name , networkCredential ) )
393392 {
394393 return ;
395394 }
@@ -440,7 +439,7 @@ internal void PushResource(string Repository, string modulePrefix, bool SkipDepe
440439
441440 if ( repository . ApiVersion == PSRepositoryInfo . APIVersion . ContainerRegistry )
442441 {
443- ContainerRegistryServerAPICalls containerRegistryServer = new ContainerRegistryServerAPICalls ( repository , _cmdletPassedIn , _networkCredential , userAgentString ) ;
442+ ContainerRegistryServerAPICalls containerRegistryServer = new ContainerRegistryServerAPICalls ( repository , _cmdletPassedIn , networkCredential , userAgentString ) ;
444443
445444 if ( _isNupkgPathSpecified )
446445 {
@@ -475,7 +474,7 @@ internal void PushResource(string Repository, string modulePrefix, bool SkipDepe
475474 }
476475
477476 // This call does not throw any exceptions, but it will write unsuccessful responses to the console
478- if ( ! PushNupkg ( outputNupkgDir , repository . Name , repository . Uri . ToString ( ) , out ErrorRecord pushNupkgError ) )
477+ if ( ! PushNupkg ( outputNupkgDir , repository . Name , repository . Uri . ToString ( ) , networkCredential , out ErrorRecord pushNupkgError ) )
479478 {
480479 _cmdletPassedIn . WriteError ( pushNupkgError ) ;
481480 // exit out of processing
@@ -648,7 +647,7 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil
648647 return true ;
649648 }
650649
651- private bool PushNupkg ( string outputNupkgDir , string repoName , string repoUri , out ErrorRecord error )
650+ private bool PushNupkg ( string outputNupkgDir , string repoName , string repoUri , NetworkCredential networkCredential , out ErrorRecord error )
652651 {
653652 _cmdletPassedIn . WriteDebug ( "In PublishPSResource::PushNupkg()" ) ;
654653
@@ -674,9 +673,9 @@ private bool PushNupkg(string outputNupkgDir, string repoName, string repoUri, o
674673 var success = false ;
675674
676675 var sourceProvider = new PackageSourceProvider ( settings ) ;
677- if ( Credential != null || _networkCredential != null )
676+ if ( Credential != null || networkCredential != null )
678677 {
679- InjectCredentialsToSettings ( settings , sourceProvider , publishLocation ) ;
678+ InjectCredentialsToSettings ( settings , sourceProvider , publishLocation , networkCredential ) ;
680679 }
681680
682681
@@ -833,10 +832,10 @@ private bool PushNupkg(string outputNupkgDir, string repoName, string repoUri, o
833832 return success ;
834833 }
835834
836- private void InjectCredentialsToSettings ( ISettings settings , IPackageSourceProvider sourceProvider , string source )
835+ private void InjectCredentialsToSettings ( ISettings settings , IPackageSourceProvider sourceProvider , string source , NetworkCredential networkCredential )
837836 {
838837 _cmdletPassedIn . WriteDebug ( "In PublishPSResource::InjectCredentialsToSettings()" ) ;
839- if ( Credential == null && _networkCredential == null )
838+ if ( Credential == null && networkCredential == null )
840839 {
841840 return ;
842841 }
@@ -851,7 +850,7 @@ private void InjectCredentialsToSettings(ISettings settings, IPackageSourceProvi
851850 }
852851
853852
854- var networkCred = Credential == null ? _networkCredential : Credential . GetNetworkCredential ( ) ;
853+ var networkCred = Credential == null ? networkCredential : Credential . GetNetworkCredential ( ) ;
855854 string key ;
856855
857856 if ( packageSource == null )
@@ -1246,7 +1245,7 @@ private Hashtable ParseRequiredModules(Hashtable parsedMetadataHash)
12461245 return dependenciesHash ;
12471246 }
12481247
1249- private bool CheckDependenciesExist ( Hashtable dependencies , string repositoryName )
1248+ private bool CheckDependenciesExist ( Hashtable dependencies , string repositoryName , NetworkCredential networkCredential )
12501249 {
12511250 _cmdletPassedIn . WriteDebug ( "In PublishHelper::CheckDependenciesExist()" ) ;
12521251
@@ -1276,7 +1275,7 @@ private bool CheckDependenciesExist(Hashtable dependencies, string repositoryNam
12761275 }
12771276
12781277 // Search for and return the dependency if it's in the repository.
1279- FindHelper findHelper = new FindHelper ( _cancellationToken , _cmdletPassedIn , _networkCredential ) ;
1278+ FindHelper findHelper = new FindHelper ( _cancellationToken , _cmdletPassedIn , networkCredential ) ;
12801279
12811280 var repository = new [ ] { repositoryName } ;
12821281 // Note: we set prerelease argument for FindByResourceName() to true because if no version is specified we want latest version (including prerelease).
0 commit comments