Skip to content

Commit

Permalink
Change proxy to be passed in by name, rather than Id.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Compton committed Sep 29, 2017
1 parent 444da1f commit a9a84d5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3595,7 +3595,7 @@ Octopus.Client.Operations
String[] EnvironmentNames { get; set; }
String MachineName { get; set; }
String MachinePolicy { get; set; }
String ProxyId { get; set; }
String ProxyName { get; set; }
String[] Roles { get; set; }
Uri SubscriptionId { get; set; }
String[] Tenants { get; set; }
Expand All @@ -3617,7 +3617,7 @@ Octopus.Client.Operations
String[] EnvironmentNames { get; set; }
String MachineName { get; set; }
String MachinePolicy { get; set; }
String ProxyId { get; set; }
String ProxyName { get; set; }
String[] Roles { get; set; }
Uri SubscriptionId { get; set; }
String[] Tenants { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3998,7 +3998,7 @@ Octopus.Client.Operations
String[] EnvironmentNames { get; set; }
String MachineName { get; set; }
String MachinePolicy { get; set; }
String ProxyId { get; set; }
String ProxyName { get; set; }
String[] Roles { get; set; }
Uri SubscriptionId { get; set; }
String[] Tenants { get; set; }
Expand All @@ -4023,7 +4023,7 @@ Octopus.Client.Operations
String[] EnvironmentNames { get; set; }
String MachineName { get; set; }
String MachinePolicy { get; set; }
String ProxyId { get; set; }
String ProxyName { get; set; }
String[] Roles { get; set; }
Uri SubscriptionId { get; set; }
String[] Tenants { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions source/Octopus.Client/Operations/IRegisterMachineOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public interface IRegisterMachineOperation
string TentacleThumbprint { get; set; }

/// <summary>
/// Gets or sets the Id of the proxy that Octopus should use when communicating with the Tentacle.
/// Gets or sets the name of the proxy that Octopus should use when communicating with the Tentacle.
/// </summary>
string ProxyId { get; set; }
string ProxyName { get; set; }

/// <summary>
/// If a machine with the same name already exists, it won't be overwritten by default (instead, an
Expand Down
38 changes: 32 additions & 6 deletions source/Octopus.Client/Operations/RegisterMachineOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public RegisterMachineOperation(IOctopusClientFactory clientFactory)
public string TentacleThumbprint { get; set; }

/// <summary>
/// Gets or sets the Id of the proxy that Octopus should use when communicating with the Tentacle.
/// Gets or sets the name of the proxy that Octopus should use when communicating with the Tentacle.
/// </summary>
public string ProxyId { get; set; }
public string ProxyName { get; set; }

/// <summary>
/// If a machine with the same name already exists, it won't be overwritten by default (instead, an
Expand Down Expand Up @@ -140,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);
Expand Down Expand Up @@ -204,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);
Expand Down Expand Up @@ -260,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);
Expand Down Expand Up @@ -326,6 +340,18 @@ async Task<MachinePolicyResource> GetMachinePolicy(IOctopusAsyncRepository repos
return machinePolicy;
}

async Task<ProxyResource> 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<MachineResource> GetMachine(IOctopusAsyncRepository repository)
{
var existing = default(MachineResource);
Expand All @@ -341,7 +367,7 @@ async Task<MachineResource> GetMachine(IOctopusAsyncRepository repository)
return existing ?? new MachineResource();
}

void ApplyChanges(MachineResource machine, IEnumerable<EnvironmentResource> environment, MachinePolicyResource machinePolicy, IEnumerable<TenantResource> tenants)
void ApplyChanges(MachineResource machine, IEnumerable<EnvironmentResource> environment, MachinePolicyResource machinePolicy, IEnumerable<TenantResource> tenants, ProxyResource proxy)
{
machine.EnvironmentIds = new ReferenceCollection(environment.Select(e => e.Id).ToArray());
machine.TenantIds = new ReferenceCollection(tenants.Select(t => t.Id).ToArray());
Expand All @@ -356,7 +382,7 @@ void ApplyChanges(MachineResource machine, IEnumerable<EnvironmentResource> envi
var listening = new ListeningTentacleEndpointResource();
listening.Uri = new Uri("https://" + TentacleHostname.ToLowerInvariant() + ":" + TentaclePort.ToString(CultureInfo.InvariantCulture) + "/").ToString();
listening.Thumbprint = TentacleThumbprint;
listening.ProxyId = ProxyId;
listening.ProxyId = proxy?.Id;
machine.Endpoint = listening;
}
else if (CommunicationStyle == CommunicationStyle.TentacleActive)
Expand Down

0 comments on commit a9a84d5

Please sign in to comment.