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 Update CA Configuration and Test(#399) #411

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
18 changes: 18 additions & 0 deletions Consul.Test/ConnectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,23 @@ public async Task Connect_GetCAConfigurationTest()
Assert.NotEqual((ulong)0, result.CreateIndex);
Assert.NotEqual((ulong)0, result.ModifyIndex);
}

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

config.Config["test_state"] = new Dictionary<string, string> { { "foo", "bar" } };
config.Config["PrivateKey"] = "";

await _client.Connect.CASetConfig(config);
req = await _client.Connect.CAGetConfig();
var updatedConfig = req.Response;

Assert.Equal("consul", updatedConfig.Provider);
Assert.Equal("bar", updatedConfig.State["foo"]);
Assert.Equal("", updatedConfig.Config["PrivateKey"]);
}
}
}
17 changes: 17 additions & 0 deletions Consul/Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ public Task<QueryResult<CAConfig>> CAGetConfig(QueryOptions q, CancellationToken
{
return _client.Get<CAConfig>("/v1/connect/ca/configuration", q).Execute(ct);
}

/// <summary>
/// CASetConfig sets the current CA configuration.
/// </summary>
public Task<WriteResult> CASetConfig(CAConfig config, CancellationToken ct = default)
{
return CASetConfig(config, WriteOptions.Default, ct);
}

/// <summary>
/// CASetConfig sets the current CA configuration.
/// </summary>
public Task<WriteResult> CASetConfig(CAConfig config, WriteOptions q, CancellationToken ct = default)
{
return _client.Put("/v1/connect/ca/configuration", config, 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 @@ -30,5 +30,7 @@ public interface IConnectEndpoint
Task<QueryResult<CARoots>> CARoots(CancellationToken ct = default);
Task<QueryResult<CAConfig>> CAGetConfig(QueryOptions q, CancellationToken ct = default);
Task<QueryResult<CAConfig>> CAGetConfig(CancellationToken ct = default);
Task<WriteResult> CASetConfig(CAConfig config, WriteOptions q, CancellationToken ct = default);
Task<WriteResult> CASetConfig(CAConfig config, CancellationToken ct = default);
}
}
Loading