Skip to content
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
6 changes: 5 additions & 1 deletion src/Service.Tests/Configuration/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ConfigurationTests
private const string POST_STARTUP_CONFIG_ENTITY = "Book";
private const string POST_STARTUP_CONFIG_ENTITY_SOURCE = "books";
private const string POST_STARTUP_CONFIG_ROLE = "PostStartupConfigRole";
private const string COSMOS_DATABASE_NAME = "config_db";
private const int RETRY_COUNT = 5;
private const int RETRY_WAIT_SECONDS = 1;

Expand Down Expand Up @@ -429,6 +430,8 @@ public async Task TestSettingConfigurationCreatesCorrectClasses()
Assert.AreEqual(DatabaseType.cosmos, configuration.DatabaseType, "Expected cosmos database type after configuring the runtime with cosmos settings.");
Assert.AreEqual(config.Schema, configuration.DataSource.CosmosDbNoSql.GraphQLSchema, "Expected the schema in the configuration to match the one sent to the configuration endpoint.");
Assert.AreEqual(config.ConnectionString, configuration.ConnectionString, "Expected the connection string in the configuration to match the one sent to the configuration endpoint.");
string db = configProvider.GetRuntimeConfiguration().DataSource.CosmosDbNoSql.Database;
Assert.AreEqual(COSMOS_DATABASE_NAME, db, "Expected the database name in the runtime config to match the one sent to the configuration endpoint.");
}

[TestMethod("Validates that an exception is thrown if there's a null model in filter parser.")]
Expand Down Expand Up @@ -975,7 +978,8 @@ private static ConfigurationPostParameters GetCosmosConfigurationParameters()
File.ReadAllText(cosmosFile),
File.ReadAllText("schema.gql"),
"AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
AccessToken: null);
AccessToken: null,
Database: COSMOS_DATABASE_NAME);
}

/// <summary>
Expand Down
10 changes: 9 additions & 1 deletion src/Service/Configurations/RuntimeConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ public static bool LoadRuntimeConfigValue(
/// <param name="schema">The GraphQL Schema. Can be left null for SQL configurations.</param>
/// <param name="connectionString">The connection string to the database.</param>
/// <param name="accessToken">The string representation of a managed identity access token
/// <param name="Database"> The name of the database to be used for Cosmos</param>
/// useful to connect to the database.</param>
public void Initialize(
string configuration,
string? schema,
string connectionString,
string? accessToken)
string? accessToken,
string? database = null)
{
if (string.IsNullOrEmpty(connectionString))
{
Expand Down Expand Up @@ -247,6 +249,12 @@ public void Initialize(
}

CosmosDbOptions? cosmosDb = RuntimeConfiguration.DataSource.CosmosDbNoSql! with { GraphQLSchema = schema };

if (!string.IsNullOrEmpty(database))
{
cosmosDb = cosmosDb with { Database = database };
}

DataSource dataSource = RuntimeConfiguration.DataSource with { CosmosDbNoSql = cosmosDb };
RuntimeConfiguration = RuntimeConfiguration with { DataSource = dataSource };
}
Expand Down
7 changes: 5 additions & 2 deletions src/Service/Controllers/ConfigurationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public ActionResult Index([FromBody] ConfigurationPostParameters configuration)
configuration.Configuration,
configuration.Schema,
configuration.ConnectionString,
configuration.AccessToken);
configuration.AccessToken,
configuration.Database);

return new OkResult();
}
Expand All @@ -45,10 +46,12 @@ public ActionResult Index([FromBody] ConfigurationPostParameters configuration)
/// <param name="Schema">The GraphQL schema. Can be left empty for SQL databases.</param>
/// <param name="ConnectionString">The database connection string.</param>
/// <param name="AccessToken">The managed identity access token (if any) used to connect to the database.</param>
/// <param name="Database"> The name of the database to be used for Cosmos</param>
public record class ConfigurationPostParameters(
string Configuration,
string? Schema,
string ConnectionString,
string? AccessToken)
string? AccessToken,
string? Database = null)
{ }
}