Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEST-362: Adding features guard configuration for Elasticsearch #44

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ public static class OrchardCoreBuilderExtensions
/// Binds Azure Storage as the conditional feature and Media as the condition feature to
/// <see cref="ConditionallyEnabledFeaturesOptions"/>.
/// </summary>
public static OrchardCoreBuilder ConfigureFeaturesGuardForAzureStorage(this OrchardCoreBuilder builder)
{
builder.ConfigureServices((tenantServices, _) =>
tenantServices.PostConfigure<ConditionallyEnabledFeaturesOptions>(options =>
options.EnableFeatureIfOtherFeatureIsEnabled = new Dictionary<string, IEnumerable<string>>
{
["OrchardCore.Media.Azure.Storage"] = new List<string> { "OrchardCore.Media" },
}));
public static OrchardCoreBuilder ConfigureFeaturesGuardForAzureStorage(this OrchardCoreBuilder builder) =>
builder.ConfigureFeaturesGuardWithoutOverriding(
new Dictionary<string, IEnumerable<string>>
{
["OrchardCore.Media.Azure.Storage"] = new List<string> { "OrchardCore.Media" },
});

return builder;
}
/// <summary>
/// Binds Elasticsearch as the conditional feature and Search or Indexing as the condition feature to
/// <see cref="ConditionallyEnabledFeaturesOptions"/>.
/// </summary>
public static OrchardCoreBuilder ConfigureFeaturesGuardForElasticsearch(this OrchardCoreBuilder builder) =>
builder.ConfigureFeaturesGuardWithoutOverriding(
new Dictionary<string, IEnumerable<string>>
{
["OrchardCore.Search.Elasticsearch"] =
new List<string> { "OrchardCore.Search", "OrchardCore.Indexing" },
});

/// <summary>
/// Binds the provided dictionary's keys and values as the conditional and condition features to
Expand All @@ -34,4 +41,25 @@ public static OrchardCoreBuilder ConfigureFeaturesGuard(

return builder;
}

public static OrchardCoreBuilder ConfigureFeaturesGuardWithoutOverriding(
this OrchardCoreBuilder builder,
IDictionary<string, IEnumerable<string>> configDictionary)
{
builder.ConfigureServices((tenantServices, _) =>
tenantServices.PostConfigure<ConditionallyEnabledFeaturesOptions>(options =>
{
if (options.EnableFeatureIfOtherFeatureIsEnabled == null)
{
options.EnableFeatureIfOtherFeatureIsEnabled = configDictionary;
}
else
{
options.EnableFeatureIfOtherFeatureIsEnabled
.AddRange(configDictionary);
}
}));

return builder;
}
}
5 changes: 3 additions & 2 deletions Lombiq.Hosting.Tenants.FeaturesGuard/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A module that makes it possible to conditionally enable and conditionally keep e
### Conditionally enabling features

- To use this feature, enable it on both the Default and the user tenant.
- Features that should be conditionally enabled, as well as the features whose status acts as the condition, can be specified either in _appsettings.json_ using `ConditionallyEnabledFeaturesOptions` or in `Program` via the `ConfigureFeaturesGuard()` extension method.
- Features that should be conditionally enabled, as well as the features whose status acts as the condition, can be specified either in _appsettings.json_ using `ConditionallyEnabledFeaturesOptions` or in `Program` via the `ConfigureFeaturesGuard()` or `ConfigureFeaturesGuardWithoutOverriding()` extension method.
Conditionally enabled features need to be provided with a singular or multiple condition features, where the status of the condition features determines whether the corresponding conditional feature is enabled or disabled. Example configuration:

`Program` config example:
Expand All @@ -27,7 +27,8 @@ builder.Services
}));
```

- `ConfigureFeaturesGuardForAzureStorage()` is also available to add `Azure Storage` as a conditional feature and `Media` as its condition feature.
- `ConfigureFeaturesGuardForAzureStorage()` is available to add `Azure Storage` as a conditional feature and `Media` as its condition feature.
- `ConfigureFeaturesGuardForElasticsearch()` is available to add `Elasticsearch` as a conditional feature and `Indexing` or `Search` as its condition feature.

_appsettings.json_ config example:
```json
Expand Down