Skip to content

Commit

Permalink
Merge pull request #29 from Inedo/1.7.0
Browse files Browse the repository at this point in the history
1.7.0
  • Loading branch information
jrasch committed Jan 21, 2020
2 parents 76915c3 + 3dcf18f commit a8063e2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 41 deletions.
22 changes: 15 additions & 7 deletions NuGet/InedoExtension/InedoExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="Inedo.Agents, Version=46.0.0.0, Culture=neutral, PublicKeyToken=9de986a2f8db80fc, processorArchitecture=MSIL">
<HintPath>..\packages\Inedo.SDK.1.7.0\lib\net452\Inedo.Agents.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Inedo.Agents.Client, Version=1000.0.0.0, Culture=neutral, PublicKeyToken=9de986a2f8db80fc, processorArchitecture=MSIL">
<HintPath>..\packages\Inedo.SDK.1.5.0\lib\net452\Inedo.Agents.Client.dll</HintPath>
<HintPath>..\packages\Inedo.SDK.1.7.0\lib\net452\Inedo.Agents.Client.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Inedo.ExecutionEngine, Version=1000.0.0.0, Culture=neutral, PublicKeyToken=68703f0e52007e75, processorArchitecture=MSIL">
<HintPath>..\packages\Inedo.SDK.1.5.0\lib\net452\Inedo.ExecutionEngine.dll</HintPath>
<HintPath>..\packages\Inedo.SDK.1.7.0\lib\net452\Inedo.ExecutionEngine.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
Expand All @@ -47,24 +52,27 @@
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Inedo.SDK, Version=1.5.0.0, Culture=neutral, PublicKeyToken=29fae5dec3001603, processorArchitecture=MSIL">
<HintPath>..\packages\Inedo.SDK.1.5.0\lib\net452\Inedo.SDK.dll</HintPath>
<Reference Include="Inedo.SDK, Version=1.7.0.0, Culture=neutral, PublicKeyToken=29fae5dec3001603, processorArchitecture=MSIL">
<HintPath>..\packages\Inedo.SDK.1.7.0\lib\net452\Inedo.SDK.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="InedoLib, Version=1000.0.0.0, Culture=neutral, PublicKeyToken=112cfb71329714a6, processorArchitecture=MSIL">
<HintPath>..\packages\Inedo.SDK.1.5.0\lib\net452\InedoLib.dll</HintPath>
<HintPath>..\packages\Inedo.SDK.1.7.0\lib\net452\InedoLib.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Inedo.SDK.1.5.0\lib\net452\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Inedo.SDK.1.7.0\lib\net452\Newtonsoft.Json.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Inedo.SDK.1.7.0\lib\net452\System.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down
9 changes: 5 additions & 4 deletions NuGet/InedoExtension/Operations/InstallPackagesOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Inedo.IO;
using Inedo.ExecutionEngine.Executer;
using System;
using Inedo.Extensions.SecureResources;
using Inedo.Extensibility.SecureResources;

namespace Inedo.Extensions.NuGet.Operations
{
Expand Down Expand Up @@ -47,10 +49,9 @@ public override async Task ExecuteAsync(IOperationExecutionContext context)
}
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;
this.LogDebug($"Using package source {this.PackageSource}.");
var packageSource = (NuGetPackageSource)SecureResource.Create(this.PackageSource, (IResourceResolutionContext)context);
this.ServerUrl = packageSource.ApiEndpointUrl;
}
}

Expand Down
47 changes: 22 additions & 25 deletions NuGet/InedoExtension/Operations/PublishPackageOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
using System.Linq;
using Inedo.ExecutionEngine.Executer;
using System.Xml.Linq;
using Inedo.Extensions.SecureResources;
using Inedo.Extensibility.SecureResources;
using Inedo.Extensions.Credentials;
using LegacyUsernamePasswordCredentials = Inedo.Extensibility.Credentials.UsernamePasswordCredentials;

