Skip to content

Commit

Permalink
[DMS-369] Test Handling of Role-Named References (#299)
Browse files Browse the repository at this point in the history
* E2E test cascading role named reference

* Test with hard coded apischema.json fix

* Complete test

* Allow use of local ApiSchema.json

* Update ApiSchema to latest
  • Loading branch information
simpat-adam authored Oct 17, 2024
1 parent cde92a5 commit 6636b1d
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 27 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,8 @@ coveragereport
# Smoke test related
sdk/


# Docker environemnt secrets
.env

# Local copies of ApiSchema.json
**/ApiSchema.json
16 changes: 9 additions & 7 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ The sections below describe custom configuration options in the `appSettings.jso

## AppSettings

| Parameter | Description |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Datastore | The primary datastore used by the DataManagementService. Valid values are `postgresql` and `mssql` |
| QueryHandler | The query handling datastore used by the DataManagementService. Valid values are `postgresql` and `opensearch` |
| DeployDatabaseOnStartup | When `true` the database in `ConnectionStrings:DatabaseConnection` will be created and initialized on startup. |
| BypassStringTypeCoercion | String type coercion attempts to coerce boolean and numeric strings to their proper type on `POST` and `PUT` requests. For example `"true"` becomes `true`. This setting bypasses that for performance. |
| AllowIdentityUpdateOverrides | Comma separated list of resource names that allow identity updates, overriding the default behavior to reject identity updates. |
| Parameter | Description |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Datastore | The primary datastore used by the DataManagementService. Valid values are `postgresql` and `mssql` |
| QueryHandler | The query handling datastore used by the DataManagementService. Valid values are `postgresql` and `opensearch` |
| DeployDatabaseOnStartup | When `true` the database in `ConnectionStrings:DatabaseConnection` will be created and initialized on startup. |
| BypassStringTypeCoercion | String type coercion attempts to coerce boolean and numeric strings to their proper type on `POST` and `PUT` requests. For example `"true"` becomes `true`. This setting bypasses that for performance. |
| AllowIdentityUpdateOverrides | Comma separated list of resource names that allow identity updates, overriding the default behavior to reject identity updates. |
| MaskRequestBodyInLogs | Controls whether to mask HTTP request bodies in log statements to avoid potentially logging PII. This setting only applies to `DEBUG` logging where requests are logged. |
| UseLocalApiSchemaJson | When `true` the application will use `src\core\EdFi.DataManagementService.Core\ApiSchema\ApiSchema.json` instead of the published package. This file is gitignored and should be manually added if needed |

## ConnectionStrings

Expand Down
4 changes: 2 additions & 2 deletions src/dms/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageVersion Include="dbup-postgresql" Version="5.0.40" />
<PackageVersion Include="dbup-sqlserver" Version="5.0.41" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.11.0" />
<PackageVersion Include="EdFi.DataStandard51.ApiSchema" Version="1.0.32" />
<PackageVersion Include="EdFi.DataStandard51.ApiSchema" Version="1.0.33" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.11.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
Expand Down Expand Up @@ -55,4 +55,4 @@
<PackageVersion Include="Reqnroll.NUnit" Version="2.1.0" />
<PackageVersion Include="Testcontainers" Version="3.10.0" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,52 @@

using System.Reflection;
using System.Text.Json.Nodes;
using EdFi.DataManagementService.Core.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace EdFi.DataManagementService.Core.ApiSchema;

/// <summary>
/// Loads and parses the ApiSchema.json from a file.
/// </summary>
internal class ApiSchemaFileLoader(ILogger<ApiSchemaFileLoader> _logger) : IApiSchemaProvider
internal class ApiSchemaFileLoader(ILogger<ApiSchemaFileLoader> _logger, IOptions<AppSettings> appSettings)
: IApiSchemaProvider
{
private readonly Lazy<JsonNode> _apiSchemaRootNode =
new(() =>
{
_logger.LogDebug("Entering ApiSchemaFileLoader");

var assembly =
Assembly.GetAssembly(typeof(DataStandard51.ApiSchema.Marker))
?? throw new InvalidOperationException("Could not load the ApiSchema library");
string jsonContent;

var resourceName = assembly
.GetManifestResourceNames()
.Single(str => str.EndsWith("ApiSchema.json"));
if (appSettings.Value.UseLocalApiSchemaJson)
{
jsonContent = File.ReadAllText(
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "",
"ApiSchema",
"ApiSchema.json"
)
);
}
else
{
var assembly =
Assembly.GetAssembly(typeof(DataStandard51.ApiSchema.Marker))
?? throw new InvalidOperationException("Could not load the ApiSchema library");

using Stream stream =
assembly.GetManifestResourceStream(resourceName)
?? throw new InvalidOperationException("Could not load ApiSchema resource");
using StreamReader reader = new(stream);
var jsonContent = reader.ReadToEnd();
var resourceName = assembly
.GetManifestResourceNames()
.Single(str => str.EndsWith("ApiSchema.json"));

using Stream stream =
assembly.GetManifestResourceStream(resourceName)
?? throw new InvalidOperationException("Could not load ApiSchema resource");
using StreamReader reader = new(stream);

jsonContent = reader.ReadToEnd();
}

JsonNode? rootNodeFromFile = JsonNode.Parse(jsonContent);
if (rootNodeFromFile == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ public class AppSettings
/// Know whether to mask the requested Body
/// </summary>
public bool MaskRequestBodyInLogs { get; set; }

/// <summary>
/// When true the application will use \ApiSchema\ApiSchema.json
/// instead of the published package.
/// </summary>
public bool UseLocalApiSchemaJson { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@
</None>
</ItemGroup>

<ItemGroup>
<None Update="ApiSchema\ApiSchema.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"BypassStringTypeCoercion": false,
"CorrelationIdHeader": "correlationid",
"AllowIdentityUpdateOverrides": "",
"MaskRequestBodyInLogs": true
"MaskRequestBodyInLogs": true,
"UseLocalApiSchemaJson": false
},
"ConnectionStrings": {
"DatabaseConnection": "host=localhost;port=5432;username=postgres;database=edfi_datamanagementservice;",
Expand All @@ -29,7 +30,7 @@
"QueueLimit": 0
},
"Serilog": {
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console" ],
"Using": ["Serilog.Sinks.File", "Serilog.Sinks.Console"],
"MinimumLevel": {
"Default": "Information"
},
Expand Down
Loading

0 comments on commit 6636b1d

Please sign in to comment.