Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/code/PublishHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ internal enum CallerCmdlet
private string pathToModuleDirToPublish = string.Empty;
private string pathToNupkgToPublish = string.Empty;
private ResourceType resourceType = ResourceType.None;
private NetworkCredential _networkCredential;
string userAgentString = UserAgentInfo.UserAgentString();
private bool _isNupkgPathSpecified = false;
private Hashtable dependencies;
Expand Down Expand Up @@ -381,15 +380,15 @@ internal void PushResource(string Repository, string modulePrefix, bool SkipDepe
}

// Set network credentials via passed in credentials, AzArtifacts CredentialProvider, or SecretManagement.
_networkCredential = repository.SetNetworkCredentials(_networkCredential, _cmdletPassedIn);
var networkCredential = repository.SetNetworkCredentials(_networkCredential, _cmdletPassedIn);

// Check if dependencies already exist within the repo if:
// 1) the resource to publish has dependencies and
// 2) the -SkipDependenciesCheck flag is not passed in
if (dependencies != null && !SkipDependenciesCheck)
{
// If error gets thrown, exit process record
if (!CheckDependenciesExist(dependencies, repository.Name))
if (!CheckDependenciesExist(dependencies, repository.Name, networkCredential))
{
return;
}
Expand Down Expand Up @@ -440,7 +439,7 @@ internal void PushResource(string Repository, string modulePrefix, bool SkipDepe

if (repository.ApiVersion == PSRepositoryInfo.APIVersion.ContainerRegistry)
{
ContainerRegistryServerAPICalls containerRegistryServer = new ContainerRegistryServerAPICalls(repository, _cmdletPassedIn, _networkCredential, userAgentString);
ContainerRegistryServerAPICalls containerRegistryServer = new ContainerRegistryServerAPICalls(repository, _cmdletPassedIn, networkCredential, userAgentString);

if (_isNupkgPathSpecified)
{
Expand Down Expand Up @@ -475,7 +474,7 @@ internal void PushResource(string Repository, string modulePrefix, bool SkipDepe
}

// This call does not throw any exceptions, but it will write unsuccessful responses to the console
if (!PushNupkg(outputNupkgDir, repository.Name, repository.Uri.ToString(), out ErrorRecord pushNupkgError))
if (!PushNupkg(outputNupkgDir, repository.Name, repository.Uri.ToString(), networkCredential, out ErrorRecord pushNupkgError))
{
_cmdletPassedIn.WriteError(pushNupkgError);
// exit out of processing
Expand Down Expand Up @@ -648,7 +647,7 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil
return true;
}

private bool PushNupkg(string outputNupkgDir, string repoName, string repoUri, out ErrorRecord error)
private bool PushNupkg(string outputNupkgDir, string repoName, string repoUri, NetworkCredential networkCredential, out ErrorRecord error)
{
_cmdletPassedIn.WriteDebug("In PublishPSResource::PushNupkg()");

Expand All @@ -674,9 +673,9 @@ private bool PushNupkg(string outputNupkgDir, string repoName, string repoUri, o
var success = false;

var sourceProvider = new PackageSourceProvider(settings);
if (Credential != null || _networkCredential != null)
if (Credential != null || networkCredential != null)
{
InjectCredentialsToSettings(settings, sourceProvider, publishLocation);
InjectCredentialsToSettings(settings, sourceProvider, publishLocation, networkCredential);
}


Expand Down Expand Up @@ -833,10 +832,10 @@ private bool PushNupkg(string outputNupkgDir, string repoName, string repoUri, o
return success;
}

private void InjectCredentialsToSettings(ISettings settings, IPackageSourceProvider sourceProvider, string source)
private void InjectCredentialsToSettings(ISettings settings, IPackageSourceProvider sourceProvider, string source, NetworkCredential networkCredential)
{
_cmdletPassedIn.WriteDebug("In PublishPSResource::InjectCredentialsToSettings()");
if (Credential == null && _networkCredential == null)
if (Credential == null && networkCredential == null)
{
return;
}
Expand All @@ -851,7 +850,7 @@ private void InjectCredentialsToSettings(ISettings settings, IPackageSourceProvi
}


var networkCred = Credential == null ? _networkCredential : Credential.GetNetworkCredential();
var networkCred = Credential == null ? networkCredential : Credential.GetNetworkCredential();
string key;

if (packageSource == null)
Expand Down Expand Up @@ -1246,7 +1245,7 @@ private Hashtable ParseRequiredModules(Hashtable parsedMetadataHash)
return dependenciesHash;
}

private bool CheckDependenciesExist(Hashtable dependencies, string repositoryName)
private bool CheckDependenciesExist(Hashtable dependencies, string repositoryName, NetworkCredential networkCredential)
{
_cmdletPassedIn.WriteDebug("In PublishHelper::CheckDependenciesExist()");

Expand Down Expand Up @@ -1276,7 +1275,7 @@ private bool CheckDependenciesExist(Hashtable dependencies, string repositoryNam
}

// Search for and return the dependency if it's in the repository.
FindHelper findHelper = new FindHelper(_cancellationToken, _cmdletPassedIn, _networkCredential);
FindHelper findHelper = new FindHelper(_cancellationToken, _cmdletPassedIn, networkCredential);

var repository = new[] { repositoryName };
// Note: we set prerelease argument for FindByResourceName() to true because if no version is specified we want latest version (including prerelease).
Expand Down