Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
strategy:
matrix:
consul: [1.6.10, 1.7.14, 1.8.19, 1.9.17, 1.10.12, 1.11.11, 1.12.9, 1.13.9, 1.14.11, 1.15.10, 1.16.6, 1.17.3, 1.18.2, 1.19.0]
consul: [1.6.10, 1.7.14, 1.8.19, 1.9.17, 1.10.12, 1.11.11, 1.12.9, 1.13.9, 1.14.11, 1.15.10, 1.16.6, 1.17.3, 1.18.2, 1.19.1]
framework: [net461, net6.0, net7.0, net8.0]
os: [ubuntu-latest, windows-latest, macos-latest, macos-13] # macos-13 for x86_x64 arch
fail-fast: false
Expand Down
14 changes: 14 additions & 0 deletions Consul.Test/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,20 @@ public async Task Agent_Metrics()
Assert.NotNull(agentMetrics.Response.Samples);
}

[Fact]
public async Task Agent_ConnectAuthorize()
{
var parameters = new AgentAuthorizeParameters
{
Target = "foo",
ClientCertSerial = "fake",
ClientCertURI = "spiffe://11111111-2222-3333-4444-555555555555.consul/ns/default/dc/ny1/svc/web",
};
var result = await _client.Agent.ConnectAuthorize(parameters);
Assert.True(result.Response.Authorized);
Assert.Equal("Default behavior configured by ACLs", result.Response.Reason);
}

[Fact]
public async Task Agent_CARoots()
{
Expand Down
2 changes: 1 addition & 1 deletion Consul.Test/Consul.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="3.1.0" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Xunit.SkippableFact" Version="1.3.12" />
Expand Down
42 changes: 42 additions & 0 deletions Consul.Test/CoordinateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// -----------------------------------------------------------------------

using System;
using System.Net;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -73,5 +74,46 @@ public async Task Coordinate_GetNode()
Assert.IsType<CoordinateEntry[]>(nodeDetails);
Assert.NotEmpty(nodeDetails);
}

[Fact]
public async Task Coordinate_Update()
{
var nodeName = "foo-update-lan";
var registration = new CatalogRegistration
{
Node = nodeName,
Address = "1.1.1.1"
};
var register = await _client.Catalog.Register(registration);
var nodeResult = await _client.Catalog.Node(nodeName);
Assert.Equal(HttpStatusCode.OK, nodeResult.StatusCode);

var coord = new CoordinateEntry
{
Node = nodeName,
Coord = new SerfCoordinate
{
Error = 1.5,
Height = 0.5,
Adjustment = 0.0,
Vec = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
}
};

var response = await _client.Coordinate.Update(coord);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

var q = new QueryOptions { WaitIndex = nodeResult.LastIndex, };
var newCoordResult = await _client.Coordinate.Node(nodeName, q);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(newCoordResult.Response);

var newCoord = newCoordResult.Response[0];
Assert.Equal(coord.Coord.Vec.Count, newCoord.Coord.Vec.Count);
Assert.Equal(coord.Node, newCoord.Node);
Assert.True(Math.Abs(coord.Coord.Height - newCoord.Coord.Height) <= 0.00001);
Assert.True(Math.Abs(coord.Coord.Adjustment - newCoord.Coord.Adjustment) <= 0.00001);
Assert.True(Math.Abs(coord.Coord.Error - newCoord.Coord.Error) <= 0.00001);
}
}
}
36 changes: 36 additions & 0 deletions Consul/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,19 @@ public class Sample
public Dictionary<string, string> Labels { get; set; }
}

public class AgentAuthorizeParameters
{
public string Target { get; set; }
public string ClientCertURI { get; set; }
public string ClientCertSerial { get; set; }
}

public class AgentAuthorizeResponse
{
public bool Authorized { get; set; }
public string Reason { get; set; }
}

