Skip to content

Commit

Permalink
fix #28
Browse files Browse the repository at this point in the history
  • Loading branch information
apxltd committed Jan 2, 2020
1 parent e249b4e commit 76915c3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
21 changes: 21 additions & 0 deletions NuGet/InedoExtension/Operations/InstallPackagesOperation.cs
Expand Up @@ -7,6 +7,8 @@
using Inedo.Diagnostics;
using Inedo.Documentation;
using Inedo.IO;
using Inedo.ExecutionEngine.Executer;
using System;

namespace Inedo.Extensions.NuGet.Operations
{
Expand All @@ -30,9 +32,28 @@ public sealed class InstallPackagesOperation : NuGetOperationBase
[DisplayName("Source URL")]
[PlaceholderText("Use default URL specified in nuget.config")]
public string ServerUrl { get; set; }
[ScriptAlias("SourceName")]
[Category("Advanced")]
[DisplayName("Package source")]
public string PackageSource { get; set; }

public override async Task ExecuteAsync(IOperationExecutionContext context)
{
if (!string.IsNullOrEmpty(this.PackageSource))
{
if (!string.IsNullOrEmpty(this.ServerUrl))
{
this.LogWarning("SourceName will be ignored because Source (url) is specified.");
}
else
{
var packageSource = SDK.GetPackageSources().FirstOrDefault(s => string.Equals(s.Name, this.PackageSource, StringComparison.OrdinalIgnoreCase));
if (packageSource == null)
throw new ExecutionFailureException($"Package source \"{this.PackageSource}\" not found.");
this.ServerUrl = packageSource.FeedUrl;
}
}

var fileOps = await context.Agent.GetServiceAsync<IFileOperationsExecuter>().ConfigureAwait(false);
var nugetExe = await this.GetNuGetExePathAsync(context).ConfigureAwait(false);
if (string.IsNullOrEmpty(nugetExe))
Expand Down
20 changes: 13 additions & 7 deletions NuGet/InedoExtension/Operations/PublishPackageOperation.cs
Expand Up @@ -99,13 +99,19 @@ protected override async Task BeforeRemoteExecuteAsync(IOperationExecutionContex
environmentId = standardContext.EnvironmentId;
}

var credentials = (UsernamePasswordCredentials)ResourceCredentials.TryCreate("UsernamePassword", packageSource.CredentialName, environmentId, applicationId, false);
if (credentials == null)
throw new ExecutionFailureException($"Credentials ({packageSource.CredentialName}) specified in \"{packageSource.Name}\" package source must be a Username & Password credential.");

// assign these values to the operation so they get serialized prior to remote execute
this.UserName = credentials.UserName;
this.Password = AH.Unprotect(credentials.Password);
// InedoProduct
if (ResourceCredentials.TryCreate("UsernamePassword", packageSource.CredentialName, environmentId, applicationId, false) is UsernamePasswordCredentials upc)
{
this.UserName = upc.UserName;
this.Password = AH.Unprotect(upc.Password);
}
else if (ResourceCredentials.TryCreate("InedoProduct", packageSource.CredentialName, environmentId, applicationId, false) is InedoProductCredentials ipc)
{
this.UserName = "api";
this.Password = AH.Unprotect(ipc.ApiKey);
}
else
throw new ExecutionFailureException($"Credentials ({packageSource.CredentialName}) specified in \"{packageSource.Name}\" package source must be an InedoProduct or UsernamePassword credential.");
}
}

Expand Down
23 changes: 23 additions & 0 deletions NuGet/InedoExtension/Operations/RestorePackagesOperation.cs
Expand Up @@ -6,6 +6,9 @@
using Inedo.Extensibility.Operations;
using Inedo.Diagnostics;
using Inedo.Documentation;
using System.Linq;
using System;
using Inedo.ExecutionEngine.Executer;

namespace Inedo.Extensions.NuGet.Operations
{
Expand All @@ -29,9 +32,29 @@ public sealed class RestorePackagesOperation : NuGetOperationBase
[DisplayName("Source URL")]
[PlaceholderText("Use default URL specified in nuget.config")]
public string ServerUrl { get; set; }
[ScriptAlias("SourceName")]
[Category("Advanced")]
[DisplayName("Package source")]
public string PackageSource { get; set; }


public override async Task ExecuteAsync(IOperationExecutionContext context)
{
if (!string.IsNullOrEmpty(this.PackageSource))
{
if (!string.IsNullOrEmpty(this.ServerUrl))
{
this.LogWarning("SourceName will be ignored because Source (url) is specified.");
}
else
{
var packageSource = SDK.GetPackageSources().FirstOrDefault(s => string.Equals(s.Name, this.PackageSource, StringComparison.OrdinalIgnoreCase));
if (packageSource == null)
throw new ExecutionFailureException($"Package source \"{this.PackageSource}\" not found.");
this.ServerUrl = packageSource.FeedUrl;
}
}

var fileOps = await context.Agent.GetServiceAsync<IFileOperationsExecuter>().ConfigureAwait(false);
var nugetExe = await this.GetNuGetExePathAsync(context).ConfigureAwait(false);
if (string.IsNullOrEmpty(nugetExe))
Expand Down
2 changes: 1 addition & 1 deletion NuGet/InedoExtension/Properties/AssemblyInfo.cs
Expand Up @@ -11,4 +11,4 @@
[assembly: ComVisible(false)]
[assembly: ScriptNamespace("NuGet")]

[assembly: AppliesTo(InedoProduct.BuildMaster | InedoProduct.Otter | InedoProduct.Hedgehog)]
[assembly: AppliesTo(InedoProduct.BuildMaster | InedoProduct.Otter)]

0 comments on commit 76915c3

Please sign in to comment.