Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CAGetConfiguration (399) #404

Merged
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please test all other fields too.

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);
}
}
Loading