public class CARoots
{
public string ActiveRootID { get; set; }
Expand Down Expand Up @@ -1177,6 +1190,29 @@ public async Task<QueryResult<ServiceConfiguration>> GetServiceConfiguration(str
return await _client.Get<ServiceConfiguration>($"/v1/agent/service/{serviceId}", q).Execute(ct).ConfigureAwait(false);
}

/// <summary>
/// ConnectAuthorize tests whether a connection is authorized between two services
/// </summary>
/// <param name="parameters">Parameters for the request</param>
/// <param name="ct">Cancellation Token</param>
/// <returns>An Authorize Response</returns>
public async Task<WriteResult<AgentAuthorizeResponse>> ConnectAuthorize(AgentAuthorizeParameters parameters, CancellationToken ct = default)
{
return await ConnectAuthorize(parameters, WriteOptions.Default, ct).ConfigureAwait(false);
}

/// <summary>
/// ConnectAuthorize tests whether a connection is authorized between two services
/// </summary>
/// <param name="parameters">Parameters for the request</param>
/// <param name="w">Write Options</param>
/// <param name="ct">Cancellation Token</param>
/// <returns>An Authorize Response</returns>
public async Task<WriteResult<AgentAuthorizeResponse>> ConnectAuthorize(AgentAuthorizeParameters parameters, WriteOptions w, CancellationToken ct = default)
{
return await _client.Post<AgentAuthorizeParameters, AgentAuthorizeResponse>("/v1/agent/connect/authorize", parameters, w).Execute(ct).ConfigureAwait(false);
}

/// <summary>
/// GetCARoots returns root certificates in the cluster
/// </summary>
Expand Down
24 changes: 24 additions & 0 deletions Consul/Coordinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace Consul
public class CoordinateEntry
{
public string Node { get; set; }
public string Segment { get; set; }
public SerfCoordinate Coord { get; set; }
}

Expand Down Expand Up @@ -105,6 +106,29 @@ public Task<QueryResult<CoordinateEntry[]>> Node(string node, CancellationToken
{
return Node(node, QueryOptions.Default, ct);
}

/// <summary>
/// Updates the LAN network coordinates for a node in a given datacenter.
/// </summary>
/// <param name="entry">The coordinate entry to update</param>
/// <param name="q">Customized write options</param>
/// <param name="ct">Cancellation Token</param>
/// <returns>An empty write result</returns>
public Task<WriteResult> Update(CoordinateEntry entry, WriteOptions q, CancellationToken ct = default)
{
return _client.Put("/v1/coordinate/update", entry, q).Execute(ct);
}

/// <summary>
/// Updates the LAN network coordinates for a node in a given datacenter.
/// </summary>
/// <param name="entry">The coordinate entry to update</param>
/// <param name="ct">Cancellation Token</param>
/// <returns>An empty write result</returns>
public Task<WriteResult> Update(CoordinateEntry entry, CancellationToken ct = default)
{
return Update(entry, WriteOptions.Default, ct);
}
}

public partial class ConsulClient : IConsulClient
Expand Down
2 changes: 2 additions & 0 deletions Consul/Interfaces/IAgentEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public interface IAgentEndpoint
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, QueryOptions q, CancellationToken ct = default);
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, CancellationToken ct = default);
Task<QueryResult<Metrics>> GetAgentMetrics(CancellationToken ct = default);
Task<WriteResult<AgentAuthorizeResponse>> ConnectAuthorize(AgentAuthorizeParameters parameters, CancellationToken ct = default);
Task<WriteResult<AgentAuthorizeResponse>> ConnectAuthorize(AgentAuthorizeParameters parameters, WriteOptions w, CancellationToken ct = default);
Task<QueryResult<CARoots>> GetCARoots(CancellationToken ct = default);
Task<QueryResult<CARoots>> GetCARoots(QueryOptions q, CancellationToken ct = default);
Task<QueryResult<CALeaf>> GetCALeaf(string serviceId, CancellationToken ct = default);
Expand Down
2 changes: 2 additions & 0 deletions Consul/Interfaces/ICoordinateEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ public interface ICoordinateEndpoint
Task<QueryResult<CoordinateEntry[]>> Node(string node, QueryOptions q, CancellationToken ct = default);
Task<QueryResult<CoordinateEntry[]>> Node(string node, CancellationToken ct = default);
Task<QueryResult<CoordinateEntry[]>> Nodes(QueryOptions q, CancellationToken ct = default);
Task<WriteResult> Update(CoordinateEntry entry, WriteOptions q, CancellationToken ct = default);
Task<WriteResult> Update(CoordinateEntry entry, CancellationToken ct = default);
}
}