Skip to content

Commit

Permalink
Add support for Update CA Configuration and Test(#399) (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
larrytamnjong authored Dec 30, 2024
1 parent 6b0e582 commit bced1f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
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);
}
}

0 comments on commit bced1f4

Please sign in to comment.