Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Consul.Test/OperatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 AreaRequest { PeerDatacenter = "dc2", UseTLS = false, RetryJoin = null };
var response = await _client.Operator.CreateArea(check);
Assert.NotNull(response.Response);
}
}
}
2 changes: 2 additions & 0 deletions Consul/Interfaces/IOperatorEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public interface IOperatorEndpoint
Task<QueryResult<ConsulLicense>> GetConsulLicense(string datacenter = "", CancellationToken ct = default);
Task<QueryResult<string[]>> SegmentList(QueryOptions q, CancellationToken cancellationToken = default);
Task<QueryResult<string[]>> SegmentList(CancellationToken cancellationToken = default);
Task<WriteResult<string>> CreateArea(AreaRequest area, WriteOptions q, CancellationToken ct = default);
Task<WriteResult<string>> CreateArea(AreaRequest area, CancellationToken ct = default);

}
}
47 changes: 47 additions & 0 deletions Consul/Operator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ public class KeyringResponse
public int NumNodes { get; set; }
}

public class AreaRequest
{
/// <summary>
/// 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.
/// </summary>
public string PeerDatacenter { get; set; }

/// <summary>
/// RetryJoin specifies the address of Consul servers to join to, such as
/// an IPs or hostnames with an optional port number. This is optional.
/// </summary>
public string[] RetryJoin { get; set; }

/// <summary>
/// UseTLS specifies whether gossip over this area should be encrypted with TLS
/// if possible.
/// </summary>
public bool UseTLS { get; set; }
}

public class Area : AreaRequest
{
/// <summary>
/// ID is this identifier for an area (a UUID).
/// </summary>
public string ID { get; set; }
}
public class Operator : IOperatorEndpoint
{
private readonly ConsulClient _client;
Expand Down Expand Up @@ -249,6 +279,23 @@ public Task<QueryResult<string[]>> SegmentList(CancellationToken ct = default)
{
return SegmentList(QueryOptions.Default, ct);
}

/// <summary>
/// CreateArea will create a new network area.
/// </summary>
public Task<WriteResult<string>> CreateArea(AreaRequest area, CancellationToken ct = default)
{
return CreateArea(area, WriteOptions.Default, ct);
}

/// <summary>
/// CreateArea will create a new network area.
/// </summary>
public async Task<WriteResult<string>> CreateArea(AreaRequest area, WriteOptions q, CancellationToken ct = default)
{
var req = await _client.Post<AreaRequest, Area>("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false);
return new WriteResult<string>(req, req.Response.ID);
}
}

public class ConsulLicense
Expand Down
Loading