|
|
|
@ -21,7 +21,25 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
|
|
|
|
|
{
|
|
|
|
|
var node = new Uri(Configuration["ElasticSearch:Url"]);
|
|
|
|
|
var settings = new ConnectionSettings(node).DefaultIndex(Options.IndexName);
|
|
|
|
|
|
|
|
|
|
Authenticate(settings);
|
|
|
|
|
|
|
|
|
|
return new ElasticClient(settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Authenticate(ConnectionSettings connectionSettings)
|
|
|
|
|
{
|
|
|
|
|
switch (Options.AuthenticationMode)
|
|
|
|
|
{
|
|
|
|
|
case DocsElasticSearchOptions.ElasticSearchAuthenticationMode.Basic:
|
|
|
|
|
var basicAuth = Options.BasicAuthentication;
|
|
|
|
|
connectionSettings.BasicAuthentication(basicAuth.Username, basicAuth.Password);
|
|
|
|
|
break;
|
|
|
|
|
case DocsElasticSearchOptions.ElasticSearchAuthenticationMode.ApiKey:
|
|
|
|
|
var apiKeyAuth = Options.ApiKeyAuthentication;
|
|
|
|
|
connectionSettings.BasicAuthentication(apiKeyAuth.Id, apiKeyAuth.ApiKey);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|