From dd55f8fe4926b4d83af5ef8201b4d64cbc764e9e Mon Sep 17 00:00:00 2001 From: tamnjongLarry Date: Mon, 21 Oct 2024 16:45:43 +0100 Subject: [PATCH] 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 8118e97a..91565d6d 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 6e96cdf3..16043d80 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