Skip to content

Commit

Permalink
add operator area create support (G-Research#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
larrytamnjong committed Oct 21, 2024
1 parent 0875700 commit dd55f8f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
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(Area area, WriteOptions q, CancellationToken ct = default);
Task<WriteResult<string>> CreateArea(Area 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,34 @@ public class KeyringResponse
public int NumNodes { get; set; }
}

public class Area
{
/// <summary>
/// ID is this identifier for an area (a UUID). This must be left empty
/// when creating a new area.
/// </summary>
public string ID { get; set; }
/// <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 Operator : IOperatorEndpoint
{
private readonly ConsulClient _client;
Expand Down Expand Up @@ -249,6 +277,25 @@ public Task<QueryResult<string[]>> SegmentList(CancellationToken ct = default)
{
return SegmentList(QueryOptions.Default, ct);
}

/// <summary>
/// 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.
/// </summary>
public Task<WriteResult<string>> CreateArea(Area area, CancellationToken ct = default)
{
return CreateArea(area, WriteOptions.Default, ct);
}

/// <summary>
/// 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.
/// </summary>
public async Task<WriteResult<string>> CreateArea(Area area, WriteOptions q, CancellationToken ct = default)
{
var res = await _client.Post<Area, Area>("/v1/operator/area", area, q).Execute(ct).ConfigureAwait(false);
return new WriteResult<string>(res, res.Response.ID);
}
}

public class ConsulLicense
Expand Down

0 comments on commit dd55f8f

Please sign in to comment.