Skip to content

[ODS-6615] API only allows tenant1's profiles when different profiles are set up for different tenants #1221

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

Merged
merged 3 commits into from
Jan 30, 2025
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 @@ -23,6 +23,14 @@
<None Update="AdminCredential.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="..\..\..\Ed-Fi-ODS\Application\EdFi.Ods.Profiles.Test\ProfilesTenant1.xml">
<Link>ProfilesTenant1.xml</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\..\Ed-Fi-ODS\Application\EdFi.Ods.Profiles.Test\ProfilesTenant2.xml">
<Link>ProfilesTenant2.xml</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\Plugin\**" LinkBase="Plugin\" Exclude="..\..\Plugin\*.ps1;..\..\Plugin\**\*.nupkg" CopyToPublishDirectory="Always" CopyToOutputDirectory="Never" />
<Content Include="..\..\..\Ed-Fi-ODS\Application\EdFi.Ods.Profiles.Test\Profiles.xml" CopyToPublishDirectory="Always" CopyToOutputDirectory="Always" />
<Content Include="..\..\..\Ed-Fi-ODS\Application\EdFi.Ods.Profiles.Test\InvalidProfiles.xml" CopyToPublishDirectory="Always" CopyToOutputDirectory="Always" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

namespace EdFi.Ods.Api.IntegrationTestHarness.Migrations;

/// <summary>
/// Defines a method for obtaining connection strings for all the EdFi_Security databases available in the deployment environment.
/// </summary>
public interface ISecurityDatabaseConnectionStringCatalog
{
/// <summary>
/// Gets the connection strings for all the EdFi_Security databases available in the deployment environment.
/// </summary>
/// <returns>The connection strings for EdFi_Security databases.</returns>
string[] GetConnectionStrings();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System.Collections.Generic;
using EdFi.Ods.Api.Middleware;
using EdFi.Ods.Common.Configuration;
using EdFi.Ods.Common.Context;
using EdFi.Security.DataAccess.Providers;

namespace EdFi.Ods.Api.IntegrationTestHarness.Migrations;

/// <summary>
/// Implements an <see cref="ISecurityDatabaseConnectionStringCatalog" /> that returns a connection string
/// for each of the tenant-specific EdFi_Security databases in a multitenant deployment.
/// </summary>
public class MultiTenantSecurityDatabaseConnectionStringCatalog : ISecurityDatabaseConnectionStringCatalog
{
private readonly ISecurityDatabaseConnectionStringProvider _securityConnectionStringProvider;
private readonly IContextProvider<TenantConfiguration> _tenantConfigurationContextProvider;
private readonly ITenantConfigurationMapProvider _tenantConfigurationMapProvider;

public MultiTenantSecurityDatabaseConnectionStringCatalog(
ISecurityDatabaseConnectionStringProvider securityConnectionStringProvider,
ITenantConfigurationMapProvider tenantConfigurationMapProvider,
IContextProvider<TenantConfiguration> tenantConfigurationContextProvider)
{
_securityConnectionStringProvider = securityConnectionStringProvider;
_tenantConfigurationMapProvider = tenantConfigurationMapProvider;
_tenantConfigurationContextProvider = tenantConfigurationContextProvider;
}

/// <summary>
/// Gets a connection string for each of the tenant-specific EdFi_Security databases in a multitenant deployment.
/// </summary>
/// <returns></returns>
public string[] GetConnectionStrings()
{
List<string> connectionStrings = new();

foreach (var tenantConfigurationMap in _tenantConfigurationMapProvider.GetMap())
{
_tenantConfigurationContextProvider.Set(tenantConfigurationMap.Value);
connectionStrings.Add(_securityConnectionStringProvider.GetConnectionString());
_tenantConfigurationContextProvider.Set(null);
}

return connectionStrings.ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Formatting = Newtonsoft.Json.Formatting;
using TenantConfiguration = EdFi.Ods.Api.Middleware.TenantConfiguration;
using TenantConfiguration = EdFi.Ods.Common.Configuration.TenantConfiguration;

namespace EdFi.Ods.Api.IntegrationTestHarness
{
Expand Down Expand Up @@ -201,8 +201,13 @@ private PostmanEnvironment UpdateAdminDatabase(string tenantIdentifier = null)
});

// Add Profiles
var profileFilenames = Directory.GetFiles(Directory.GetParent(AppContext.BaseDirectory).FullName, "*Profiles.xml");
string[] profileFilenames = Directory.GetFiles(Directory.GetParent(AppContext.BaseDirectory).FullName, $"*Profiles.xml");

if(!string.IsNullOrEmpty(tenantIdentifier))
{
profileFilenames = profileFilenames.Union(Directory.GetFiles(Directory.GetParent(AppContext.BaseDirectory).FullName, $"*Profiles{tenantIdentifier}.xml")).ToArray();
}

var profileDefinitionByName = new Dictionary<string, XmlNode>(StringComparer.OrdinalIgnoreCase);

foreach (var profileFilename in profileFilenames)
Expand Down
Loading