From c2b8d5e64e5e59254580218ebec5ebdf4afe5bb8 Mon Sep 17 00:00:00 2001 From: tamnjongLarry Date: Mon, 25 Nov 2024 10:14:14 +0100 Subject: [PATCH] add interface and method to List CA Roots (#399) --- Consul/Connect.cs | 50 +++++++++++++++++++++++++++ Consul/Interfaces/IConnectEndpoint.cs | 4 +++ 2 files changed, 54 insertions(+) diff --git a/Consul/Connect.cs b/Consul/Connect.cs index b55f8bfa..81877b95 100644 --- a/Consul/Connect.cs +++ b/Consul/Connect.cs @@ -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 Roots { get; set; } + } + public class CARoot + { + /// + /// ID is a globally unique ID (UUID) representing this CA root. + /// + public string ID { get; set; } + /// + /// Name is a human-friendly name for this CA root. + /// This value is opaque to Consul and is not used for anything internally. + /// + public string Name { get; set; } + /// + /// RootCertPEM is the PEM-encoded public certificate. + /// + public string RootCertPEM { get; set; } + /// + /// 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. + /// + public bool Active { get; set; } + public ulong CreateIndex { get; set; } + public ulong ModifyIndex { get; set; } + } + public class Connect : IConnectEndpoint { private readonly ConsulClient _client; @@ -31,6 +66,21 @@ internal Connect(ConsulClient c) { _client = c; } + /// + /// CARoots queries the list of available roots. + /// + public Task> CARoots(CancellationToken ct = default) + { + return CARoots(QueryOptions.Default, ct); + } + /// + /// CARoots queries the list of available roots. + /// + public Task> CARoots(QueryOptions q, CancellationToken ct = default) + { + return _client.Get("/v1/connect/ca/roots", q).Execute(ct); + } + } public partial class ConsulClient : IConsulClient diff --git a/Consul/Interfaces/IConnectEndpoint.cs b/Consul/Interfaces/IConnectEndpoint.cs index 82211ae2..a5a03668 100644 --- a/Consul/Interfaces/IConnectEndpoint.cs +++ b/Consul/Interfaces/IConnectEndpoint.cs @@ -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> CARoots(QueryOptions q, CancellationToken ct = default); + Task> CARoots(CancellationToken ct = default); } }