diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt
index e64a0bcb8..7a2476b13 100644
--- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt
+++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt
@@ -3595,6 +3595,7 @@ Octopus.Client.Operations
String[] EnvironmentNames { get; set; }
String MachineName { get; set; }
String MachinePolicy { get; set; }
+ String ProxyName { get; set; }
String[] Roles { get; set; }
Uri SubscriptionId { get; set; }
String[] Tenants { get; set; }
@@ -3616,6 +3617,7 @@ Octopus.Client.Operations
String[] EnvironmentNames { get; set; }
String MachineName { get; set; }
String MachinePolicy { get; set; }
+ String ProxyName { get; set; }
String[] Roles { get; set; }
Uri SubscriptionId { get; set; }
String[] Tenants { get; set; }
diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt
index a0faffa07..ea7b393c2 100644
--- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt
+++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt
@@ -3998,6 +3998,7 @@ Octopus.Client.Operations
String[] EnvironmentNames { get; set; }
String MachineName { get; set; }
String MachinePolicy { get; set; }
+ String ProxyName { get; set; }
String[] Roles { get; set; }
Uri SubscriptionId { get; set; }
String[] Tenants { get; set; }
@@ -4022,6 +4023,7 @@ Octopus.Client.Operations
String[] EnvironmentNames { get; set; }
String MachineName { get; set; }
String MachinePolicy { get; set; }
+ String ProxyName { get; set; }
String[] Roles { get; set; }
Uri SubscriptionId { get; set; }
String[] Tenants { get; set; }
diff --git a/source/Octopus.Client/Operations/IRegisterMachineOperation.cs b/source/Octopus.Client/Operations/IRegisterMachineOperation.cs
index fd859b575..78f1d4abe 100644
--- a/source/Octopus.Client/Operations/IRegisterMachineOperation.cs
+++ b/source/Octopus.Client/Operations/IRegisterMachineOperation.cs
@@ -54,6 +54,11 @@ public interface IRegisterMachineOperation
///
string TentacleThumbprint { get; set; }
+ ///
+ /// Gets or sets the name of the proxy that Octopus should use when communicating with the Tentacle.
+ ///
+ string ProxyName { get; set; }
+
///
/// If a machine with the same name already exists, it won't be overwritten by default (instead, an
/// will be thrown).
diff --git a/source/Octopus.Client/Operations/RegisterMachineOperation.cs b/source/Octopus.Client/Operations/RegisterMachineOperation.cs
index 4c0befb1f..93ba4bb34 100644
--- a/source/Octopus.Client/Operations/RegisterMachineOperation.cs
+++ b/source/Octopus.Client/Operations/RegisterMachineOperation.cs
@@ -77,6 +77,11 @@ public RegisterMachineOperation(IOctopusClientFactory clientFactory)
///
public string TentacleThumbprint { get; set; }
+ ///
+ /// Gets or sets the name of the proxy that Octopus should use when communicating with the Tentacle.
+ ///
+ public string ProxyName { get; set; }
+
///
/// If a machine with the same name already exists, it won't be overwritten by default (instead, an
/// will be thrown).
@@ -135,8 +140,9 @@ public void Execute(IOctopusRepository repository)
var machine = GetMachine(repository);
var tenants = GetTenants(repository);
ValidateTenantTags(repository);
+ var proxy = GetProxy(repository);
- ApplyChanges(machine, selectedEnvironments, machinePolicy, tenants);
+ ApplyChanges(machine, selectedEnvironments, machinePolicy, tenants, proxy);
if (machine.Id != null)
repository.Machines.Modify(machine);
@@ -199,6 +205,18 @@ MachinePolicyResource GetMachinePolicy(IOctopusRepository repository)
return machinePolicy;
}
+ ProxyResource GetProxy(IOctopusRepository repository)
+ {
+ var proxy = default(ProxyResource);
+ if (!string.IsNullOrEmpty(ProxyName))
+ {
+ proxy = repository.Proxies.FindByName(ProxyName);
+ if (proxy == null)
+ throw new ArgumentException(CouldNotFindMessage("proxy name", ProxyName));
+ }
+ return proxy;
+ }
+
MachineResource GetMachine(IOctopusRepository repository)
{
var existing = default(MachineResource);
@@ -255,9 +273,10 @@ public async Task ExecuteAsync(IOctopusAsyncRepository repository)
var machineTask = GetMachine(repository).ConfigureAwait(false);
var tenants = GetTenants(repository).ConfigureAwait(false);
await ValidateTenantTags(repository).ConfigureAwait(false);
+ var proxy = GetProxy(repository).ConfigureAwait(false);
var machine = await machineTask;
- ApplyChanges(machine, await selectedEnvironments, await machinePolicy, await tenants);
+ ApplyChanges(machine, await selectedEnvironments, await machinePolicy, await tenants, await proxy);
if (machine.Id != null)
await repository.Machines.Modify(machine).ConfigureAwait(false);
@@ -321,6 +340,18 @@ async Task GetMachinePolicy(IOctopusAsyncRepository repos
return machinePolicy;
}
+ async Task GetProxy(IOctopusAsyncRepository repository)
+ {
+ var proxy = default(ProxyResource);
+ if (!string.IsNullOrEmpty(ProxyName))
+ {
+ proxy = await repository.Proxies.FindByName(ProxyName).ConfigureAwait(false);
+ if (proxy == null)
+ throw new ArgumentException(CouldNotFindMessage("proxy name", ProxyName));
+ }
+ return proxy;
+ }
+
async Task GetMachine(IOctopusAsyncRepository repository)
{
var existing = default(MachineResource);
@@ -336,7 +367,7 @@ async Task GetMachine(IOctopusAsyncRepository repository)
return existing ?? new MachineResource();
}
- void ApplyChanges(MachineResource machine, IEnumerable environment, MachinePolicyResource machinePolicy, IEnumerable tenants)
+ void ApplyChanges(MachineResource machine, IEnumerable environment, MachinePolicyResource machinePolicy, IEnumerable tenants, ProxyResource proxy)
{
machine.EnvironmentIds = new ReferenceCollection(environment.Select(e => e.Id).ToArray());
machine.TenantIds = new ReferenceCollection(tenants.Select(t => t.Id).ToArray());
@@ -351,6 +382,7 @@ void ApplyChanges(MachineResource machine, IEnumerable envi
var listening = new ListeningTentacleEndpointResource();
listening.Uri = new Uri("https://" + TentacleHostname.ToLowerInvariant() + ":" + TentaclePort.ToString(CultureInfo.InvariantCulture) + "/").ToString();
listening.Thumbprint = TentacleThumbprint;
+ listening.ProxyId = proxy?.Id;
machine.Endpoint = listening;
}
else if (CommunicationStyle == CommunicationStyle.TentacleActive)