Skip to content

Commit

Permalink
add interface and method to List CA Roots (G-Research#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
larrytamnjong committed Nov 25, 2024
1 parent a327db8 commit c2b8d5e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Consul/Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,45 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Consul.Interfaces;

namespace Consul
{
public class CARootList
{
public string ActiveRootID { get; set; }
public string TrustDomain { get; set; }
public List<CARoot> Roots { get; set; }
}
public class CARoot
{
/// <summary>
/// ID is a globally unique ID (UUID) representing this CA root.
/// </summary>
public string ID { get; set; }
/// <summary>
/// Name is a human-friendly name for this CA root.
/// This value is opaque to Consul and is not used for anything internally.
/// </summary>
public string Name { get; set; }
/// <summary>
/// RootCertPEM is the PEM-encoded public certificate.
/// </summary>
public string RootCertPEM { get; set; }
/// <summary>
/// Active is true if this is the current active CA. This must only
/// be true for exactly one CA. For any method that modifies roots in the
/// state store, tests should be written to verify that multiple roots
/// cannot be active.
/// </summary>
public bool Active { get; set; }
public ulong CreateIndex { get; set; }
public ulong ModifyIndex { get; set; }
}

public class Connect : IConnectEndpoint
{
private readonly ConsulClient _client;
Expand All @@ -31,6 +66,21 @@ internal Connect(ConsulClient c)
{
_client = c;
}
/// <summary>
/// CARoots queries the list of available roots.
/// </summary>
public Task<QueryResult<CARootList>> CARoots(CancellationToken ct = default)
{
return CARoots(QueryOptions.Default, ct);
}
/// <summary>
/// CARoots queries the list of available roots.
/// </summary>
public Task<QueryResult<CARootList>> CARoots(QueryOptions q, CancellationToken ct = default)
{
return _client.Get<CARootList>("/v1/connect/ca/roots", q).Execute(ct);
}

}

public partial class ConsulClient : IConsulClient
Expand Down
4 changes: 4 additions & 0 deletions Consul/Interfaces/IConnectEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Consul.Interfaces
{
public interface IConnectEndpoint
{
Task<QueryResult<CARootList>> CARoots(QueryOptions q, CancellationToken ct = default);
Task<QueryResult<CARootList>> CARoots(CancellationToken ct = default);
}
}

0 comments on commit c2b8d5e

Please sign in to comment.