|
|
|
@ -1,28 +1,53 @@
|
|
|
|
|
namespace Volo.Docs.Documents.FullSearch.Elastic
|
|
|
|
|
using System;
|
|
|
|
|
using Nest;
|
|
|
|
|
using Volo.Abp;
|
|
|
|
|
|
|
|
|
|
namespace Volo.Docs.Documents.FullSearch.Elastic
|
|
|
|
|
{
|
|
|
|
|
public class DocsElasticSearchOptions
|
|
|
|
|
{
|
|
|
|
|
public bool Enable { get; set; }
|
|
|
|
|
|
|
|
|
|
public string IndexName { get; set; }
|
|
|
|
|
|
|
|
|
|
protected Action<ConnectionSettings> AuthenticationAction { get; set; }
|
|
|
|
|
|
|
|
|
|
public DocsElasticSearchOptions()
|
|
|
|
|
{
|
|
|
|
|
Enable = false;
|
|
|
|
|
IndexName = "abp_documents";
|
|
|
|
|
AuthenticationMode = ElasticSearchAuthenticationMode.None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Enable { get; set; }
|
|
|
|
|
public DocsElasticSearchOptions UseBasicAuthentication(string username, string password)
|
|
|
|
|
{
|
|
|
|
|
Check.NotNullOrEmpty(username, nameof(username));
|
|
|
|
|
Check.NotNullOrEmpty(password, nameof(password));
|
|
|
|
|
|
|
|
|
|
public string IndexName { get; set; }
|
|
|
|
|
AuthenticationAction = settings =>
|
|
|
|
|
{
|
|
|
|
|
settings.BasicAuthentication(username, password);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public ElasticSearchAuthenticationMode AuthenticationMode { get; set; }
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DocsElasticSearchBasicAuthenticationOptions BasicAuthentication { get; set; }
|
|
|
|
|
public DocsElasticSearchApiKeyAuthenticationOptions ApiKeyAuthentication { get; set; }
|
|
|
|
|
public DocsElasticSearchOptions UseApiKeyAuthentication(string id, string apiKey)
|
|
|
|
|
{
|
|
|
|
|
Check.NotNullOrEmpty(id, nameof(id));
|
|
|
|
|
Check.NotNullOrEmpty(apiKey, nameof(apiKey));
|
|
|
|
|
|
|
|
|
|
AuthenticationAction = settings =>
|
|
|
|
|
{
|
|
|
|
|
settings.ApiKeyAuthentication(id, apiKey);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ElasticSearchAuthenticationMode
|
|
|
|
|
public ConnectionSettings Authenticate(ConnectionSettings connectionSettings)
|
|
|
|
|
{
|
|
|
|
|
None = 0,
|
|
|
|
|
Basic = 1,
|
|
|
|
|
ApiKey = 2
|
|
|
|
|
AuthenticationAction?.Invoke(connectionSettings);
|
|
|
|
|
return connectionSettings;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|