From b2ec9f10008b5474dad4409629ec395290391269 Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Wed, 9 Jan 2019 16:01:11 +0100 Subject: [PATCH 1/3] add support for the get ssl certificates API --- .../ApiGenerator/ApiGenerator.cs | 1 - src/CodeGeneration/ApiGenerator/Program.cs | 2 +- .../RequestParameters.Generated.cs | 5 ++ .../ElasticLowLevelClient.Generated.cs | 8 +++ .../IElasticLowLevelClient.Generated.cs | 6 ++ src/Nest/Nest.csproj | 3 + .../ElasticClient-GetCertificates.cs | 71 +++++++++++++++++++ .../GetCertificates/GetCertificatesRequest.cs | 11 +++ .../GetCertificatesResponse.cs | 44 ++++++++++++ src/Nest/_Generated/_Descriptors.generated.cs | 8 +++ .../_Generated/_LowLevelDispatch.generated.cs | 20 ++++++ src/Nest/_Generated/_Requests.generated.cs | 12 ++++ .../GetCertificatesApiTests.cs | 46 ++++++++++++ .../GetCertificatesUrlTests.cs | 16 +++++ 14 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 src/Nest/XPack/Ssl/GetCertificates/ElasticClient-GetCertificates.cs create mode 100644 src/Nest/XPack/Ssl/GetCertificates/GetCertificatesRequest.cs create mode 100644 src/Nest/XPack/Ssl/GetCertificates/GetCertificatesResponse.cs create mode 100644 src/Tests/Tests/XPack/Ssl/GetCertificates/GetCertificatesApiTests.cs create mode 100644 src/Tests/Tests/XPack/Ssl/GetCertificates/GetCertificatesUrlTests.cs diff --git a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs index ff1ac824830..8187f13e88b 100644 --- a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs +++ b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs @@ -41,7 +41,6 @@ public class ApiGenerator "xpack.ml.get_calendar_job.json", "xpack.ml.delete_forecast.json", "xpack.ml.find_file_structure.json", - "xpack.ssl.certificates.json", "delete_by_query_rethrottle.json", "update_by_query_rethrottle.json", diff --git a/src/CodeGeneration/ApiGenerator/Program.cs b/src/CodeGeneration/ApiGenerator/Program.cs index 18793411d0a..25e65806591 100644 --- a/src/CodeGeneration/ApiGenerator/Program.cs +++ b/src/CodeGeneration/ApiGenerator/Program.cs @@ -40,7 +40,7 @@ private static void Main(string[] args) RestSpecDownloader.Download(downloadBranch); ApiGenerator.Generate(downloadBranch, "Core", "Graph", "License", "Security", "Watcher", "Info", "MachineLearning", "Migration", "Sql", - "Rollup"); + "Rollup", "Ssl"); } } } diff --git a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs index f817c5d596b..852c5feadbf 100644 --- a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs +++ b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs @@ -2624,6 +2624,11 @@ public partial class TranslateSqlRequestParameters : RequestParameters HttpMethod.POST; } + ///Request options for XpackSslCertificates
https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html
+ public partial class GetCertificatesRequestParameters : RequestParameters + { + public override HttpMethod DefaultHttpMethod => HttpMethod.GET; + } ///Request options for XpackWatcherAckWatch
http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-ack-watch.html
public partial class AcknowledgeWatchRequestParameters : RequestParameters { diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs index edbab257282..f742ab80ece 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.Generated.cs @@ -4002,6 +4002,14 @@ public TResponse XpackSqlTranslateGet(TranslateSqlRequestParameters r ///A func that allows you to describe the querystring parameters & request specific connection settings. public Task XpackSqlTranslateGetAsync(TranslateSqlRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync(GET, Url($"_xpack/sql/translate"), ctx, null, _params(requestParameters)); + ///GET on /_xpack/ssl/certificates https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html + ///A func that allows you to describe the querystring parameters & request specific connection settings. + public TResponse XpackSslCertificates(GetCertificatesRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new() => this.DoRequest(GET, Url($"_xpack/ssl/certificates"), null, _params(requestParameters)); + ///GET on /_xpack/ssl/certificates https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html + ///A func that allows you to describe the querystring parameters & request specific connection settings. + public Task XpackSslCertificatesAsync(GetCertificatesRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) + where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync(GET, Url($"_xpack/ssl/certificates"), ctx, null, _params(requestParameters)); ///PUT on /_xpack/watcher/watch/{watch_id}/_ack http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-ack-watch.html ///Watch ID ///A func that allows you to describe the querystring parameters & request specific connection settings. diff --git a/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs b/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs index f713a605222..a885d11b567 100644 --- a/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs +++ b/src/Elasticsearch.Net/IElasticLowLevelClient.Generated.cs @@ -3242,6 +3242,12 @@ public partial interface IElasticLowLevelClient ///GET on /_xpack/sql/translate Translate SQL into Elasticsearch queries ///A func that allows you to describe the querystring parameters & request specific connection settings. Task XpackSqlTranslateGetAsync(TranslateSqlRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new(); + ///GET on /_xpack/ssl/certificates https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html + ///A func that allows you to describe the querystring parameters & request specific connection settings. + TResponse XpackSslCertificates(GetCertificatesRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new(); + ///GET on /_xpack/ssl/certificates https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html + ///A func that allows you to describe the querystring parameters & request specific connection settings. + Task XpackSslCertificatesAsync(GetCertificatesRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new(); ///PUT on /_xpack/watcher/watch/{watch_id}/_ack http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-ack-watch.html ///Watch ID ///A func that allows you to describe the querystring parameters & request specific connection settings. diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index 19cf9bbd345..dc6efd51035 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -12,4 +12,7 @@ + + + \ No newline at end of file diff --git a/src/Nest/XPack/Ssl/GetCertificates/ElasticClient-GetCertificates.cs b/src/Nest/XPack/Ssl/GetCertificates/ElasticClient-GetCertificates.cs new file mode 100644 index 00000000000..0d3b9312e7c --- /dev/null +++ b/src/Nest/XPack/Ssl/GetCertificates/ElasticClient-GetCertificates.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Elasticsearch.Net; + +namespace Nest +{ + public partial interface IElasticClient + { + /// + /// The certificates API enables you to retrieve information about the X.509 certificates + /// that are used to encrypt communications in your Elasticsearch cluster. + /// + IGetCertificatesResponse GetCertificates(Func selector = null); + + /// + IGetCertificatesResponse GetCertificates(IGetCertificatesRequest request); + + /// + Task GetCertificatesAsync(Func selector = null, + CancellationToken cancellationToken = default + ); + + /// + Task GetCertificatesAsync(IGetCertificatesRequest request, + CancellationToken cancellationToken = default + ); + } + + public partial class ElasticClient + { + /// + public IGetCertificatesResponse GetCertificates(Func selector = null) => + GetCertificates(selector.InvokeOrDefault(new GetCertificatesDescriptor())); + + /// + public IGetCertificatesResponse GetCertificates(IGetCertificatesRequest request) => + Dispatcher.Dispatch( + request, + ToCertificatesResponse, + (p, d) => LowLevelDispatch.XpackSslCertificatesDispatch(p) + ); + + /// + public Task GetCertificatesAsync(Func selector = null, + CancellationToken cancellationToken = default + ) => + GetCertificatesAsync(selector.InvokeOrDefault(new GetCertificatesDescriptor()), cancellationToken); + + /// + public Task GetCertificatesAsync(IGetCertificatesRequest request, + CancellationToken cancellationToken = default + ) => + Dispatcher + .DispatchAsync( + request, + cancellationToken, + ToCertificatesResponse, + (p, d, c) => LowLevelDispatch.XpackSslCertificatesDispatchAsync(p, c) + ); + + private GetCertificatesResponse ToCertificatesResponse(IApiCallDetails apiCallDetails, Stream stream) + { + var result = RequestResponseSerializer.Deserialize(stream); + return new GetCertificatesResponse { Certificates = result }; + } + } +} diff --git a/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesRequest.cs b/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesRequest.cs new file mode 100644 index 00000000000..b745c86352b --- /dev/null +++ b/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesRequest.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; + +namespace Nest +{ + [MapsApi("xpack.ssl.certificates.json")] + public partial interface IGetCertificatesRequest { } + + public partial class GetCertificatesRequest { } + + public partial class GetCertificatesDescriptor { } +} diff --git a/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesResponse.cs b/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesResponse.cs new file mode 100644 index 00000000000..b07d8e54368 --- /dev/null +++ b/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesResponse.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Nest +{ + public interface IGetCertificatesResponse : IResponse + { + [JsonIgnore] + IReadOnlyCollection Certificates { get; } + + } + + public class GetCertificatesResponse : ResponseBase, IGetCertificatesResponse + { + public IReadOnlyCollection Certificates { get; internal set; } = + EmptyReadOnly.Collection; + } + + public class ClusterCertificateInformation + { + + [JsonProperty("path")] + public string Path { get; set; } + + [JsonProperty("alias")] + public string Alias { get; set; } + + [JsonProperty("format")] + public string Format { get; set; } + + [JsonProperty("subject_dn")] + public string SubjectDomainName { get; set; } + + [JsonProperty("serial_number")] + public string SerialNumber { get; set; } + + [JsonProperty("has_private_key")] + public bool HasPrivateKey { get; set; } + + [JsonProperty("expiry")] + public DateTimeOffset Expiry { get; set; } + } +} diff --git a/src/Nest/_Generated/_Descriptors.generated.cs b/src/Nest/_Generated/_Descriptors.generated.cs index 5a83ee5c75a..f02957f3c36 100644 --- a/src/Nest/_Generated/_Descriptors.generated.cs +++ b/src/Nest/_Generated/_Descriptors.generated.cs @@ -4746,6 +4746,14 @@ public partial class TranslateSqlDescriptor : RequestDescriptorBasedescriptor for XpackSslCertificates
https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html
+ public partial class GetCertificatesDescriptor : RequestDescriptorBase, IGetCertificatesRequest + { + // values part of the url path + + // Request parameters + } ///descriptor for XpackWatcherAckWatch
http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-ack-watch.html
public partial class AcknowledgeWatchDescriptor : RequestDescriptorBase, IAcknowledgeWatchRequest diff --git a/src/Nest/_Generated/_LowLevelDispatch.generated.cs b/src/Nest/_Generated/_LowLevelDispatch.generated.cs index 1f753c547e2..e46b0d7040a 100644 --- a/src/Nest/_Generated/_LowLevelDispatch.generated.cs +++ b/src/Nest/_Generated/_LowLevelDispatch.generated.cs @@ -4474,6 +4474,26 @@ internal partial class LowLevelDispatch throw InvalidDispatch("XpackSqlTranslate", p, new [] { POST, GET }, "/_xpack/sql/translate"); } + internal TResponse XpackSslCertificatesDispatch(IRequest p) where TResponse : class, IElasticsearchResponse, new() + { + switch(p.HttpMethod) + { + case GET: + return _lowLevel.XpackSslCertificates(p.RequestParameters); + } + throw InvalidDispatch("XpackSslCertificates", p, new [] { GET }, "/_xpack/ssl/certificates"); + } + + internal Task XpackSslCertificatesDispatchAsync(IRequest p, CancellationToken ct) where TResponse : class, IElasticsearchResponse, new() + { + switch(p.HttpMethod) + { + case GET: + return _lowLevel.XpackSslCertificatesAsync(p.RequestParameters,ct); + } + throw InvalidDispatch("XpackSslCertificates", p, new [] { GET }, "/_xpack/ssl/certificates"); + } + internal TResponse XpackWatcherAckWatchDispatch(IRequest p) where TResponse : class, IElasticsearchResponse, new() { switch(p.HttpMethod) diff --git a/src/Nest/_Generated/_Requests.generated.cs b/src/Nest/_Generated/_Requests.generated.cs index 1037d91cfc8..9102625bb40 100644 --- a/src/Nest/_Generated/_Requests.generated.cs +++ b/src/Nest/_Generated/_Requests.generated.cs @@ -2633,6 +2633,18 @@ public GetCategoriesRequest(Id job_id) : base(r=>r.Required("job_id", job_id)){} // Request parameters } [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public partial interface IGetCertificatesRequest : IRequest + { + } + ///Request parameters for XpackSslCertificates
https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html
+ public partial class GetCertificatesRequest : PlainRequestBase, IGetCertificatesRequest + { + protected IGetCertificatesRequest Self => this; + // values part of the url path + + // Request parameters + } + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] public partial interface IGetDatafeedsRequest : IRequest { Id DatafeedId { get; } diff --git a/src/Tests/Tests/XPack/Ssl/GetCertificates/GetCertificatesApiTests.cs b/src/Tests/Tests/XPack/Ssl/GetCertificates/GetCertificatesApiTests.cs new file mode 100644 index 00000000000..ce13bd91ac2 --- /dev/null +++ b/src/Tests/Tests/XPack/Ssl/GetCertificates/GetCertificatesApiTests.cs @@ -0,0 +1,46 @@ +using System; +using Elastic.Xunit.XunitPlumbing; +using Elasticsearch.Net; +using FluentAssertions; +using Nest; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Framework; +using Tests.Framework.Integration; + +namespace Tests.XPack.Ssl.GetCertificates +{ + [SkipVersion("<6.5.0", "")] + public class GetCertificatesApiTests + : ApiIntegrationTestBase + { + public GetCertificatesApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override bool ExpectIsValid => true; + protected override int ExpectStatusCode => 200; + protected override HttpMethod HttpMethod => HttpMethod.GET; + + protected override GetCertificatesRequest Initializer => new GetCertificatesRequest(); + + protected override string UrlPath => $"/_xpack/ssl/certificates"; + + protected override LazyResponses ClientUsage() => Calls( + (client, f) => client.GetCertificates(f), + (client, f) => client.GetCertificatesAsync(f), + (client, r) => client.GetCertificates(r), + (client, r) => client.GetCertificatesAsync(r) + ); + + protected override void ExpectResponse(IGetCertificatesResponse response) + { + response.Certificates.Should().NotBeEmpty(); + foreach (var c in response.Certificates) + { + c.Path.Should().NotBeNullOrWhiteSpace(); + c.Format.Should().NotBeNullOrWhiteSpace(); + c.SubjectDomainName.Should().NotBeNullOrWhiteSpace(); + c.SerialNumber.Should().NotBeNullOrWhiteSpace(); + c.Expiry.Should().BeAfter(DateTime.UtcNow.AddYears(-2)); + } + } + } +} diff --git a/src/Tests/Tests/XPack/Ssl/GetCertificates/GetCertificatesUrlTests.cs b/src/Tests/Tests/XPack/Ssl/GetCertificates/GetCertificatesUrlTests.cs new file mode 100644 index 00000000000..882a1f44dd6 --- /dev/null +++ b/src/Tests/Tests/XPack/Ssl/GetCertificates/GetCertificatesUrlTests.cs @@ -0,0 +1,16 @@ +using System.Threading.Tasks; +using Elastic.Xunit.XunitPlumbing; +using Nest; +using Tests.Framework; + +namespace Tests.XPack.Ssl.GetCertificates +{ + public class GetCertificatesUrlTests : UrlTestsBase + { + [U] public override async Task Urls() => await UrlTester.GET("/_xpack/ssl/certificates") + .Fluent(c => c.GetCertificates()) + .Request(c => c.GetCertificates(new GetCertificatesRequest())) + .FluentAsync(c => c.GetCertificatesAsync()) + .RequestAsync(c => c.GetCertificatesAsync(new GetCertificatesRequest())); + } +} From 9a9f8899ac67856ebe79926db4721a5dc43abd9e Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Fri, 25 Jan 2019 10:44:05 +0100 Subject: [PATCH 2/3] removed superfluous folder reference in Nest.csproj --- src/Nest/Nest.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index dc6efd51035..19cf9bbd345 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -12,7 +12,4 @@ - - - \ No newline at end of file From 9035874d066a94fd9dfe340453a00a1ed1e1a95b Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Fri, 25 Jan 2019 10:45:28 +0100 Subject: [PATCH 3/3] internal setters on GetCertificatesResponse --- .../Ssl/GetCertificates/GetCertificatesResponse.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesResponse.cs b/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesResponse.cs index b07d8e54368..b7a3197974b 100644 --- a/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesResponse.cs +++ b/src/Nest/XPack/Ssl/GetCertificates/GetCertificatesResponse.cs @@ -21,24 +21,24 @@ public class ClusterCertificateInformation { [JsonProperty("path")] - public string Path { get; set; } + public string Path { get; internal set; } [JsonProperty("alias")] - public string Alias { get; set; } + public string Alias { get; internal set; } [JsonProperty("format")] - public string Format { get; set; } + public string Format { get; internal set; } [JsonProperty("subject_dn")] - public string SubjectDomainName { get; set; } + public string SubjectDomainName { get; internal set; } [JsonProperty("serial_number")] - public string SerialNumber { get; set; } + public string SerialNumber { get; internal set; } [JsonProperty("has_private_key")] - public bool HasPrivateKey { get; set; } + public bool HasPrivateKey { get; internal set; } [JsonProperty("expiry")] - public DateTimeOffset Expiry { get; set; } + public DateTimeOffset Expiry { get; internal set; } } }