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

[ODS-4459] Use .NET Feature Management library for API features #1205

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 @@ -5,20 +5,20 @@

using Autofac;
using EdFi.Ods.Api.IntegrationTestHarness.Migrations;
using EdFi.Ods.Common.Configuration;
using EdFi.Ods.Common.Constants;
using EdFi.Ods.Common.Container;
using Microsoft.FeatureManagement;

namespace EdFi.Ods.Api.IntegrationTestHarness.Modules;

public class MultiTenancyModule : ConditionalModule
{
public MultiTenancyModule(ApiSettings apiSettings)
: base(apiSettings, nameof(MultiTenancyModule)) { }
public MultiTenancyModule(IFeatureManager featureManager)
: base(featureManager) { }

public override bool IsSelected() => IsFeatureEnabled(ApiFeature.MultiTenancy);
protected override bool IsSelected() => IsFeatureEnabled(ApiFeature.MultiTenancy);

public override void ApplyConfigurationSpecificRegistrations(ContainerBuilder builder)
protected override void ApplyConfigurationSpecificRegistrations(ContainerBuilder builder)
{
builder.RegisterType<MultiTenantSecurityDatabaseConnectionStringCatalog>()
.As<ISecurityDatabaseConnectionStringCatalog>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

using Autofac;
using EdFi.Ods.Api.IntegrationTestHarness.Migrations;
using EdFi.Ods.Common.Configuration;
using EdFi.Ods.Common.Constants;
using EdFi.Ods.Common.Container;
using Microsoft.FeatureManagement;

namespace EdFi.Ods.Api.IntegrationTestHarness.Modules;

public class SingleTenancyModule : ConditionalModule
{
public SingleTenancyModule(ApiSettings apiSettings)
: base(apiSettings, nameof(SingleTenancyModule)) { }
public SingleTenancyModule(IFeatureManager featureManager)
: base(featureManager) { }

public override bool IsSelected() => !IsFeatureEnabled(ApiFeature.MultiTenancy);
protected override bool IsSelected() => !IsFeatureEnabled(ApiFeature.MultiTenancy);

public override void ApplyConfigurationSpecificRegistrations(ContainerBuilder builder)
protected override void ApplyConfigurationSpecificRegistrations(ContainerBuilder builder)
{
builder.RegisterType<SingleTenantSecurityDatabaseConnectionStringCatalog>()
.As<ISecurityDatabaseConnectionStringCatalog>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using EdFi.Admin.DataAccess.Models;
using EdFi.Admin.DataAccess.Repositories;
using EdFi.Admin.DataAccess.Utils;
using EdFi.Common.Configuration;
using EdFi.Common.Extensions;
using EdFi.Ods.Api.Middleware;
using EdFi.Ods.Api.Startup;
Expand All @@ -21,9 +22,11 @@
using EdFi.Ods.Common.Context;
using EdFi.Ods.Common.Conventions;
using EdFi.Ods.Common.Database;
using EdFi.Ods.Common.Extensions;
using EdFi.Ods.Common.Models;
using log4net;
using Microsoft.Extensions.Configuration;
using Microsoft.FeatureManagement;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Formatting = Newtonsoft.Json.Formatting;
Expand All @@ -37,7 +40,8 @@ public class UpdateAdminDatabaseStartupCommand : IStartupCommand
private readonly IClientAppRepo _clientAppRepo;
private readonly IDefaultApplicationCreator _defaultApplicationCreator;
private readonly IConfiguration _configuration;
private readonly ApiSettings _apiSettings;
private readonly IFeatureManager _featureManager;
private readonly DatabaseEngine _databaseEngine;
private readonly TestHarnessConfiguration _testHarnessConfiguration;
private readonly ITenantConfigurationMapProvider _tenantConfigurationMapProvider;
private readonly IContextProvider<TenantConfiguration> _tenantConfigurationContextProvider;
Expand All @@ -48,14 +52,16 @@ public class UpdateAdminDatabaseStartupCommand : IStartupCommand
public UpdateAdminDatabaseStartupCommand(IClientAppRepo clientAppRepo,
IDefaultApplicationCreator defaultApplicationCreator,
IConfiguration configuration,
ApiSettings apiSettings,
IFeatureManager featureManager,
DatabaseEngine databaseEngine,
TestHarnessConfigurationProvider testHarnessConfigurationProvider,
IDomainModelProvider domainModelProvider)
{
_clientAppRepo = clientAppRepo;
_defaultApplicationCreator = defaultApplicationCreator;
_configuration = configuration;
_apiSettings = apiSettings;
_featureManager = featureManager;
_databaseEngine = databaseEngine;
_testHarnessConfiguration = testHarnessConfigurationProvider.GetTestHarnessConfiguration();
_domainModelProvider = domainModelProvider;

Expand All @@ -76,12 +82,13 @@ public UpdateAdminDatabaseStartupCommand(IClientAppRepo clientAppRepo,
public UpdateAdminDatabaseStartupCommand(IClientAppRepo clientAppRepo,
IDefaultApplicationCreator defaultApplicationCreator,
IConfiguration configuration,
ApiSettings apiSettings,
IFeatureManager featureManager,
DatabaseEngine databaseEngine,
TestHarnessConfigurationProvider testHarnessConfigurationProvider,
IContextProvider<TenantConfiguration> tenantConfigurationContextProvider,
ITenantConfigurationMapProvider tenantConfigurationMapProvider,
IDomainModelProvider domainModelProvider)
: this (clientAppRepo, defaultApplicationCreator, configuration, apiSettings, testHarnessConfigurationProvider, domainModelProvider)
: this(clientAppRepo, defaultApplicationCreator, configuration, featureManager, databaseEngine, testHarnessConfigurationProvider, domainModelProvider)
{
_tenantConfigurationMapProvider = tenantConfigurationMapProvider;
_tenantConfigurationContextProvider = tenantConfigurationContextProvider;
Expand All @@ -91,7 +98,7 @@ public Task ExecuteAsync()
{
PostmanEnvironment postmanEnvironment;

if (!_apiSettings.IsFeatureEnabled(ApiFeature.MultiTenancy.GetConfigKeyName()))
if (!_featureManager.IsFeatureEnabled(ApiFeature.MultiTenancy))
{
_logger.Debug($"Loading test data in Admin Database.");
postmanEnvironment = UpdateAdminDatabase();
Expand Down Expand Up @@ -137,23 +144,23 @@ void CreateEnvironmentFile()
new ValueItem
{
Enabled = true,
Value = _apiSettings.IsFeatureEnabled(ApiFeature.Composites.ToString()),
Value = _featureManager.IsFeatureEnabled(ApiFeature.Composites),
Key = "CompositesFeatureIsEnabled"
});

postmanEnvironment.Values.Add(
new ValueItem
{
Enabled = true,
Value = _apiSettings.IsFeatureEnabled(ApiFeature.Profiles.ToString()),
Value = _featureManager.IsFeatureEnabled(ApiFeature.Profiles),
Key = "ProfilesFeatureIsEnabled"
});

postmanEnvironment.Values.Add(
new ValueItem
{
Enabled = true,
Value = _apiSettings.IsFeatureEnabled(ApiFeature.ChangeQueries.ToString()),
Value = _featureManager.IsFeatureEnabled(ApiFeature.ChangeQueries),
Key = "ChangeQueriesFeatureIsEnabled"
});

Expand Down Expand Up @@ -197,7 +204,7 @@ private PostmanEnvironment UpdateAdminDatabase(string tenantIdentifier = null)
string odsConnectionString = string.Format(_configuration.GetConnectionString("EdFi_Ods"), tenantIdentifier);

var dbConnectionStringBuilderAdapterFactory =
new DbConnectionStringBuilderAdapterFactory(_apiSettings.GetDatabaseEngine());
new DbConnectionStringBuilderAdapterFactory(_databaseEngine);

var connectionStringBuilderAdapter = dbConnectionStringBuilderAdapterFactory.Get();
connectionStringBuilderAdapter.ConnectionString = odsConnectionString;
Expand Down
73 changes: 17 additions & 56 deletions Application/EdFi.Ods.Api.IntegrationTestHarness/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,28 @@
"DefaultApplicationName": "Default Sandbox Application",
"DefaultClaimSetName": "Ed-Fi Sandbox",
"DefaultOperationalContextUri": "uri://ed-fi-api-host.org",
"FeatureManagement": {
"OpenApiMetadata": true,
"AggregateDependencies": true,
"TokenInfo": true,
"Extensions": true,
"Composites": true,
"Profiles": true,
"ChangeQueries": true,
"IdentityManagement": false,
"OwnershipBasedAuthorization": true,
"UniqueIdValidation": false,
"XsdMetadata": true,
"SerializedData": true,
"ResourceLinks": true
},
"ApiSettings": {
"Engine": "",
"EncryptSecrets": false,
"UseReverseProxyHeaders": false,
"BearerTokenTimeoutMinutes": "30",
"BearerTokenPerClientLimit": "-1",
"BearerTokenPerClientLimit": "-1",
"OdsTokens": [],
"Features": [
{
"Name": "OpenApiMetadata",
"IsEnabled": true
},
{
"Name": "AggregateDependencies",
"IsEnabled": true
},
{
"Name": "TokenInfo",
"IsEnabled": true
},
{
"Name": "Extensions",
"IsEnabled": true
},
{
"Name": "Composites",
"IsEnabled": true
},
{
"Name": "Profiles",
"IsEnabled": true
},
{
"Name": "ChangeQueries",
"IsEnabled": true
},
{
"Name": "IdentityManagement",
"IsEnabled": false
},
{
"Name": "OwnershipBasedAuthorization",
"IsEnabled": true
},
{
"Name": "UniqueIdValidation",
"IsEnabled": false
},
{
"Name": "XsdMetadata",
"IsEnabled": true
},
{
"Name": "SerializedData",
"IsEnabled": true
},
{
"Name": "ResourceLinks",
"IsEnabled": true
}
],
"ExcludedExtensions": [],
"Caching": {
"ExternalCacheProvider": "",
Expand Down Expand Up @@ -117,4 +78,4 @@
"Microsoft": "Warning"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
// See the LICENSE and NOTICES files in the project root for more information.

using Autofac;
using EdFi.Ods.Common.Configuration;
using EdFi.Ods.Common.Constants;
using EdFi.Ods.Common.Container;
using EdFi.Ods.Common.Infrastructure.Configuration;
using EdFi.Ods.Common.Repositories;
using EdFi.Ods.Features.OwnershipBasedAuthorization.NHibernate;
using EdFi.Ods.Features.OwnershipBasedAuthorization.Security;
using Microsoft.FeatureManagement;

namespace EdFi.Ods.Features.OwnershipBasedAuthorization.Container.Modules
{
public class OwnershipBasedAuthorizationModule : ConditionalModule
{
public OwnershipBasedAuthorizationModule(ApiSettings apiSettings)
: base(apiSettings, nameof(OwnershipBasedAuthorizationModule)) { }
public OwnershipBasedAuthorizationModule(IFeatureManager featureManager)
: base(featureManager) { }

public override bool IsSelected() => IsFeatureEnabled(ApiFeature.OwnershipBasedAuthorization);
protected override bool IsSelected() => IsFeatureEnabled(ApiFeature.OwnershipBasedAuthorization);

public override void ApplyConfigurationSpecificRegistrations(ContainerBuilder builder)
protected override void ApplyConfigurationSpecificRegistrations(ContainerBuilder builder)
{
builder.RegisterType<OwnershipBasedAuthorizationNHibernateConfigurationActivity>()
.As<INHibernateBeforeBindMappingActivity>();
Expand Down
79 changes: 17 additions & 62 deletions Application/EdFi.Ods.WebApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
"Tenants": {
},
"AllowedHosts": "*",
"FeatureManagement": {
"OpenApiMetadata": true,
"AggregateDependencies": true,
"TokenInfo": true,
"Extensions": true,
"Composites": true,
"Profiles": true,
"ChangeQueries": true,
"IdentityManagement": false,
"OwnershipBasedAuthorization": false,
"UniqueIdValidation": false,
"XsdMetadata": true,
"MultiTenancy": false,
"Notifications": false,
"SerializedData": true,
"ResourceLinks": true
},
"ApiSettings": {
"Engine": "SQLServer",
"UseReverseProxyHeaders": false,
Expand All @@ -32,68 +49,6 @@
"BearerTokenPerClientLimit": "15",
"DefaultPageSizeLimit": 500,
"LogRequestResponseContentForMinutes": 0,
"Features": [
{
"Name": "OpenApiMetadata",
"IsEnabled": true
},
{
"Name": "AggregateDependencies",
"IsEnabled": true
},
{
"Name": "TokenInfo",
"IsEnabled": true
},
{
"Name": "Extensions",
"IsEnabled": true
},
{
"Name": "Composites",
"IsEnabled": true
},
{
"Name": "Profiles",
"IsEnabled": true
},
{
"Name": "ChangeQueries",
"IsEnabled": true
},
{
"Name": "IdentityManagement",
"IsEnabled": false
},
{
"Name": "OwnershipBasedAuthorization",
"IsEnabled": false
},
{
"Name": "UniqueIdValidation",
"IsEnabled": false
},
{
"Name": "XsdMetadata",
"IsEnabled": true
},
{
"Name": "MultiTenancy",
"IsEnabled": false
},
{
"Name": "Notifications",
"IsEnabled": false
},
{
"Name": "SerializedData",
"IsEnabled": true
},
{
"Name": "ResourceLinks",
"IsEnabled": true
}
],
"ScheduledJobs": [
{
"Name": "DeleteExpiredTokens",
Expand Down
3 changes: 3 additions & 0 deletions Application/EdFi.Ods.WebApi/log4net.development.config
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<logger name="EdFi.Ods.Api.Security.Authorization.Repositories.EntityAuthorizer">
<level value="OFF"/>
</logger>
<logger name="EdFi.Ods.Common.Models.Graphs">
<level value="OFF"/>
</logger>
<root>
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="DebugAppender" />
Expand Down
Loading
Loading