diff --git a/Consul.Test/OperatorTest.cs b/Consul.Test/OperatorTest.cs index d6fb61bc..7cca81a6 100644 --- a/Consul.Test/OperatorTest.cs +++ b/Consul.Test/OperatorTest.cs @@ -17,6 +17,9 @@ // // ----------------------------------------------------------------------- +using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Xunit; @@ -98,11 +101,27 @@ public async Task Segment_List() } [EnterpriseOnlyFact] - public async Task Operator_CreateArea() + public async Task Operator_AreaCreate() { - var check = new AreaRequest { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null }; - var response = await _client.Operator.CreateArea(check); + var peerDataCenter = KVTest.GenerateTestKeyName(); + var check = new AreaRequest { PeerDatacenter = peerDataCenter, UseTLS = false, RetryJoin = null }; + + var response = await _client.Operator.AreaCreate(check); Assert.NotNull(response.Response); } + [EnterpriseOnlyFact] + public async Task Operator_AreaList() + { + var peerDataCenter = KVTest.GenerateTestKeyName(); + var area = new AreaRequest { PeerDatacenter = peerDataCenter, UseTLS = false, RetryJoin = new string[] { "10.1.2.3", "10.1.2.4" } }; + + await _client.Operator.AreaCreate(area); + + var req = await _client.Operator.AreaList(); + var result = req.Response.Single(x => x.PeerDatacenter == area.PeerDatacenter); + + Assert.Equal(area.UseTLS, result.UseTLS); + Assert.Equal(area.RetryJoin, result.RetryJoin); + } } } diff --git a/Consul/Interfaces/IOperatorEndpoint.cs b/Consul/Interfaces/IOperatorEndpoint.cs index a170a3f0..5d4adafa 100644 --- a/Consul/Interfaces/IOperatorEndpoint.cs +++ b/Consul/Interfaces/IOperatorEndpoint.cs @@ -45,8 +45,9 @@ public interface IOperatorEndpoint Task> GetConsulLicense(string datacenter = "", CancellationToken ct = default); Task> SegmentList(QueryOptions q, CancellationToken cancellationToken = default); Task> SegmentList(CancellationToken cancellationToken = default); - Task> CreateArea(AreaRequest area, WriteOptions q, CancellationToken ct = default); - Task> CreateArea(AreaRequest area, CancellationToken ct = default); - + Task> AreaCreate(AreaRequest area, WriteOptions q, CancellationToken ct = default); + Task> AreaCreate(AreaRequest area, CancellationToken ct = default); + Task>> AreaList(CancellationToken cancellationToken = default); + Task>> AreaList(QueryOptions q, CancellationToken cancellationToken = default); } } diff --git a/Consul/Operator.cs b/Consul/Operator.cs index 16c09983..74af9a1a 100644 --- a/Consul/Operator.cs +++ b/Consul/Operator.cs @@ -283,19 +283,35 @@ public Task> SegmentList(CancellationToken ct = default) /// /// CreateArea will create a new network area, a generated ID will be returned on success. /// - public Task> CreateArea(AreaRequest area, CancellationToken ct = default) + public Task> AreaCreate(AreaRequest area, CancellationToken ct = default) { - return CreateArea(area, WriteOptions.Default, ct); + return AreaCreate(area, WriteOptions.Default, ct); } /// /// 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) + public async Task> AreaCreate(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.ID); } + + /// + /// AreaList returns all the available network areas + /// + public Task>> AreaList(CancellationToken ct = default) + { + return AreaList(QueryOptions.Default, ct); + } + + /// + /// AreaList returns all the available network areas + /// + public Task>> AreaList(QueryOptions q, CancellationToken ct = default) + { + return _client.Get>("/v1/operator/area", q).Execute(ct); + } } public class ConsulLicense