From dd55f8fe4926b4d83af5ef8201b4d64cbc764e9e Mon Sep 17 00:00:00 2001 From: tamnjongLarry Date: Mon, 21 Oct 2024 16:45:43 +0100 Subject: [PATCH 01/11] add operator area create support (#381) --- Consul/Interfaces/IOperatorEndpoint.cs | 2 ++ Consul/Operator.cs | 47 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/Consul/Interfaces/IOperatorEndpoint.cs b/Consul/Interfaces/IOperatorEndpoint.cs index 8118e97a2..91565d6d6 100644 --- a/Consul/Interfaces/IOperatorEndpoint.cs +++ b/Consul/Interfaces/IOperatorEndpoint.cs @@ -45,6 +45,8 @@ public interface IOperatorEndpoint Task> GetConsulLicense(string datacenter = "", CancellationToken ct = default); Task> SegmentList(QueryOptions q, CancellationToken cancellationToken = default); Task> SegmentList(CancellationToken cancellationToken = default); + Task> CreateArea(Area area, WriteOptions q, CancellationToken ct = default); + Task> CreateArea(Area area, CancellationToken ct = default); } } diff --git a/Consul/Operator.cs b/Consul/Operator.cs index 6e96cdf33..16043d80d 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -100,6 +100,34 @@ public class KeyringResponse public int NumNodes { get; set; } } + public class Area + { + /// + /// ID is this identifier for an area (a UUID). This must be left empty + /// when creating a new area. + /// + public string ID { get; set; } + /// + /// PeerDatacenter is the peer Consul datacenter that will make up the + /// other side of this network area. Network areas always involve a pair + /// of datacenters: the datacenter where the area was created, and the + /// peer datacenter. This is required. + /// + public string PeerDatacenter { get; set; } + + /// + /// RetryJoin specifies the address of Consul servers to join to, such as + /// an IPs or hostnames with an optional port number. This is optional. + /// + public string[] RetryJoin { get; set; } + + /// + /// UseTLS specifies whether gossip over this area should be encrypted with TLS + /// if possible. + /// + public bool UseTLS { get; set; } + } + public class Operator : IOperatorEndpoint { private readonly ConsulClient _client; @@ -249,6 +277,25 @@ public Task> SegmentList(CancellationToken ct = default) { return SegmentList(QueryOptions.Default, ct); } + + /// + /// CreateArea will create a new network area. The ID in the given structure must + /// be empty and a generated ID will be returned on success. + /// + public Task> CreateArea(Area area, CancellationToken ct = default) + { + return CreateArea(area, WriteOptions.Default, ct); + } + + /// + /// CreateArea will create a new network area. The ID in the given structure must + /// be empty and a generated ID will be returned on success. + /// + public async Task> CreateArea(Area area, WriteOptions q, CancellationToken ct = default) + { + var res = await _client.Post("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false); + return new WriteResult(res, res.Response.ID); + } } public class ConsulLicense From e1fe8dc41adb91ab7c084bfe7e4c33e4bf4840dd Mon Sep 17 00:00:00 2001 From: tamnjongLarry Date: Mon, 21 Oct 2024 17:10:19 +0100 Subject: [PATCH 02/11] add test for operator create network area (#381) --- Consul.Test/OperatorTest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Consul.Test/OperatorTest.cs b/Consul.Test/OperatorTest.cs index 0e78f4dca..cda759e8b 100644 --- a/Consul.Test/OperatorTest.cs +++ b/Consul.Test/OperatorTest.cs @@ -96,5 +96,13 @@ public async Task Segment_List() var segments = await _client.Operator.SegmentList(); Assert.NotEmpty(segments.Response); } + + [EnterpriseOnlyFact] + public async Task Operator_CreateArea() + { + var check = new Area { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null }; + var response = await _client.Operator.CreateArea(check); + Assert.NotNull(response.Response); + } } } From fa3efc054ccbfeccc1ad1af3d79f3e363806b396 Mon Sep 17 00:00:00 2001 From: tamnjongLarry Date: Tue, 22 Oct 2024 10:54:16 +0100 Subject: [PATCH 03/11] split area structure into request and response --- Consul/Operator.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Consul/Operator.cs b/Consul/Operator.cs index 16043d80d..d5aeef04f 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -102,11 +102,6 @@ public class KeyringResponse public class Area { - /// - /// ID is this identifier for an area (a UUID). This must be left empty - /// when creating a new area. - /// - public string ID { get; set; } /// /// PeerDatacenter is the peer Consul datacenter that will make up the /// other side of this network area. Network areas always involve a pair @@ -128,6 +123,14 @@ public class Area public bool UseTLS { get; set; } } + public class AreaResponse: Area + { + /// + /// ID is this identifier for an area (a UUID). This must be left empty + /// when creating a new area. + /// + public string ID { get; set; } + } public class Operator : IOperatorEndpoint { private readonly ConsulClient _client; @@ -293,7 +296,7 @@ public Task> CreateArea(Area area, CancellationToken ct = de /// public async Task> CreateArea(Area area, WriteOptions q, CancellationToken ct = default) { - var res = await _client.Post("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false); + var res = await _client.Post("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false); return new WriteResult(res, res.Response.ID); } } From ba8cffd9b77c06ad7f0bcc2e9df7654f572d0030 Mon Sep 17 00:00:00 2001 From: octocat Date: Tue, 22 Oct 2024 09:55:19 +0000 Subject: [PATCH 04/11] style: fix whitespaces --- Consul/Operator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Consul/Operator.cs b/Consul/Operator.cs index d5aeef04f..0d78a9191 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -123,7 +123,7 @@ public class Area public bool UseTLS { get; set; } } - public class AreaResponse: Area + public class AreaResponse : Area { /// /// ID is this identifier for an area (a UUID). This must be left empty From 3f4128fe3cd0a80d0df403932c908938844151cb Mon Sep 17 00:00:00 2001 From: tamnjongLarry Date: Wed, 23 Oct 2024 15:27:52 +0100 Subject: [PATCH 05/11] remove unnecessary inheritance and update create area result return type --- Consul/Interfaces/IOperatorEndpoint.cs | 4 ++-- Consul/Operator.cs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Consul/Interfaces/IOperatorEndpoint.cs b/Consul/Interfaces/IOperatorEndpoint.cs index 91565d6d6..c2227ff63 100644 --- a/Consul/Interfaces/IOperatorEndpoint.cs +++ b/Consul/Interfaces/IOperatorEndpoint.cs @@ -45,8 +45,8 @@ public interface IOperatorEndpoint Task> GetConsulLicense(string datacenter = "", CancellationToken ct = default); Task> SegmentList(QueryOptions q, CancellationToken cancellationToken = default); Task> SegmentList(CancellationToken cancellationToken = default); - Task> CreateArea(Area area, WriteOptions q, CancellationToken ct = default); - Task> CreateArea(Area area, CancellationToken ct = default); + Task> CreateArea(Area area, WriteOptions q, CancellationToken ct = default); + Task> CreateArea(Area area, CancellationToken ct = default); } } diff --git a/Consul/Operator.cs b/Consul/Operator.cs index 0d78a9191..7fef6aada 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -123,7 +123,7 @@ public class Area public bool UseTLS { get; set; } } - public class AreaResponse : Area + public class AreaResponse { /// /// ID is this identifier for an area (a UUID). This must be left empty @@ -285,7 +285,7 @@ public Task> SegmentList(CancellationToken ct = default) /// CreateArea will create a new network area. The ID in the given structure must /// be empty and a generated ID will be returned on success. /// - public Task> CreateArea(Area area, CancellationToken ct = default) + public Task> CreateArea(Area area, CancellationToken ct = default) { return CreateArea(area, WriteOptions.Default, ct); } @@ -294,10 +294,10 @@ public Task> CreateArea(Area area, CancellationToken ct = de /// CreateArea will create a new network area. The ID in the given structure must /// be empty and a generated ID will be returned on success. /// - public async Task> CreateArea(Area area, WriteOptions q, CancellationToken ct = default) + public async Task> CreateArea(Area area, WriteOptions q, CancellationToken ct = default) { - var res = await _client.Post("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false); - return new WriteResult(res, res.Response.ID); + var req = await _client.Post("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false); + return new WriteResult(req, req.Response); } } From 6a5f359a4ee520c46eef31da609984259044915f Mon Sep 17 00:00:00 2001 From: tamnjongLarry Date: Thu, 24 Oct 2024 10:58:32 +0100 Subject: [PATCH 06/11] added inheritance to area-response structure --- Consul/Operator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Consul/Operator.cs b/Consul/Operator.cs index 7fef6aada..d6ad1080e 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -123,7 +123,7 @@ public class Area public bool UseTLS { get; set; } } - public class AreaResponse + public class AreaResponse: Area { /// /// ID is this identifier for an area (a UUID). This must be left empty From fe6123f8ff9e2737a26118283d8b5fb70f6e8bcf Mon Sep 17 00:00:00 2001 From: octocat Date: Thu, 24 Oct 2024 09:59:38 +0000 Subject: [PATCH 07/11] style: fix whitespaces --- Consul/Operator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Consul/Operator.cs b/Consul/Operator.cs index d6ad1080e..b26955842 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -123,7 +123,7 @@ public class Area public bool UseTLS { get; set; } } - public class AreaResponse: Area + public class AreaResponse : Area { /// /// ID is this identifier for an area (a UUID). This must be left empty From a0c4986f9997702153158345fff32d24c05f0518 Mon Sep 17 00:00:00 2001 From: tamnjongLarry Date: Fri, 25 Oct 2024 09:32:53 +0100 Subject: [PATCH 08/11] refactor area struct usage and response handling in Create method --- Consul.Test/OperatorTest.cs | 2 +- Consul/Interfaces/IOperatorEndpoint.cs | 4 ++-- Consul/Operator.cs | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Consul.Test/OperatorTest.cs b/Consul.Test/OperatorTest.cs index cda759e8b..d6fb61bc2 100644 --- a/Consul.Test/OperatorTest.cs +++ b/Consul.Test/OperatorTest.cs @@ -100,7 +100,7 @@ public async Task Segment_List() [EnterpriseOnlyFact] public async Task Operator_CreateArea() { - var check = new Area { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null }; + var check = new AreaRequest { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null }; var response = await _client.Operator.CreateArea(check); Assert.NotNull(response.Response); } diff --git a/Consul/Interfaces/IOperatorEndpoint.cs b/Consul/Interfaces/IOperatorEndpoint.cs index c2227ff63..a170a3f0c 100644 --- a/Consul/Interfaces/IOperatorEndpoint.cs +++ b/Consul/Interfaces/IOperatorEndpoint.cs @@ -45,8 +45,8 @@ public interface IOperatorEndpoint Task> GetConsulLicense(string datacenter = "", CancellationToken ct = default); Task> SegmentList(QueryOptions q, CancellationToken cancellationToken = default); Task> SegmentList(CancellationToken cancellationToken = default); - Task> CreateArea(Area area, WriteOptions q, CancellationToken ct = default); - Task> CreateArea(Area area, CancellationToken ct = default); + Task> CreateArea(AreaRequest area, WriteOptions q, CancellationToken ct = default); + Task> CreateArea(AreaRequest area, CancellationToken ct = default); } } diff --git a/Consul/Operator.cs b/Consul/Operator.cs index b26955842..53083685e 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -100,7 +100,7 @@ public class KeyringResponse public int NumNodes { get; set; } } - public class Area + public class AreaRequest { /// /// PeerDatacenter is the peer Consul datacenter that will make up the @@ -123,7 +123,7 @@ public class Area public bool UseTLS { get; set; } } - public class AreaResponse : Area + public class Area : AreaRequest { /// /// ID is this identifier for an area (a UUID). This must be left empty @@ -285,7 +285,7 @@ public Task> SegmentList(CancellationToken ct = default) /// CreateArea will create a new network area. The ID in the given structure must /// be empty and a generated ID will be returned on success. /// - public Task> CreateArea(Area area, CancellationToken ct = default) + public Task> CreateArea(AreaRequest area, CancellationToken ct = default) { return CreateArea(area, WriteOptions.Default, ct); } @@ -294,10 +294,10 @@ public Task> CreateArea(Area area, CancellationToken c /// CreateArea will create a new network area. The ID in the given structure must /// be empty and a generated ID will be returned on success. /// - public async Task> CreateArea(Area area, WriteOptions q, CancellationToken ct = default) + public async Task> CreateArea(AreaRequest area, WriteOptions q, CancellationToken ct = default) { - var req = await _client.Post("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false); - return new WriteResult(req, req.Response); + var req = await _client.Post("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false); + return new WriteResult(req, req.Response.ID); } } From 97444c35623c6fdc30d718ada4aa20abd72fabdf Mon Sep 17 00:00:00 2001 From: tamnjongLarry Date: Fri, 25 Oct 2024 09:43:17 +0100 Subject: [PATCH 09/11] remove unnecessary comments --- Consul/Operator.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Consul/Operator.cs b/Consul/Operator.cs index 53083685e..b18675752 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -126,8 +126,7 @@ public class AreaRequest public class Area : AreaRequest { /// - /// ID is this identifier for an area (a UUID). This must be left empty - /// when creating a new area. + /// ID is this identifier for an area (a UUID). /// public string ID { get; set; } } @@ -282,8 +281,7 @@ public Task> SegmentList(CancellationToken ct = default) } /// - /// CreateArea will create a new network area. The ID in the given structure must - /// be empty and a generated ID will be returned on success. + /// CreateArea will create a new network area. /// public Task> CreateArea(AreaRequest area, CancellationToken ct = default) { @@ -291,8 +289,7 @@ public Task> CreateArea(AreaRequest area, CancellationToken } /// - /// CreateArea will create a new network area. The ID in the given structure must - /// be empty and a generated ID will be returned on success. + /// CreateArea will create a new network area. /// public async Task> CreateArea(AreaRequest area, WriteOptions q, CancellationToken ct = default) { From 3abb767f8822abf79074af806a2691eb17854f90 Mon Sep 17 00:00:00 2001 From: Tamnjong Larry Tabeh <122117063+larrytamnjong@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:00:28 +0100 Subject: [PATCH 10/11] Update Consul/Operator.cs Update documentation comment Co-authored-by: Marcin Krystianc --- Consul/Operator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Consul/Operator.cs b/Consul/Operator.cs index b18675752..1e0df946b 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -281,7 +281,7 @@ public Task> SegmentList(CancellationToken ct = default) } /// - /// CreateArea will create a new network area. + /// CreateArea will create a new network area, a generated ID will be returned on success. /// public Task> CreateArea(AreaRequest area, CancellationToken ct = default) { From e6ac926e6b19da9b9239a6d7ca06b99bd3fa898c Mon Sep 17 00:00:00 2001 From: Tamnjong Larry Tabeh <122117063+larrytamnjong@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:00:48 +0100 Subject: [PATCH 11/11] Update Consul/Operator.cs Update documentation comment Co-authored-by: Marcin Krystianc --- Consul/Operator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Consul/Operator.cs b/Consul/Operator.cs index 1e0df946b..16c099834 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -289,7 +289,7 @@ public Task> CreateArea(AreaRequest area, CancellationToken } /// - /// CreateArea will create a new network area. + /// CreateArea will create a new network area, a generated ID will be returned on success. /// public async Task> CreateArea(AreaRequest area, WriteOptions q, CancellationToken ct = default) {