Skip to content

Commit

Permalink
Upgrading elasticsearch to use the new client Elastic.Clients.Elastic…
Browse files Browse the repository at this point in the history
…search instead of deprecated NEST client (#682)
  • Loading branch information
thepirat000 committed Jul 19, 2024
1 parent e7026b3 commit 212d4e9
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 278 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to Audit.NET and its extensions will be documented in this f

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [26.0.0] - 2024-07-19:
- Audit.NET.Elasticsearch: Upgrading the elasticsearch data provider to use the new client Elastic.Clients.Elasticsearch instead of the deprecated NEST client. [Migration guide](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/migration-guide.html) (#682)

## [25.0.7] - 2024-07-04:
- Audit.HttpClient: Allowing to audit the HttpRequestMessage.Options to add contextual information to the HTTP Audit Event.
Adding GetRequestMessage() and GetResponseMessage() to the HttpAction to be able to retrieve the HttpRequestMessage and HttpResponseMessage objects from the audit event. (#673)
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>25.0.7</Version>
<Version>26.0.0</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
Expand Down
76 changes: 38 additions & 38 deletions src/Audit.NET.ElasticSearch/Audit.NET.Elasticsearch.csproj
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Description>Store Audit.NET Trail Logs into Elasticsearch database</Description>
<Copyright>Copyright 2018</Copyright>
<AssemblyTitle>Audit.Elasticsearch</AssemblyTitle>
<Authors>Federico Colombo</Authors>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);STRONG_NAME</DefineConstants>
<NoWarn>$(NoWarn);1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Audit.NET.Elasticsearch</AssemblyName>
<AssemblyOriginatorKeyFile>../StrongName/Audit.NET.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>Audit.NET.Elasticsearch</PackageId>
<PackageTags>Audit;Trail;Log;Elasticsearch</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/thepirat000/Audit.NET</PackageProjectUrl>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/thepirat000/Audit.NET</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<PropertyGroup>
<Description>Store Audit.NET Trail Logs into Elasticsearch database</Description>
<Copyright>Copyright 2018</Copyright>
<AssemblyTitle>Audit.Elasticsearch</AssemblyTitle>
<Authors>Federico Colombo</Authors>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);STRONG_NAME</DefineConstants>
<NoWarn>$(NoWarn);1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Audit.NET.Elasticsearch</AssemblyName>
<AssemblyOriginatorKeyFile>../StrongName/Audit.NET.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>Audit.NET.Elasticsearch</PackageId>
<PackageTags>Audit;Trail;Log;Elasticsearch</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/thepirat000/Audit.NET</PackageProjectUrl>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/thepirat000/Audit.NET</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath="LICENSE" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" PackagePath="LICENSE" />
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="NEST" Version="7.17.5" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.14.6" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Audit.NET\Audit.NET.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="images\icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Audit.NET\Audit.NET.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="images\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,11 @@
using Audit.Core.ConfigurationApi;
using Audit.Elasticsearch.Configuration;
using Audit.Elasticsearch.Providers;
using Nest;

namespace Audit.Core
{
public static class ElasticsearchConfiguratorExtensions
{
/// <summary>
/// Store the events in Elasticsearch indexes.
/// </summary>
/// <param name="configurator">The Audit.NET configurator object</param>
/// <param name="settings">The Elasticsearch connection settings</param>
/// <param name="idBuilder">The builder to get the id to use for an audit event. NULL to use a server generated id</param>
/// <param name="indexBuilder">The builder to get the index to use for an audit event. NULL to use the default index name</param>
public static ICreationPolicyConfigurator UseElasticsearch(this IConfigurator configurator, IConnectionSettingsValues settings,
Func<AuditEvent, Id> idBuilder = null, Func<AuditEvent, IndexName> indexBuilder = null)
{
Configuration.DataProvider = new ElasticsearchDataProvider()
{
ConnectionSettings = settings,
IdBuilder = idBuilder,
Index = indexBuilder
};
return new CreationPolicyConfigurator();
}

/// <summary>
/// Store the events in Elasticsearch indexes.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
using System;
using Audit.Core;
using Elasticsearch.Net;
using Nest;
using Elastic.Clients.Elasticsearch;

namespace Audit.Elasticsearch.Configuration
{
public class ElasticsearchProviderConfigurator : IElasticsearchProviderConfigurator
{
internal IConnectionSettingsValues _connectionSettings;
internal IElasticsearchClientSettings _clientSettings;
internal Setting<IndexName> _index;
internal Func<Core.AuditEvent, Id> _idBuilder;
internal ElasticsearchClient _client;

public IElasticsearchProviderConfigurator ConnectionSettings(IConnectionSettingsValues connectionSettings)
public IElasticsearchProviderConfigurator Client(ElasticsearchClient client)
{
_connectionSettings = connectionSettings;
_client = client;
_clientSettings = null;
return this;
}

public IElasticsearchProviderConfigurator ConnectionSettings(Uri uri)
public IElasticsearchProviderConfigurator Client(IElasticsearchClientSettings clientSettings)
{
_connectionSettings = new ConnectionSettings(uri);
_clientSettings = clientSettings;
_client = null;
return this;
}

public IElasticsearchProviderConfigurator ConnectionSettings(IConnectionPool connectionPool)
public IElasticsearchProviderConfigurator Client(Uri uri)
{
_connectionSettings = new ConnectionSettings(connectionPool);
_clientSettings = new ElasticsearchClientSettings(uri);
_client = null;
return this;
}

public IElasticsearchProviderConfigurator ConnectionSettings(IConnectionPool connectionPool, IConnection connection)
{
_connectionSettings = new ConnectionSettings(connectionPool, connection);
return this;
}


public IElasticsearchProviderConfigurator Id(Func<Core.AuditEvent, Id> idBuilder)
{
_idBuilder = idBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Audit.Core;
using Elastic = Elasticsearch.Net;
using Nest;
using Elastic.Clients.Elasticsearch;

namespace Audit.Elasticsearch.Configuration
{
Expand All @@ -11,29 +10,22 @@ namespace Audit.Elasticsearch.Configuration
public interface IElasticsearchProviderConfigurator
{
/// <summary>
/// Specifies the Elasticsearch connection settings.
/// Specifies the Elasticsearch client settings.
/// </summary>
/// <param name="connectionSettings">The elasticsearch connection settings.</param>
IElasticsearchProviderConfigurator ConnectionSettings(IConnectionSettingsValues connectionSettings);
/// <param name="clientSettings">The elasticsearch client settings.</param>
IElasticsearchProviderConfigurator Client(IElasticsearchClientSettings clientSettings);

/// <summary>
/// Specifies the Elasticsearch connection settings by providing the single node URL.
/// Specifies the Elasticsearch client to use.
/// </summary>
/// <param name="uri">The elasticsearch single node URL.</param>
IElasticsearchProviderConfigurator ConnectionSettings(Uri uri);
/// <param name="client">The elasticsearch client to use.</param>
IElasticsearchProviderConfigurator Client(ElasticsearchClient client);

/// <summary>
/// Specifies the Elasticsearch connection settings by providing the connection pool.
/// Specifies the Elasticsearch client settings by providing a single node URL.
/// </summary>
/// <param name="connectionPool">The connection pool to use.</param>
IElasticsearchProviderConfigurator ConnectionSettings(Elastic.IConnectionPool connectionPool);

/// <summary>
/// Specifies the Elasticsearch connection settings by providing the connection pool and the connection.
/// </summary>
/// <param name="connectionPool">The connection pool to use.</param>
/// <param name="connection">The connection to use.</param>
IElasticsearchProviderConfigurator ConnectionSettings(Elastic.IConnectionPool connectionPool, Elastic.IConnection connection);
/// <param name="uri">The elasticsearch single node URL.</param>
IElasticsearchProviderConfigurator Client(Uri uri);

/// <summary>
/// Specifies the Elasticsearch Index name to use.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Nest;
using Elastic.Clients.Elasticsearch;

namespace Audit.Elasticsearch.Providers
{
Expand Down
Loading

0 comments on commit 212d4e9

Please sign in to comment.