forked from elsa-workflows/elsa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
80 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/modules/Elsa.Elasticsearch/Extensions/ConnectionSettingsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Elasticsearch.Net; | ||
using Elsa.Elasticsearch.Options; | ||
using Elsa.Elasticsearch.Services; | ||
using Nest; | ||
|
||
namespace Elsa.Elasticsearch.Extensions; | ||
|
||
public static class ConnectionSettingsExtensions | ||
{ | ||
public static ConnectionSettings ConfigureAuthentication(this ConnectionSettings settings, ElasticsearchOptions options) | ||
{ | ||
if (!string.IsNullOrEmpty(options.ApiKey)) | ||
{ | ||
settings.ApiKeyAuthentication(new ApiKeyAuthenticationCredentials(options.ApiKey)); | ||
} | ||
else if (!string.IsNullOrEmpty(options.Username) && !string.IsNullOrEmpty(options.Password)) | ||
{ | ||
settings.BasicAuthentication(options.Username, options.Password); | ||
} | ||
|
||
return settings; | ||
} | ||
|
||
public static ConnectionSettings ConfigureMapping(this ConnectionSettings settings) | ||
{ | ||
var configs = AppDomain.CurrentDomain.GetAssemblies() | ||
.SelectMany(s => s.GetTypes()) | ||
.Where(p => typeof(IElasticConfiguration).IsAssignableFrom(p) && p.IsClass); | ||
|
||
foreach (var config in configs) | ||
{ | ||
var configInstance = (IElasticConfiguration)Activator.CreateInstance(config)!; | ||
configInstance.Apply(settings); | ||
} | ||
|
||
return settings; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/modules/Elsa.Elasticsearch/Modules/Management/WorkflowInstanceConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Elsa.Elasticsearch.Options; | ||
using Elsa.Elasticsearch.Services; | ||
using Elsa.Workflows.Management.Entities; | ||
using Nest; | ||
|
||
namespace Elsa.Elasticsearch.Modules.Management; | ||
|
||
public class WorkflowInstanceConfiguration : IElasticConfiguration | ||
{ | ||
public void Apply(ConnectionSettings connectionSettings) | ||
{ | ||
connectionSettings.DefaultMappingFor<WorkflowInstance>(m => | ||
m.IndexName(ElasticsearchOptions.Indices[typeof(WorkflowInstance)])); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/modules/Elsa.Elasticsearch/Modules/Runtime/ExecutionLogConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Elsa.Elasticsearch.Options; | ||
using Elsa.Elasticsearch.Services; | ||
using Elsa.Workflows.Runtime.Entities; | ||
using Nest; | ||
|
||
namespace Elsa.Elasticsearch.Modules.Runtime; | ||
|
||
public class ExecutionLogConfiguration : IElasticConfiguration | ||
{ | ||
public void Apply(ConnectionSettings connectionSettings) | ||
{ | ||
connectionSettings.DefaultMappingFor<WorkflowExecutionLogRecord>(m => | ||
m.IndexName(ElasticsearchOptions.Indices[typeof(WorkflowExecutionLogRecord)])); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/modules/Elsa.Elasticsearch/Services/IElasticConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Nest; | ||
|
||
namespace Elsa.Elasticsearch.Services; | ||
|
||
public interface IElasticConfiguration | ||
{ | ||
void Apply(ConnectionSettings connectionSettings); | ||
} |