namespace Inedo.Extensions.NuGet.Operations
{
Expand All @@ -25,7 +29,10 @@ namespace Inedo.Extensions.NuGet.Operations
[Description("Publishes a package to a NuGet feed.")]
[DefaultProperty(nameof(PackagePath))]
[Tag("nuget")]
public sealed class PublishPackageOperation : RemoteExecuteOperation, IHasCredentials<UsernamePasswordCredentials>
public sealed class PublishPackageOperation : RemoteExecuteOperation
#pragma warning disable CS0618 // Type or member is obsolete
, IHasCredentials<LegacyUsernamePasswordCredentials>
#pragma warning restore CS0618 // Type or member is obsolete
{
[NonSerialized]
private IPackageManager packageManager;
Expand All @@ -52,13 +59,13 @@ public sealed class PublishPackageOperation : RemoteExecuteOperation, IHasCreden
[Category("Authentication")]
[ScriptAlias("UserName")]
[DisplayName("User name")]
[MappedCredential(nameof(UsernamePasswordCredentials.UserName))]
[MappedCredential(nameof(LegacyUsernamePasswordCredentials.UserName))]
[PlaceholderText("Use username from credentials")]
public string UserName { get; set; }
[Category("Authentication")]
[ScriptAlias("Password")]
[DisplayName("Password")]
[MappedCredential(nameof(UsernamePasswordCredentials.Password))]
[MappedCredential(nameof(LegacyUsernamePasswordCredentials.Password))]
[PlaceholderText("Use password from credentials")]
public string Password { get; set; }

Expand All @@ -79,39 +86,28 @@ protected override async Task BeforeRemoteExecuteAsync(IOperationExecutionContex
// if username is not already specified and there is a package source, look up any attached credentials
if (string.IsNullOrEmpty(this.UserName) && !string.IsNullOrEmpty(this.PackageSource))
{
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.LogDebug($"Using package source {this.PackageSource}.");
var packageSource = (NuGetPackageSource)SecureResource.Create(this.PackageSource, (IResourceResolutionContext)context);

if (string.IsNullOrEmpty(this.ServerUrl))
this.ServerUrl = packageSource.FeedUrl;
this.ServerUrl = packageSource.ApiEndpointUrl;

if (!string.IsNullOrEmpty(packageSource.CredentialName))
{
int? applicationId = null;
int? environmentId = null;

if (context is IStandardContext standardContext)
this.LogDebug($"Using credentials {packageSource.CredentialName}.");
var creds = packageSource.GetCredentials((ICredentialResolutionContext)context);
if (creds is TokenCredentials tc)
{
applicationId = standardContext.ProjectId;
environmentId = standardContext.EnvironmentId;
this.UserName = "api";
this.Password = AH.Unprotect(tc.Token);
}

// InedoProduct
if (ResourceCredentials.TryCreate("UsernamePassword", packageSource.CredentialName, environmentId, applicationId, false) is UsernamePasswordCredentials upc)
else if (creds is Inedo.Extensions.Credentials.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.");
else
throw new InvalidOperationException();
}
}

Expand Down Expand Up @@ -181,6 +177,7 @@ protected override async Task<object> RemoteExecuteAsync(IRemoteOperationExecuti
{
this.LogError($"Server responded with {(int)response.StatusCode}: {response.ReasonPhrase}");
this.LogError(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
return null;
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions NuGet/InedoExtension/Operations/RestorePackagesOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Linq;
using System;
using Inedo.ExecutionEngine.Executer;
using Inedo.Extensibility.SecureResources;
using Inedo.Extensions.SecureResources;

namespace Inedo.Extensions.NuGet.Operations
{
Expand Down Expand Up @@ -48,10 +50,9 @@ public override async Task ExecuteAsync(IOperationExecutionContext context)
}
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;
this.LogDebug($"Using package source {this.PackageSource}.");
var packageSource = (NuGetPackageSource)SecureResource.Create(this.PackageSource, (IResourceResolutionContext)context);
this.ServerUrl = packageSource.ApiEndpointUrl;
}
}

Expand Down
2 changes: 1 addition & 1 deletion NuGet/InedoExtension/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Inedo.NuGet" version="31.1" targetFramework="net452" />
<package id="Inedo.SDK" version="1.5.0" targetFramework="net452" />
<package id="Inedo.SDK" version="1.7.0" targetFramework="net452" />
</packages>

0 comments on commit a8063e2

Please sign in to comment.