From 82145bf3fce7772c22158065c22d71f9451dbc63 Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Sun, 30 Oct 2022 17:20:13 +0530 Subject: [PATCH 01/10] removing --no-build argument when creating nuget, removing config references --- .pipelines/build-pipelines.yml | 2 +- src/Azure.DataApiBuilder.sln | 9 --------- src/Service/Azure.DataApiBuilder.Service.csproj | 5 ----- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/.pipelines/build-pipelines.yml b/.pipelines/build-pipelines.yml index fc3caf4a52..bc3dff997e 100644 --- a/.pipelines/build-pipelines.yml +++ b/.pipelines/build-pipelines.yml @@ -102,7 +102,7 @@ steps: command: custom custom: pack projects: '**/Cli.csproj' - arguments: '--configuration $(buildConfiguration) --no-build -p:Version=$(dabVersion) -o $(Build.ArtifactStagingDirectory)/nupkg' + arguments: '--configuration $(buildConfiguration) -p:Version=$(dabVersion) -o $(Build.ArtifactStagingDirectory)/nupkg' # Now sign the nuget package itself. - template: templates/code-signing.yml diff --git a/src/Azure.DataApiBuilder.sln b/src/Azure.DataApiBuilder.sln index 68f776ad92..4f1c9599f4 100644 --- a/src/Azure.DataApiBuilder.sln +++ b/src/Azure.DataApiBuilder.sln @@ -8,16 +8,7 @@ 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 Service\schema.gql = Service\schema.gql EndProjectSection EndProject diff --git a/src/Service/Azure.DataApiBuilder.Service.csproj b/src/Service/Azure.DataApiBuilder.Service.csproj index dec888a1fe..517cb625cd 100644 --- a/src/Service/Azure.DataApiBuilder.Service.csproj +++ b/src/Service/Azure.DataApiBuilder.Service.csproj @@ -48,14 +48,9 @@ - - - - - From 1cdde366d7bc2bfdf6296dff80f27bb50b693940 Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Mon, 31 Oct 2022 16:44:36 +0530 Subject: [PATCH 02/10] Generating default config using cli, adding command files to sln for easy editing using visual studio --- ConfigGenerators/DefaultConfigCommands.txt | 55 ++++++++++++++++++++++ ConfigGenerators/configGenerator.ps1 | 8 +++- ConfigGenerators/configGenerator.sh | 7 ++- src/Azure.DataApiBuilder.sln | 8 ++++ 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 ConfigGenerators/DefaultConfigCommands.txt diff --git a/ConfigGenerators/DefaultConfigCommands.txt b/ConfigGenerators/DefaultConfigCommands.txt new file mode 100644 index 0000000000..946ae5709c --- /dev/null +++ b/ConfigGenerators/DefaultConfigCommands.txt @@ -0,0 +1,55 @@ +init --database-type mssql --connection-string " " --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" +add Publisher --source publishers --permissions "anonymous:read" +add Stock --source stocks --permissions "anonymous:create,read,update" +add Book --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books" +add BookWebsitePlacement --source book_website_placements --permissions "anonymous:read" +add Author --source authors --permissions "anonymous:read" +add Review --source reviews --permissions "anonymous:create,read,update" --rest true --graphql "review:reviews" +add Comic --source comics --permissions "anonymous:create,read,update" +add Broker --source brokers --permissions "anonymous:read" +add WebsiteUser --source website_users --permissions "anonymous:create,read,delete,update" +add SupportedType --source type_table --permissions "anonymous:create,read,delete,update" +add stocks_price --source stocks_price --permissions "anonymous:read" +add Tree --source trees --permissions "anonymous:create,read,update,delete" +add Shrub --source trees --permissions "anonymous:create,read,update,delete" --rest plants +add Fungus --source fungi --permissions "anonymous:create,read,update,delete" --graphql "fungus:fungi" +add Empty --source "empty_table" --permissions "authenticated:create,read,update,delete" --rest true +add Notebook --source "notebooks" --permissions "anonymous:read" --rest true --graphql true --fields.include "*" --policy-database "@item ne 1" +add Journal --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete" +add ArtOfWar --source "aow" --rest true --permissions "anonymous:create,read,update,delete" +add series --source "series" --permissions "anonymous:create,read,update,delete" +update Publisher --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many +update Stock --permissions "authenticated:create,read,update,delete" --rest commodities --graphql true +update Book --permissions "authenticated:create,read,update,delete" +update Book --relationship publishers --target.entity Publisher --cardinality one +update Book --relationship websiteplacement --target.entity BookWebsitePlacement --cardinality one +update Book --relationship reviews --target.entity Review --cardinality many +update Book --relationship authors --target.entity Author --cardinality many --linking.object book_author_link --linking.source.fields "book_id" --linking.target.fields "author_id" +update Book --map "id:id,title:title" +update Review --permissions "authenticated:create,read,update,delete" +update Review --relationship books --target.entity Book --cardinality one +update BookWebsitePlacement --permissions "authenticated:create,update" --rest true --graphql true +update BookWebsitePlacement --permissions "authenticated:delete" --fields.include "*" --policy-database "@claims.id eq @item.id" +update Author --permissions "authenticated:create,read,update,delete" --rest true --graphql true +update WebsiteUser --permissions "authenticated:create,read,delete,update" --rest false --graphql "websiteUser:websiteUsers" +update stocks_price --permissions "authenticated:create,read,delete,update" --rest false +update Comic --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship series --target.entity series --cardinality one +update series --relationship comics --target.entity Comic --cardinality many +update Broker --permissions "authenticated:create,update,read,delete" --graphql false +update Tree --rest true --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region" +update Shrub --permissions "authenticated:create,read,update,delete" --map "species:fancyName" +update Fungus --permissions "authenticated:create,read,update,delete" --map "spores:hazards" --rest true +update Fungus --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'" +update BookWebsitePlacement --relationship books --target.entity Book --cardinality one +update SupportedType --permissions "authenticated:create,read,delete,update" --rest false +update Author --relationship books --target.entity Book --cardinality many --linking.object book_author_link +update Notebook --permissions "anonymous:create,update,delete" +update Empty --permissions "anonymous:read" +update Journal --permissions "policy_tester_noupdate:update" --fields.include "*" --policy-database "@item.id ne 1" +update Journal --permissions "policy_tester_noupdate:read" --fields.include "*" +update Journal --permissions "policy_tester_update_noread:create" +update Journal --permissions "policy_tester_update_noread:update" --fields.include "*" --policy-database "@item.id eq 1" +update Journal --permissions "policy_tester_update_noread:read" --fields.exclude "*" +update Journal --permissions "policy_tester_update_noread:delete" --fields.include "*" --policy-database "@item.id eq 1" +update Journal --permissions "authorizationHandlerTester:read" +update ArtOfWar --permissions "authenticated:create,read,update,delete" --map "DetailAssessmentAndPlanning:始計,WagingWar:作戰,StrategicAttack:謀攻,NoteNum:┬─┬ノ( º _ ºノ)" diff --git a/ConfigGenerators/configGenerator.ps1 b/ConfigGenerators/configGenerator.ps1 index 2195829824..e01042d811 100644 --- a/ConfigGenerators/configGenerator.ps1 +++ b/ConfigGenerators/configGenerator.ps1 @@ -7,7 +7,7 @@ $PSDefaultParameterValues['*:Encoding'] = 'utf8'; # When invoked without any arguments, config files for all the database types will be generated. $databaseTypes = @(); if($args.Count -eq 0){ - $databaseTypes = "MsSql", "MySql", "PostgreSql", "Cosmos"; + $databaseTypes = "MsSql", "MySql", "PostgreSql", "Cosmos", "Default"; } elseif($args.Count -eq 1){ $databaseType = $args[0]; @@ -44,10 +44,14 @@ foreach($databaseType in $databaseTypes){ $commandFile = "PostgreSqlCommands.txt"; $configFile = "dab-config.PostgreSql.json"; } - else{ + elseif($databaseType -eq "Cosmos"){ $commandFile = "CosmosCommands.txt"; $configFile = "dab-config.Cosmos.json"; } + else{ + $commandFile = "DefaultConfigCommands.txt"; + $configFile = "dab-config.json"; + } # If a config file with the same name exists, it is deleted to avoid writing to # the same config file diff --git a/ConfigGenerators/configGenerator.sh b/ConfigGenerators/configGenerator.sh index 95a0e82ccd..57e0dc0d02 100644 --- a/ConfigGenerators/configGenerator.sh +++ b/ConfigGenerators/configGenerator.sh @@ -7,7 +7,7 @@ databaseTypes=(); # When invoked with a database type, config file for that database type will be generated. # When invoked without any arguments, config files for all the database types will be generated. if [[ $# -eq 0 ]]; then - databaseTypes=("MsSql" "MySql" "PostgreSql" "Cosmos") + databaseTypes=("MsSql" "MySql" "PostgreSql" "Cosmos" "Default") elif [[ $# -eq 1 ]]; then databaseType=$1; if ! { [ $databaseType == "MsSql" ] || [ $databaseType == "MySql" ] || [ $databaseType == "PostgreSql" ] || [ $databaseType == "Cosmos" ]; }; then @@ -44,9 +44,12 @@ do elif [[ $databaseType == "PostgreSql" ]]; then commandFile="PostgreSqlCommands.txt"; configFile="dab-config.PostgreSql.json"; - else + elif [[ $databaseType == "Cosmos" ]]; then commandFile="CosmosCommands.txt"; configFile="dab-config.Cosmos.json"; + else + commandFile="DefaultConfigCommands.txt"; + configFile="dab-config.json"; fi # If a config file with the same name exists, it is deleted to avoid writing to diff --git a/src/Azure.DataApiBuilder.sln b/src/Azure.DataApiBuilder.sln index 4f1c9599f4..c9a7b2cbb9 100644 --- a/src/Azure.DataApiBuilder.sln +++ b/src/Azure.DataApiBuilder.sln @@ -8,7 +8,15 @@ 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 + ..\ConfigGenerators\CosmosCommands.txt = ..\ConfigGenerators\CosmosCommands.txt + ..\ConfigGenerators\MsSqlCommands.txt = ..\ConfigGenerators\MsSqlCommands.txt + ..\ConfigGenerators\MySqlCommands.txt = ..\ConfigGenerators\MySqlCommands.txt + ..\ConfigGenerators\PostgreSqlCommands.txt = ..\ConfigGenerators\PostgreSqlCommands.txt + ..\ConfigGenerators\DefaultConfigCommands.txt = ..\ConfigGenerators\DefaultConfigCommands.txt Service\dab-config.json = Service\dab-config.json + ..\schemas\dab.draft.schema.json = ..\schemas\dab.draft.schema.json + ..\ConfigGenerators\configGenerator.ps1 = ..\ConfigGenerators\configGenerator.ps1 + ..\ConfigGenerators\configGenerator.sh = ..\ConfigGenerators\configGenerator.sh Service\schema.gql = Service\schema.gql EndProjectSection EndProject From 328bf89f6aaab34155b144fddb46f3632e0e817c Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Mon, 31 Oct 2022 16:45:32 +0530 Subject: [PATCH 03/10] removing checked-in default config --- src/Service/dab-config.json | 361 ------------------------------------ 1 file changed, 361 deletions(-) delete mode 100644 src/Service/dab-config.json 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": { - } - } - } -} From 0ef4d6955096230fca8e1bbb430a5f10922cc49f Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Mon, 31 Oct 2022 17:09:37 +0530 Subject: [PATCH 04/10] removing config files itemgroup --- src/Service/Azure.DataApiBuilder.Service.csproj | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Service/Azure.DataApiBuilder.Service.csproj b/src/Service/Azure.DataApiBuilder.Service.csproj index 517cb625cd..8c28852a54 100644 --- a/src/Service/Azure.DataApiBuilder.Service.csproj +++ b/src/Service/Azure.DataApiBuilder.Service.csproj @@ -46,11 +46,6 @@ - - - - - From d78b50076bab592fb289a91a6872192415f61888 Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Mon, 31 Oct 2022 17:57:23 +0530 Subject: [PATCH 05/10] removing dab-config.json from sln --- src/Azure.DataApiBuilder.sln | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Azure.DataApiBuilder.sln b/src/Azure.DataApiBuilder.sln index c9a7b2cbb9..f134ff17fd 100644 --- a/src/Azure.DataApiBuilder.sln +++ b/src/Azure.DataApiBuilder.sln @@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Configs", "Configs", "{EFA9 ..\ConfigGenerators\MySqlCommands.txt = ..\ConfigGenerators\MySqlCommands.txt ..\ConfigGenerators\PostgreSqlCommands.txt = ..\ConfigGenerators\PostgreSqlCommands.txt ..\ConfigGenerators\DefaultConfigCommands.txt = ..\ConfigGenerators\DefaultConfigCommands.txt - Service\dab-config.json = Service\dab-config.json ..\schemas\dab.draft.schema.json = ..\schemas\dab.draft.schema.json ..\ConfigGenerators\configGenerator.ps1 = ..\ConfigGenerators\configGenerator.ps1 ..\ConfigGenerators\configGenerator.sh = ..\ConfigGenerators\configGenerator.sh From 10921b4cfebeb61a38c990f79dd52d56a5bcd60c Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Wed, 2 Nov 2022 12:06:07 +0530 Subject: [PATCH 06/10] updating unit tests that uses dab-config.json file --- .pipelines/build-pipelines.yml | 2 +- ConfigGenerators/DefaultConfigCommands.txt | 55 ------------------- ConfigGenerators/configGenerator.ps1 | 8 +-- ConfigGenerators/configGenerator.sh | 7 +-- src/Azure.DataApiBuilder.sln | 7 +-- src/Cli/test/EndToEndTests.cs | 15 ++--- src/Cli/test/InitTests.cs | 6 +- src/Cli/test/TestHelper.cs | 44 ++++++++++++++- src/Config/RuntimeConfig.cs | 2 +- src/Config/RuntimeConfigPath.cs | 9 +++ .../Configuration/ConfigurationTests.cs | 2 +- .../Configuration/CorsUnitTests.cs | 2 +- 12 files changed, 73 insertions(+), 86 deletions(-) delete mode 100644 ConfigGenerators/DefaultConfigCommands.txt diff --git a/.pipelines/build-pipelines.yml b/.pipelines/build-pipelines.yml index bc3dff997e..fc3caf4a52 100644 --- a/.pipelines/build-pipelines.yml +++ b/.pipelines/build-pipelines.yml @@ -102,7 +102,7 @@ steps: command: custom custom: pack projects: '**/Cli.csproj' - arguments: '--configuration $(buildConfiguration) -p:Version=$(dabVersion) -o $(Build.ArtifactStagingDirectory)/nupkg' + arguments: '--configuration $(buildConfiguration) --no-build -p:Version=$(dabVersion) -o $(Build.ArtifactStagingDirectory)/nupkg' # Now sign the nuget package itself. - template: templates/code-signing.yml diff --git a/ConfigGenerators/DefaultConfigCommands.txt b/ConfigGenerators/DefaultConfigCommands.txt deleted file mode 100644 index 946ae5709c..0000000000 --- a/ConfigGenerators/DefaultConfigCommands.txt +++ /dev/null @@ -1,55 +0,0 @@ -init --database-type mssql --connection-string " " --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" -add Publisher --source publishers --permissions "anonymous:read" -add Stock --source stocks --permissions "anonymous:create,read,update" -add Book --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books" -add BookWebsitePlacement --source book_website_placements --permissions "anonymous:read" -add Author --source authors --permissions "anonymous:read" -add Review --source reviews --permissions "anonymous:create,read,update" --rest true --graphql "review:reviews" -add Comic --source comics --permissions "anonymous:create,read,update" -add Broker --source brokers --permissions "anonymous:read" -add WebsiteUser --source website_users --permissions "anonymous:create,read,delete,update" -add SupportedType --source type_table --permissions "anonymous:create,read,delete,update" -add stocks_price --source stocks_price --permissions "anonymous:read" -add Tree --source trees --permissions "anonymous:create,read,update,delete" -add Shrub --source trees --permissions "anonymous:create,read,update,delete" --rest plants -add Fungus --source fungi --permissions "anonymous:create,read,update,delete" --graphql "fungus:fungi" -add Empty --source "empty_table" --permissions "authenticated:create,read,update,delete" --rest true -add Notebook --source "notebooks" --permissions "anonymous:read" --rest true --graphql true --fields.include "*" --policy-database "@item ne 1" -add Journal --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete" -add ArtOfWar --source "aow" --rest true --permissions "anonymous:create,read,update,delete" -add series --source "series" --permissions "anonymous:create,read,update,delete" -update Publisher --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many -update Stock --permissions "authenticated:create,read,update,delete" --rest commodities --graphql true -update Book --permissions "authenticated:create,read,update,delete" -update Book --relationship publishers --target.entity Publisher --cardinality one -update Book --relationship websiteplacement --target.entity BookWebsitePlacement --cardinality one -update Book --relationship reviews --target.entity Review --cardinality many -update Book --relationship authors --target.entity Author --cardinality many --linking.object book_author_link --linking.source.fields "book_id" --linking.target.fields "author_id" -update Book --map "id:id,title:title" -update Review --permissions "authenticated:create,read,update,delete" -update Review --relationship books --target.entity Book --cardinality one -update BookWebsitePlacement --permissions "authenticated:create,update" --rest true --graphql true -update BookWebsitePlacement --permissions "authenticated:delete" --fields.include "*" --policy-database "@claims.id eq @item.id" -update Author --permissions "authenticated:create,read,update,delete" --rest true --graphql true -update WebsiteUser --permissions "authenticated:create,read,delete,update" --rest false --graphql "websiteUser:websiteUsers" -update stocks_price --permissions "authenticated:create,read,delete,update" --rest false -update Comic --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship series --target.entity series --cardinality one -update series --relationship comics --target.entity Comic --cardinality many -update Broker --permissions "authenticated:create,update,read,delete" --graphql false -update Tree --rest true --permissions "authenticated:create,read,update,delete" --map "species:Scientific Name,region:United State's Region" -update Shrub --permissions "authenticated:create,read,update,delete" --map "species:fancyName" -update Fungus --permissions "authenticated:create,read,update,delete" --map "spores:hazards" --rest true -update Fungus --permissions "policy_tester_01:read" --fields.include "*" --policy-database "@item.region ne 'northeast'" -update BookWebsitePlacement --relationship books --target.entity Book --cardinality one -update SupportedType --permissions "authenticated:create,read,delete,update" --rest false -update Author --relationship books --target.entity Book --cardinality many --linking.object book_author_link -update Notebook --permissions "anonymous:create,update,delete" -update Empty --permissions "anonymous:read" -update Journal --permissions "policy_tester_noupdate:update" --fields.include "*" --policy-database "@item.id ne 1" -update Journal --permissions "policy_tester_noupdate:read" --fields.include "*" -update Journal --permissions "policy_tester_update_noread:create" -update Journal --permissions "policy_tester_update_noread:update" --fields.include "*" --policy-database "@item.id eq 1" -update Journal --permissions "policy_tester_update_noread:read" --fields.exclude "*" -update Journal --permissions "policy_tester_update_noread:delete" --fields.include "*" --policy-database "@item.id eq 1" -update Journal --permissions "authorizationHandlerTester:read" -update ArtOfWar --permissions "authenticated:create,read,update,delete" --map "DetailAssessmentAndPlanning:始計,WagingWar:作戰,StrategicAttack:謀攻,NoteNum:┬─┬ノ( º _ ºノ)" diff --git a/ConfigGenerators/configGenerator.ps1 b/ConfigGenerators/configGenerator.ps1 index e01042d811..2195829824 100644 --- a/ConfigGenerators/configGenerator.ps1 +++ b/ConfigGenerators/configGenerator.ps1 @@ -7,7 +7,7 @@ $PSDefaultParameterValues['*:Encoding'] = 'utf8'; # When invoked without any arguments, config files for all the database types will be generated. $databaseTypes = @(); if($args.Count -eq 0){ - $databaseTypes = "MsSql", "MySql", "PostgreSql", "Cosmos", "Default"; + $databaseTypes = "MsSql", "MySql", "PostgreSql", "Cosmos"; } elseif($args.Count -eq 1){ $databaseType = $args[0]; @@ -44,14 +44,10 @@ foreach($databaseType in $databaseTypes){ $commandFile = "PostgreSqlCommands.txt"; $configFile = "dab-config.PostgreSql.json"; } - elseif($databaseType -eq "Cosmos"){ + else{ $commandFile = "CosmosCommands.txt"; $configFile = "dab-config.Cosmos.json"; } - else{ - $commandFile = "DefaultConfigCommands.txt"; - $configFile = "dab-config.json"; - } # If a config file with the same name exists, it is deleted to avoid writing to # the same config file diff --git a/ConfigGenerators/configGenerator.sh b/ConfigGenerators/configGenerator.sh index 57e0dc0d02..d208953d65 100644 --- a/ConfigGenerators/configGenerator.sh +++ b/ConfigGenerators/configGenerator.sh @@ -7,7 +7,7 @@ databaseTypes=(); # When invoked with a database type, config file for that database type will be generated. # When invoked without any arguments, config files for all the database types will be generated. if [[ $# -eq 0 ]]; then - databaseTypes=("MsSql" "MySql" "PostgreSql" "Cosmos" "Default") + databaseTypes=("MsSql" "MySql" "PostgreSql" "Cosmos") elif [[ $# -eq 1 ]]; then databaseType=$1; if ! { [ $databaseType == "MsSql" ] || [ $databaseType == "MySql" ] || [ $databaseType == "PostgreSql" ] || [ $databaseType == "Cosmos" ]; }; then @@ -44,12 +44,9 @@ do elif [[ $databaseType == "PostgreSql" ]]; then commandFile="PostgreSqlCommands.txt"; configFile="dab-config.PostgreSql.json"; - elif [[ $databaseType == "Cosmos" ]]; then + else [[ $databaseType == "Cosmos" ]]; then commandFile="CosmosCommands.txt"; configFile="dab-config.Cosmos.json"; - else - commandFile="DefaultConfigCommands.txt"; - configFile="dab-config.json"; fi # If a config file with the same name exists, it is deleted to avoid writing to diff --git a/src/Azure.DataApiBuilder.sln b/src/Azure.DataApiBuilder.sln index f134ff17fd..68453fd2f5 100644 --- a/src/Azure.DataApiBuilder.sln +++ b/src/Azure.DataApiBuilder.sln @@ -8,14 +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 + ..\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 - ..\ConfigGenerators\DefaultConfigCommands.txt = ..\ConfigGenerators\DefaultConfigCommands.txt - ..\schemas\dab.draft.schema.json = ..\schemas\dab.draft.schema.json - ..\ConfigGenerators\configGenerator.ps1 = ..\ConfigGenerators\configGenerator.ps1 - ..\ConfigGenerators\configGenerator.sh = ..\ConfigGenerators\configGenerator.sh Service\schema.gql = Service\schema.gql EndProjectSection EndProject diff --git a/src/Cli/test/EndToEndTests.cs b/src/Cli/test/EndToEndTests.cs index 19992a2676..a14050da61 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 = RuntimeConfigPath.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..3dc17e20df 100644 --- a/src/Cli/test/TestHelper.cs +++ b/src/Cli/test/TestHelper.cs @@ -49,13 +49,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 +125,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 +358,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/Config/RuntimeConfigPath.cs b/src/Config/RuntimeConfigPath.cs index 4687339cae..7f07820aeb 100644 --- a/src/Config/RuntimeConfigPath.cs +++ b/src/Config/RuntimeConfigPath.cs @@ -189,6 +189,15 @@ public static string DefaultName } } + // Name of an invalid config file that can be used for tests. + public static string InvalidConfigFileName + { + get + { + return "dab-config.invalid.json"; + } + } + /// /// Generates the config file name and a corresponding overridden file name, /// With precedence given to overridden file name, returns that name diff --git a/src/Service.Tests/Configuration/ConfigurationTests.cs b/src/Service.Tests/Configuration/ConfigurationTests.cs index 47eb6f7235..90ffc9423a 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( From b21d9c0a12c39d446879750b9fa0f284630cb96e Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Wed, 2 Nov 2022 12:09:59 +0530 Subject: [PATCH 07/10] re-writing a condition --- ConfigGenerators/configGenerator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConfigGenerators/configGenerator.sh b/ConfigGenerators/configGenerator.sh index d208953d65..95a0e82ccd 100644 --- a/ConfigGenerators/configGenerator.sh +++ b/ConfigGenerators/configGenerator.sh @@ -44,7 +44,7 @@ do elif [[ $databaseType == "PostgreSql" ]]; then commandFile="PostgreSqlCommands.txt"; configFile="dab-config.PostgreSql.json"; - else [[ $databaseType == "Cosmos" ]]; then + else commandFile="CosmosCommands.txt"; configFile="dab-config.Cosmos.json"; fi From 8b0839b87865271b1fd52af513283bbf812ebb58 Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Wed, 2 Nov 2022 12:31:51 +0530 Subject: [PATCH 08/10] changing the case of MsSql --- src/Service.Tests/Unittests/RestServiceUnitTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From ad8e3a4720aa6f922a0a8eb78c6e3a8a244c33ec Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Wed, 2 Nov 2022 12:52:14 +0530 Subject: [PATCH 09/10] moving invalid config name to testhelper --- src/Cli/test/EndToEndTests.cs | 4 ++-- src/Cli/test/TestHelper.cs | 9 +++++++++ src/Config/RuntimeConfigPath.cs | 11 +---------- src/Service.Tests/Configuration/ConfigurationTests.cs | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Cli/test/EndToEndTests.cs b/src/Cli/test/EndToEndTests.cs index a14050da61..0c9c67dd22 100644 --- a/src/Cli/test/EndToEndTests.cs +++ b/src/Cli/test/EndToEndTests.cs @@ -308,8 +308,8 @@ public void TestStartEngine(string logging, bool useInvalidConfig, bool expectSu if (useInvalidConfig) { // Invalid config with an empty connection string. - configFileName = RuntimeConfigPath.InvalidConfigFileName; - WriteJsonContentToFile(configFileName,CONFIG_WTIH_INVALID_CONNECTION_STRING ); + configFileName = InvalidConfigFileName; + WriteJsonContentToFile(configFileName, CONFIG_WTIH_INVALID_CONNECTION_STRING); } else { diff --git a/src/Cli/test/TestHelper.cs b/src/Cli/test/TestHelper.cs index 3dc17e20df..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. /// diff --git a/src/Config/RuntimeConfigPath.cs b/src/Config/RuntimeConfigPath.cs index 7f07820aeb..77b2e6b5d4 100644 --- a/src/Config/RuntimeConfigPath.cs +++ b/src/Config/RuntimeConfigPath.cs @@ -188,16 +188,7 @@ public static string DefaultName return $"{CONFIGFILE_NAME}{CONFIG_EXTENSION}"; } } - - // Name of an invalid config file that can be used for tests. - public static string InvalidConfigFileName - { - get - { - return "dab-config.invalid.json"; - } - } - + /// /// Generates the config file name and a corresponding overridden file name, /// With precedence given to overridden file name, returns that name diff --git a/src/Service.Tests/Configuration/ConfigurationTests.cs b/src/Service.Tests/Configuration/ConfigurationTests.cs index 90ffc9423a..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.CONFIGFILE_NAME}." + $"{COSMOS_ENVIRONMENT}{RuntimeConfigPath.CONFIG_EXTENSION}"); + 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)); From 9e7b5ba5506a8508f03476bbdc127bc7c1562b9d Mon Sep 17 00:00:00 2001 From: Shyam Sundar J Date: Wed, 2 Nov 2022 13:17:15 +0530 Subject: [PATCH 10/10] fix formatting --- src/Config/RuntimeConfigPath.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/RuntimeConfigPath.cs b/src/Config/RuntimeConfigPath.cs index 77b2e6b5d4..4687339cae 100644 --- a/src/Config/RuntimeConfigPath.cs +++ b/src/Config/RuntimeConfigPath.cs @@ -188,7 +188,7 @@ public static string DefaultName return $"{CONFIGFILE_NAME}{CONFIG_EXTENSION}"; } } - + /// /// Generates the config file name and a corresponding overridden file name, /// With precedence given to overridden file name, returns that name