Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 Area { 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(Area area, WriteOptions q, CancellationToken ct = default);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result type should be Task<WriteResult<AreaResponse>>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result type should be Task<WriteResult<AreaResponse>>

When I made that comment I assumed that AreaResponse will contain only an ID field.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split it into two structures, one for request and one for response.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve just completed it. Please let me know if everything looks good.

{
/// <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
Copy link
Contributor

@marcin-krystianc marcin-krystianc Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as well it is not relevant for our API -> The ID in the given structure must be empty and a generated ID will be returned on success.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

/// 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
Loading