Skip to content

Commit

Permalink
Add support for CAGetConfiguration (399) (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
larrytamnjong authored Dec 20, 2024
1 parent 5f0c473 commit 6b0e582
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Consul.Test/ConnectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,18 @@ public async Task Connect_CARoots()
Assert.NotNull(root.RootCert);
Assert.NotNull(root.SigningKeyID);
}

[Fact]
public async Task Connect_GetCAConfigurationTest()
{
var req = await _client.Connect.CAGetConfig();
var result = req.Response;

Assert.Equal("consul", result.Provider);
Assert.NotEmpty(result.Config);
Assert.False(result.ForceWithoutCrossSigning);
Assert.NotEqual((ulong)0, result.CreateIndex);
Assert.NotEqual((ulong)0, result.ModifyIndex);
}
}
}
42 changes: 42 additions & 0 deletions Consul/Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@

namespace Consul
{
public class CAConfig
{ /// <summary>
/// Provider is the CA provider implementation to use.
/// </summary>
public string Provider { get; set; }
/// <summary>
/// Configuration is arbitrary configuration for the provider. This
/// should only contain primitive values and containers (such as lists and maps).
/// </summary>
public Dictionary<string, object> Config { get; set; }
/// <summary>
/// State is read-only data that the provider might have persisted for use
/// after restart or leadership transition. For example this might include
/// UUIDs of resources it has created. Setting this when writing a configuration is an error.
/// </summary>
public Dictionary<string, string> State { get; set; }
/// <summary>
/// ForceWithoutCrossSigning indicates that the CA reconfiguration should go
/// ahead even if the current CA is unable to cross sign certificates. This
/// risks temporary connection failures during the rollout as new leafs will be
/// rejected by proxies that have not yet observed the new root cert but is the
/// only option if a CA that doesn't support cross signing needs to be reconfigured or mirated away from.
/// </summary>
public bool ForceWithoutCrossSigning { get; set; }
public ulong CreateIndex { get; set; }
public ulong ModifyIndex { get; set; }
}
public class Connect : IConnectEndpoint
{
private readonly ConsulClient _client;
Expand All @@ -48,6 +75,21 @@ public Task<QueryResult<CARoots>> CARoots(QueryOptions q, CancellationToken ct =
{
return _client.Get<CARoots>("/v1/connect/ca/roots", q).Execute(ct);
}
/// <summary>
/// CAGetConfig returns the current CA configuration.
/// </summary>
public Task<QueryResult<CAConfig>> CAGetConfig(CancellationToken ct = default)
{
return CAGetConfig(QueryOptions.Default, ct);
}

/// <summary>
/// CAGetConfig returns the current CA configuration.
/// </summary>
public Task<QueryResult<CAConfig>> CAGetConfig(QueryOptions q, CancellationToken ct = default)
{
return _client.Get<CAConfig>("/v1/connect/ca/configuration", q).Execute(ct);
}
}

public partial class ConsulClient : IConsulClient
Expand Down
2 changes: 2 additions & 0 deletions Consul/Interfaces/IConnectEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public interface IConnectEndpoint
{
Task<QueryResult<CARoots>> CARoots(QueryOptions q, CancellationToken ct = default);
Task<QueryResult<CARoots>> CARoots(CancellationToken ct = default);
Task<QueryResult<CAConfig>> CAGetConfig(QueryOptions q, CancellationToken ct = default);
Task<QueryResult<CAConfig>> CAGetConfig(CancellationToken ct = default);
}
}

0 comments on commit 6b0e582

Please sign in to comment.