From 444da1f12649d052a77be3387fe1d7c237ccab1c Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Thu, 28 Sep 2017 12:24:24 +1000 Subject: [PATCH 1/2] Add option to set a proxy in RegisterMachineOperation --- ...ePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt | 2 ++ ...icSurfaceAreaShouldNotRegress..NETFramework.approved.txt | 2 ++ .../Octopus.Client/Operations/IRegisterMachineOperation.cs | 5 +++++ .../Octopus.Client/Operations/RegisterMachineOperation.cs | 6 ++++++ 4 files changed, 15 insertions(+) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index e64a0bcb8..da72859e0 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 ProxyId { 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 ProxyId { 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..0c768fa6c 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 ProxyId { 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 ProxyId { 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..6742c7d8d 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 Id of the proxy that Octopus should use when communicating with the Tentacle. + /// + string ProxyId { 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..616fe1b56 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 Id of the proxy that Octopus should use when communicating with the Tentacle. + /// + public string ProxyId { get; set; } + /// /// If a machine with the same name already exists, it won't be overwritten by default (instead, an /// will be thrown). @@ -351,6 +356,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 = ProxyId; machine.Endpoint = listening; } else if (CommunicationStyle == CommunicationStyle.TentacleActive) From a9a84d51ce29cf53eee350fdf1e5cbeeb0d6221d Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 29 Sep 2017 10:21:25 +1000 Subject: [PATCH 2/2] Change proxy to be passed in by name, rather than Id. Relates to OctopusDeploy/Issues#3815 --- ...AreaShouldNotRegress..NETCore.approved.txt | 4 +- ...houldNotRegress..NETFramework.approved.txt | 4 +- .../Operations/IRegisterMachineOperation.cs | 4 +- .../Operations/RegisterMachineOperation.cs | 38 ++++++++++++++++--- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index da72859e0..7a2476b13 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -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; } @@ -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; } diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 0c768fa6c..ea7b393c2 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -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; } @@ -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; } diff --git a/source/Octopus.Client/Operations/IRegisterMachineOperation.cs b/source/Octopus.Client/Operations/IRegisterMachineOperation.cs index 6742c7d8d..78f1d4abe 100644 --- a/source/Octopus.Client/Operations/IRegisterMachineOperation.cs +++ b/source/Octopus.Client/Operations/IRegisterMachineOperation.cs @@ -55,9 +55,9 @@ public interface IRegisterMachineOperation string TentacleThumbprint { get; set; } /// - /// 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. /// - string ProxyId { get; set; } + string ProxyName { get; set; } /// /// If a machine with the same name already exists, it won't be overwritten by default (instead, an diff --git a/source/Octopus.Client/Operations/RegisterMachineOperation.cs b/source/Octopus.Client/Operations/RegisterMachineOperation.cs index 616fe1b56..93ba4bb34 100644 --- a/source/Octopus.Client/Operations/RegisterMachineOperation.cs +++ b/source/Octopus.Client/Operations/RegisterMachineOperation.cs @@ -78,9 +78,9 @@ public RegisterMachineOperation(IOctopusClientFactory clientFactory) public string TentacleThumbprint { get; set; } /// - /// 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. /// - public string ProxyId { get; set; } + public string ProxyName { get; set; } /// /// If a machine with the same name already exists, it won't be overwritten by default (instead, an @@ -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); @@ -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); @@ -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); @@ -326,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); @@ -341,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()); @@ -356,7 +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 = ProxyId; + listening.ProxyId = proxy?.Id; machine.Endpoint = listening; } else if (CommunicationStyle == CommunicationStyle.TentacleActive)