diff --git a/src/Azure.DataApiBuilder.sln b/src/Azure.DataApiBuilder.sln index 68f776ad92..68453fd2f5 100644 --- a/src/Azure.DataApiBuilder.sln +++ b/src/Azure.DataApiBuilder.sln @@ -8,16 +8,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.DataApiBuilder.Servic EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Configs", "Configs", "{EFA9C661-D8FD-469A-9372-284387C4BEFC}" ProjectSection(SolutionItems) = preProject - Service\dab-config.Cosmos.json = Service\dab-config.Cosmos.json - Service\dab-config.Cosmos.overrides.example.json = Service\dab-config.Cosmos.overrides.example.json - Service\dab-config.json = Service\dab-config.json - Service\dab-config.MsSql.json = Service\dab-config.MsSql.json - Service\dab-config.MsSql.overrides.example.json = Service\dab-config.MsSql.overrides.example.json - Service\dab-config.MySql.json = Service\dab-config.MySql.json - Service\dab-config.MySql.overrides.example.json = Service\dab-config.MySql.overrides.example.json - Service\dab-config.PostgreSql.json = Service\dab-config.PostgreSql.json - Service\dab-config.PostgreSql.overrides.example.json = Service\dab-config.PostgreSql.overrides.example.json - schemas\dab.draft-01.schema.json = schemas\dab.draft-01.schema.json + ..\ConfigGenerators\configGenerator.ps1 = ..\ConfigGenerators\configGenerator.ps1 + ..\ConfigGenerators\configGenerator.sh = ..\ConfigGenerators\configGenerator.sh + ..\ConfigGenerators\CosmosCommands.txt = ..\ConfigGenerators\CosmosCommands.txt + ..\schemas\dab.draft.schema.json = ..\schemas\dab.draft.schema.json + ..\ConfigGenerators\MsSqlCommands.txt = ..\ConfigGenerators\MsSqlCommands.txt + ..\ConfigGenerators\MySqlCommands.txt = ..\ConfigGenerators\MySqlCommands.txt + ..\ConfigGenerators\PostgreSqlCommands.txt = ..\ConfigGenerators\PostgreSqlCommands.txt Service\schema.gql = Service\schema.gql EndProjectSection EndProject diff --git a/src/Cli/test/EndToEndTests.cs b/src/Cli/test/EndToEndTests.cs index 19992a2676..0c9c67dd22 100644 --- a/src/Cli/test/EndToEndTests.cs +++ b/src/Cli/test/EndToEndTests.cs @@ -275,9 +275,9 @@ public void TestUpdateEntity() Assert.AreEqual("{\"id\":\"identity\",\"name\":\"Company Name\"}", JsonSerializer.Serialize(entity.Mappings)); } - // - // Test to verify the engine gets started using start command - // + /// + /// Test to verify the engine starts with the right log level using start command + /// [DataTestMethod] [DataRow("", true, false, DisplayName = "No logging from command line.")] [DataRow("--verbose", true, false, DisplayName = "Verbose logging from command line.")] @@ -302,13 +302,14 @@ public void TestUpdateEntity() [DataRow("--LogLevel eRROR", false, true, DisplayName = "Case sensitivity: LogLevel Error from command line.")] [DataRow("--LogLevel CrItIcal", false, true, DisplayName = "Case sensitivity: LogLevel Critical from command line.")] [DataRow("--LogLevel NONE", false, true, DisplayName = "Case sensitivity: LogLevel None from command line.")] - public void TestStartEngine(string logging, bool useDefaultConfig, bool expectSuccess) + public void TestStartEngine(string logging, bool useInvalidConfig, bool expectSuccess) { string configFileName; - if (useDefaultConfig) + if (useInvalidConfig) { - // default config contains empty connection-string - configFileName = RuntimeConfigPath.DefaultName; + // Invalid config with an empty connection string. + configFileName = InvalidConfigFileName; + WriteJsonContentToFile(configFileName, CONFIG_WTIH_INVALID_CONNECTION_STRING); } else { diff --git a/src/Cli/test/InitTests.cs b/src/Cli/test/InitTests.cs index 7455fce2b0..ddc9898b6c 100644 --- a/src/Cli/test/InitTests.cs +++ b/src/Cli/test/InitTests.cs @@ -28,7 +28,7 @@ public void MssqlDatabase() _basicRuntimeConfig = @"{ - ""$schema"": ""dab.draft-01.schema.json"", + ""$schema"": ""dab.draft.schema.json"", ""data-source"": { ""database-type"": ""mssql"", ""connection-string"": ""testconnectionstring"" @@ -67,7 +67,7 @@ public void TestInitializingConfigWithoutConnectionString() _basicRuntimeConfig = @"{ - ""$schema"": ""dab.draft-01.schema.json"", + ""$schema"": ""dab.draft.schema.json"", ""data-source"": { ""database-type"": ""mssql"", ""connection-string"": """" @@ -104,7 +104,7 @@ public void CosmosDatabase() devModeDefaultAuth: null); _basicRuntimeConfig = @"{ - ""$schema"": ""dab.draft-01.schema.json"", + ""$schema"": ""dab.draft.schema.json"", ""data-source"": { ""database-type"": ""cosmos"", ""connection-string"": ""testconnectionstring"" diff --git a/src/Cli/test/TestHelper.cs b/src/Cli/test/TestHelper.cs index c2d4488cbe..dc9dd1fb9b 100644 --- a/src/Cli/test/TestHelper.cs +++ b/src/Cli/test/TestHelper.cs @@ -5,6 +5,15 @@ public static class TestHelper // Config file name for tests public static string _testRuntimeConfig = "dab-config-test.json"; + // Name of an invalid config file that can be used for tests. + public static string InvalidConfigFileName + { + get + { + return "dab-config.invalid.json"; + } + } + /// /// Adds the entity properties to the configuration and returns the updated configuration json as a string. /// @@ -49,13 +58,25 @@ public static Process StartDabProcess(string command, string flags) } public const string SAMPLE_SCHEMA_DATA_SOURCE = @" - ""$schema"": ""dab.draft-01.schema.json"", + ""$schema"": ""dab.draft.schema.json"", ""data-source"": { ""database-type"": ""mssql"", ""connection-string"": ""testconnectionstring"" } "; + /// + /// Sample data source element with an empty connection string. + /// Used for generating an invalid config for tests. + /// + public const string SAMPLE_SCHEMA_DATA_SOURCE_WITH_EMPTY_CONNSTRING = @" + ""$schema"": ""dab.draft.schema.json"", + ""data-source"": { + ""database-type"": ""mssql"", + ""connection-string"": """" + } + "; + public const string INITIAL_CONFIG = "{" + SAMPLE_SCHEMA_DATA_SOURCE + "," + @@ -113,6 +134,34 @@ public static Process StartDabProcess(string command, string flags) ""entities"": {}" + "}"; + /// + /// Initial config with an empty connection string + /// + public const string CONFIG_WTIH_INVALID_CONNECTION_STRING = "{" + + SAMPLE_SCHEMA_DATA_SOURCE_WITH_EMPTY_CONNSTRING + "," + + @" + ""runtime"": { + ""rest"": { + ""path"": ""/api"" + }, + ""graphql"": { + ""path"": ""/graphql"", + ""allow-introspection"": true + }, + ""host"": { + ""mode"": ""development"", + ""cors"": { + ""origins"": [], + ""allow-credentials"": false + }, + ""authentication"": { + ""provider"": ""StaticWebApps"" + } + } + }, + ""entities"": {}" + + "}"; + public const string SINGLE_ENTITY = @" { ""entities"": { @@ -318,7 +367,7 @@ public static Process StartDabProcess(string command, string flags) public const string CONFIG_WITH_SINGLE_ENTITY = @" { - ""$schema"": ""dab.draft-01.schema.json"", + ""$schema"": ""dab.draft.schema.json"", ""data-source"": { ""database-type"": ""mssql"", ""connection-string"": ""localhost:5000"" diff --git a/src/Config/RuntimeConfig.cs b/src/Config/RuntimeConfig.cs index 84d6aa87cb..a51aa16332 100644 --- a/src/Config/RuntimeConfig.cs +++ b/src/Config/RuntimeConfig.cs @@ -71,7 +71,7 @@ public record RuntimeConfig( Dictionary Entities) { public const string SCHEMA_PROPERTY_NAME = "$schema"; - public const string SCHEMA = "dab.draft-01.schema.json"; + public const string SCHEMA = "dab.draft.schema.json"; // use camel case // convert Enum to strings diff --git a/src/Service.Tests/Configuration/ConfigurationTests.cs b/src/Service.Tests/Configuration/ConfigurationTests.cs index 47eb6f7235..0208bc21a1 100644 --- a/src/Service.Tests/Configuration/ConfigurationTests.cs +++ b/src/Service.Tests/Configuration/ConfigurationTests.cs @@ -456,7 +456,7 @@ public void VerifyExceptionOnNullModelinFilterParser() public void TestReadingRuntimeConfig() { Mock logger = new(); - string jsonString = File.ReadAllText(RuntimeConfigPath.DefaultName); + string jsonString = File.ReadAllText($"{RuntimeConfigPath.CONFIGFILE_NAME}." + $"{COSMOS_ENVIRONMENT}{RuntimeConfigPath.CONFIG_EXTENSION}"); RuntimeConfig.TryGetDeserializedRuntimeConfig(jsonString, out RuntimeConfig runtimeConfig, logger.Object); Assert.IsNotNull(runtimeConfig.Schema); Assert.IsInstanceOfType(runtimeConfig.DataSource, typeof(DataSource)); diff --git a/src/Service.Tests/Configuration/CorsUnitTests.cs b/src/Service.Tests/Configuration/CorsUnitTests.cs index bdc46125ef..9fb569b093 100644 --- a/src/Service.Tests/Configuration/CorsUnitTests.cs +++ b/src/Service.Tests/Configuration/CorsUnitTests.cs @@ -40,7 +40,7 @@ public class CorsUnitTests public void TestCorsConfigReadCorrectly() { Mock logger = new(); - string jsonString = File.ReadAllText(RuntimeConfigPath.DefaultName); + string jsonString = File.ReadAllText($"{RuntimeConfigPath.CONFIGFILE_NAME}." + $"{TestCategory.COSMOS}{RuntimeConfigPath.CONFIG_EXTENSION}"); RuntimeConfig.TryGetDeserializedRuntimeConfig(jsonString, out RuntimeConfig runtimeConfig, logger.Object); HostGlobalSettings hostGlobalSettings = JsonSerializer.Deserialize( diff --git a/src/Service.Tests/Unittests/RestServiceUnitTests.cs b/src/Service.Tests/Unittests/RestServiceUnitTests.cs index e35eef6b95..ee7dd3d6e9 100644 --- a/src/Service.Tests/Unittests/RestServiceUnitTests.cs +++ b/src/Service.Tests/Unittests/RestServiceUnitTests.cs @@ -19,7 +19,7 @@ namespace Azure.DataApiBuilder.Service.Tests.UnitTests public class RestServiceUnitTests { private static RestService _restService; - private static string _testCategory = "mssql"; + private static string _testCategory = "MsSql"; #region Positive Cases diff --git a/src/Service/Azure.DataApiBuilder.Service.csproj b/src/Service/Azure.DataApiBuilder.Service.csproj index dec888a1fe..8c28852a54 100644 --- a/src/Service/Azure.DataApiBuilder.Service.csproj +++ b/src/Service/Azure.DataApiBuilder.Service.csproj @@ -46,16 +46,6 @@ - - - - - - - - - - diff --git a/src/Service/dab-config.json b/src/Service/dab-config.json deleted file mode 100644 index 8fa6c8147d..0000000000 --- a/src/Service/dab-config.json +++ /dev/null @@ -1,361 +0,0 @@ -{ - "$schema": "../schemas/dab.draft-01.schema.json", - "data-source": { - "database-type": "mssql", - "connection-string": "" - }, - "runtime": { - "rest": { - "path": "/api" - }, - "graphql": { - "allow-introspection": true - }, - "host": { - "mode": "development", - "authenticate-devmode-requests": false, - "cors": { - "origins": [ "http://localhost:5000" ], - "allow-credentials": false - }, - "authentication": { - "provider": "StaticWebApps" - } - } - }, - "entities": { - "Publisher": { - "source": "publishers", - "rest": true, - "graphql": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ], - "relationships": { - "books": { - "cardinality": "many", - "target.entity": "Book" - } - } - }, - "Stock": { - "source": "stocks", - "rest": true, - "graphql": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "create", "read", "update" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "Book": { - "source": "books", - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ], - "relationships": { - "publishers": { - "cardinality": "one", - "target.entity": "Publisher" - }, - "websiteplacement": { - "cardinality": "one", - "target.entity": "BookWebsitePlacement" - }, - "reviews": { - "cardinality": "many", - "target.entity": "Review" - }, - "authors": { - "cardinality": "many", - "target.entity": "Author", - "linking.object": "book_author_link", - "linking.source.fields": [ "book_id" ], - "linking.target.fields": [ "author_id" ] - } - } - }, - "BookWebsitePlacement": { - "source": "book_website_placements", - "rest": true, - "graphql": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ - "create", - "update", - { - "action": "delete", - "policy": { - "database": "@claims.id eq @item.id" - }, - "fields": { - "include": [ "*" ], - "exclude": [ "id" ] - } - } - ] - } - ], - "relationships": { - "books": { - "cardinality": "one", - "target.entity": "Book" - } - } - }, - "Author": { - "source": "authors", - "rest": true, - "graphql": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ], - "relationships": { - "books": { - "cardinality": "many", - "target.entity": "Book", - "linking.object": "book_author_link" - } - } - }, - "Review": { - "source": "reviews", - "rest": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ], - "relationships": { - "books": { - "cardinality": "one", - "target.entity": "Book" - } - } - }, - "Comic": { - "source": "comics", - "rest": true, - "graphql": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "Broker": { - "source": "brokers", - "graphql": false, - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "WebsiteUser": { - "source": "website_users", - "rest": false, - "permissions": [ - { - "role": "anonymous", - "actions": [ "create", "read", "update", "delete" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "SupportedType": { - "source": "type_table", - "rest": false, - "permissions": [ - { - "role": "anonymous", - "actions": [ "create", "read", "update", "delete" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "stocks_price": { - "source": "stocks_price", - "rest": false, - "permissions": [ - { - "role": "anonymous", - "actions": [ "create", "read", "update", "delete" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "Tree": { - "source": "trees", - "rest": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "create", "read", "update", "delete" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "Shrub": { - "source": "trees", - "rest": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "create", "read", "update", "delete" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "Fungus": { - "source": "fungi", - "rest": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "create", "read", "update", "delete" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "Empty": { - "source": "empty_table", - "rest": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "create", "read", "update", "delete" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ] - }, - "books_view_all": { - "source": { - "object": "books_view_all", - "type": "view" - }, - "rest": true, - "graphql": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ], - "relationships": { - } - }, - "stocks_view_selected": { - "source": { - "object": "stocks_view_selected", - "type": "view" - }, - "rest": true, - "graphql": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ], - "relationships": { - } - }, - "books_publishers_view_composite": { - "source": { - "object": "books_publishers_view_composite", - "type": "view" - }, - "rest": true, - "graphql": true, - "permissions": [ - { - "role": "anonymous", - "actions": [ "read" ] - }, - { - "role": "authenticated", - "actions": [ "create", "read", "update", "delete" ] - } - ], - "relationships": { - } - } - } -}