Skip to content

Commit

Permalink
Upgrades from .NET7 to 8 (keeps 6 as current LTS) (#3617)
Browse files Browse the repository at this point in the history
* Upgrades from .NET7 to 8 (keeps 6 as current LTS)
* Adds RoleClaimType mapping for .net8

+semver: major
  • Loading branch information
brendankowitz authored Dec 18, 2023
1 parent fccb7a4 commit 1dae2e5
Show file tree
Hide file tree
Showing 111 changed files with 449 additions and 330 deletions.
6 changes: 4 additions & 2 deletions CustomAnalysisRules.ruleset
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="FHIR Analysis Rules" Description="The code analysis rules used for the FHIR server C# source projects." ToolsVersion="16.0">
<RuleSet Name="FHIR Analysis Rules" Description="The code analysis rules used for the FHIR server C# source projects." ToolsVersion="17.0">
<Include Path="minimumrecommendedrules.ruleset" Action="Default" />
<Include Path="securityrules.ruleset" Action="Default" />
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
Expand All @@ -16,6 +16,8 @@
<Rule Id="CA1062" Action="Info" />
<Rule Id="CA1508" Action="Info" />
<Rule Id="CA1805" Action="Info" />
<Rule Id="CA1860" Action="Info" />
<Rule Id="CA1863" Action="Info" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
<Rule Id="CA1054" Action="Info" />
Expand Down Expand Up @@ -48,4 +50,4 @@
<Rule Id="SA1642" Action="None" />
<Rule Id="SA1652" Action="None" />
</Rules>
</RuleSet>
</RuleSet>
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryUrl>https://github.com/microsoft/fhir-server/</RepositoryUrl>
<RunSettingsFilePath>$(MSBuildThisFileDirectory)\CodeCoverage.runsettings</RunSettingsFilePath>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
Expand Down
51 changes: 26 additions & 25 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<Project>
<!-- Shared dependencies versions.-->
<PropertyGroup>
<HealthcareSharedPackageVersion>7.0.29</HealthcareSharedPackageVersion>
<HealthcareSharedPackageVersion>7.1.5</HealthcareSharedPackageVersion>
<Hl7FhirVersion>4.3.0</Hl7FhirVersion>
</PropertyGroup>
<ItemGroup Label="CVE Mitigation">
<!--Please include the CGA id if possible-->
<PackageVersion Include="System.Security.Cryptography.Xml" Version="7.0.1" />
<PackageVersion Include="System.Security.Cryptography.Xml" Version="8.0.0" />
<!--CVE-2023-29331-->
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="7.0.3" />
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="8.0.0" />
<!-- CVE-2021-26701 -->
<PackageVersion Include="System.Text.Encodings.Web" Version="7.0.0" />
<PackageVersion Include="System.Text.Encodings.Web" Version="8.0.0" />
<!-- CVE-2020-1045 -->
<PackageVersion Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<!-- CVE-2022-26907 -->
<PackageVersion Include="Microsoft.Rest.ClientRuntime" Version="2.3.24" />
</ItemGroup>
<!-- SDK Packages -->
<Choose>
<When Condition="'$(TargetFramework)' == 'net7.0'">
<When Condition="'$(TargetFramework)' == 'net8.0'">
<PropertyGroup>
<AspNetPackageVersion>7.0.12</AspNetPackageVersion>
<AspNetPackageVersion>8.0.0</AspNetPackageVersion>
</PropertyGroup>
</When>
<Otherwise>
Expand All @@ -32,7 +32,7 @@
<ItemGroup>
<PackageVersion Include="AngleSharp" Version="1.0.4" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageVersion Include="Azure.Identity" Version="1.10.3" />
<PackageVersion Include="Azure.Identity" Version="1.10.4" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.0.0-beta.6" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.17.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
Expand Down Expand Up @@ -61,21 +61,22 @@
<PackageVersion Include="Microsoft.Azure.ContainerRegistry" Version="1.0.0-preview.2" />
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.35.3" />
<PackageVersion Include="Microsoft.Azure.Storage.Blob" Version="11.2.3" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageVersion Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="7.0.12" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="7.0.12" />
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="7.0.12" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="7.0.12" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.20.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Health.Abstractions" Version="$(HealthcareSharedPackageVersion)" />
<PackageVersion Include="Microsoft.Health.Api" Version="$(HealthcareSharedPackageVersion)" />
<PackageVersion Include="Microsoft.Health.Client" Version="$(HealthcareSharedPackageVersion)" />
Expand Down Expand Up @@ -108,9 +109,9 @@
<PackageVersion Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Configuration.Configuration" Version="6.0.1" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
<PackageVersion Include="System.Data.SqlClient" Version="4.8.5" />
<PackageVersion Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageVersion Include="System.Diagnostics.PerformanceCounter" Version="8.0.0" />
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Private.ServiceModel" Version="4.10.2" />
Expand All @@ -119,7 +120,7 @@
<PackageVersion Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageVersion Include="xunit" Version="2.5.0" />
<PackageVersion Include="xunit.assert" Version="2.5.0" />
<PackageVersion Include="System.Drawing.Common" Version="7.0.0" />
<PackageVersion Include="System.Drawing.Common" Version="8.0.0" />
<PackageVersion Include="Moq" Version="4.18.1" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion build/.vsts-PRInternalChecks-azureBuild-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
displayName: dotnet build
inputs:
projects: '**/*.sln'
arguments: --configuration ${{ parameters.BuildConfiguration }} --version-suffix $(build.buildnumber) /warnaserror -f net7.0
arguments: --configuration ${{ parameters.BuildConfiguration }} --version-suffix $(build.buildnumber) /warnaserror -f net8.0
- task: AutoApplicability@1
displayName: Run AutoApplicability
continueOnError: True
Expand Down
2 changes: 1 addition & 1 deletion build/build-variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

variables:
buildConfiguration: 'Release'
defaultBuildFramework: 'net7.0'
defaultBuildFramework: 'net8.0'
azureSubscriptionEndpoint: 'docker-build'
azureContainerRegistryName: 'healthplatformregistry'
azureContainerRegistry: '$(azureContainerRegistryName).azurecr.io'
Expand Down
2 changes: 1 addition & 1 deletion build/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ stages:
majorMinorPatch: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.majorMinorPatch']]
nuGetVersion: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.nuGetVersion']]
jobs:
- job: Windows_dotnet7
- job: Windows_dotnet8
pool:
name: '$(DefaultWindowsPool)'
steps:
Expand Down
6 changes: 3 additions & 3 deletions build/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0.402-cbl-mariner2.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0.100-1-cbl-mariner2.0 AS build
ARG FHIR_VERSION
ARG ASSEMBLY_VER

Expand Down Expand Up @@ -67,9 +67,9 @@ RUN dotnet restore ./src/Microsoft.Health.Fhir.${FHIR_VERSION}.Web/Microsoft.Hea

COPY . .

RUN dotnet publish /repo/src/Microsoft.Health.Fhir.${FHIR_VERSION}.Web/Microsoft.Health.Fhir.${FHIR_VERSION}.Web.csproj -c Release -o "/build" --no-restore -p:AssemblyVersion="${ASSEMBLY_VER}" -p:FileVersion="${ASSEMBLY_VER}" -p:Version="${ASSEMBLY_VER}" -f net7.0
RUN dotnet publish /repo/src/Microsoft.Health.Fhir.${FHIR_VERSION}.Web/Microsoft.Health.Fhir.${FHIR_VERSION}.Web.csproj -c Release -o "/build" --no-restore -p:AssemblyVersion="${ASSEMBLY_VER}" -p:FileVersion="${ASSEMBLY_VER}" -p:Version="${ASSEMBLY_VER}" -f net8.0

FROM mcr.microsoft.com/dotnet/aspnet:7.0.12-cbl-mariner2.0 AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:8.0.0-cbl-mariner2.0 AS runtime

ARG FHIR_VERSION

Expand Down
2 changes: 1 addition & 1 deletion build/dotnet6-compat/global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "6.0.415"
"version": "6.0.417"
}
}
2 changes: 1 addition & 1 deletion build/jobs/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ steps:
inputs:
userProvideBuildInfo: 'msBuildInfo'
msBuildArchitecture: 'DotNetCore'
msBuildCommandline: 'dotnet build $(Build.SourcesDirectory)/Microsoft.Health.Fhir.sln --configuration $(buildConfiguration) -p:ContinuousIntegrationBuild=true -f net7.0'
msBuildCommandline: 'dotnet build $(Build.SourcesDirectory)/Microsoft.Health.Fhir.sln --configuration $(buildConfiguration) -p:ContinuousIntegrationBuild=true -f net8.0'

- task: BinSkim@4
inputs:
Expand Down
2 changes: 1 addition & 1 deletion build/pr-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ stages:
majorMinorPatch: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.majorMinorPatch']]
nuGetVersion: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.nuGetVersion']]
jobs:
- job: Windows_dotnet7
- job: Windows_dotnet8
pool:
name: '$(DefaultWindowsPool)'
steps:
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "7.0.402"
"version": "8.0.100"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,36 @@ protected virtual async Task PublishNotificationAsync(HttpContext context, Reque
{
var apiNotification = new ApiResponseNotification();

using (var timer = _logger.BeginTimedScope(nameof(ApiNotificationMiddleware)) as ActionTimer)
using ActionTimer timer = _logger.BeginTimedScope(nameof(ApiNotificationMiddleware));
try
{
await next(context);
}
finally
{
apiNotification.Latency = timer.ElapsedTime;

try
{
await next(context);
}
finally
{
apiNotification.Latency = timer.ElapsedTime;
IFhirRequestContext fhirRequestContext = _fhirRequestContextAccessor.RequestContext;

try
// For now, we will only emit metrics for audited actions (e.g., metadata will not emit metrics).
if (fhirRequestContext?.AuditEventType != null)
{
IFhirRequestContext fhirRequestContext = _fhirRequestContextAccessor.RequestContext;
apiNotification.Authentication = fhirRequestContext.Principal?.Identity.AuthenticationType;
apiNotification.FhirOperation = fhirRequestContext.AuditEventType;
apiNotification.Protocol = context.Request.Scheme;
apiNotification.ResourceType = fhirRequestContext.ResourceType;
apiNotification.StatusCode = (HttpStatusCode)context.Response.StatusCode;

// For now, we will only emit metrics for audited actions (e.g., metadata will not emit metrics).
if (fhirRequestContext?.AuditEventType != null)
{
apiNotification.Authentication = fhirRequestContext.Principal?.Identity.AuthenticationType;
apiNotification.FhirOperation = fhirRequestContext.AuditEventType;
apiNotification.Protocol = context.Request.Scheme;
apiNotification.ResourceType = fhirRequestContext.ResourceType;
apiNotification.StatusCode = (HttpStatusCode)context.Response.StatusCode;

await _mediator.Publish(apiNotification, CancellationToken.None);
}
}
catch (Exception e)
{
// Failures in publishing API notifications should not cause the API to return an error.
_logger.LogCritical(e, "Failure while publishing API notification.");
await _mediator.Publish(apiNotification, CancellationToken.None);
}
}
catch (Exception e)
{
// Failures in publishing API notifications should not cause the API to return an error.
_logger.LogCritical(e, "Failure while publishing API notification.");
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Health.Fhir.Api/Features/Audit/AuditHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ private void Log(AuditAction auditAction, HttpStatusCode? statusCode, HttpContex
/// Return all the values of constants of the specified type
/// </summary>
/// <returns>List of constant values</returns>
private static IList<string> GetAnonymousOperations()
private static List<string> GetAnonymousOperations()
{
IList<string> anonymousOperations = new List<string>();
List<string> anonymousOperations = new List<string>();
FieldInfo[] fieldInfos = typeof(FhirAnonymousOperationType).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);

// Go through the list and only pick out the constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static bool TryParseDictionaryJson(string value, out Dictionary<string, s
}

value = value.Trim();
if (!value.StartsWith("{", StringComparison.Ordinal) || !value.EndsWith("}", StringComparison.Ordinal))
if (!value.StartsWith('{') || !value.EndsWith('}'))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ public static void AddRetryAfterHeaders(this IHeaderDictionary responseHeaders,
{
retryAfterTimeSpan ??= TimeSpan.FromSeconds(1); // in case this is missing, provide some value so we that the header is always there

responseHeaders.Add(
KnownHeaders.RetryAfterMilliseconds,
((int)retryAfterTimeSpan.Value.TotalMilliseconds).ToString(CultureInfo.InvariantCulture));
responseHeaders[KnownHeaders.RetryAfterMilliseconds] = ((int)retryAfterTimeSpan.Value.TotalMilliseconds).ToString(CultureInfo.InvariantCulture);

int retryAfterSeconds = retryAfterTimeSpan == default ? 0 : Math.Max(1, (int)Math.Round(retryAfterTimeSpan.Value.TotalSeconds));

responseHeaders.Add(
KnownHeaders.RetryAfter,
retryAfterSeconds.ToString(CultureInfo.InvariantCulture));
responseHeaders[KnownHeaders.RetryAfter] = retryAfterSeconds.ToString(CultureInfo.InvariantCulture);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static ResourceActionResult<TResult> SetContentLocationHeader<TResult>(th

var url = urlResolver.ResolveOperationResultUrl(operationName, id);

result.Headers.Add(HeaderNames.ContentLocation, url.ToString());
result.Headers[HeaderNames.ContentLocation] = url.ToString();
return result;
}

Expand All @@ -31,7 +31,7 @@ public static ResourceActionResult<TResult> SetContentTypeHeader<TResult>(this R
EnsureArg.IsNotNull(result, nameof(result));
EnsureArg.IsNotNullOrWhiteSpace(contentTypeValue, nameof(contentTypeValue));

result.Headers.Add(HeaderNames.ContentType, contentTypeValue);
result.Headers[HeaderNames.ContentType] = contentTypeValue;
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.Health.Fhir.Api.Configs;
using Microsoft.Health.Fhir.Api.Features.Headers;
using Microsoft.Health.Fhir.Core.Configs;
using Microsoft.Health.Fhir.Core.Extensions;
using Microsoft.Health.Fhir.Core.Features;
using Microsoft.Health.Fhir.Core.Features.Operations;

Expand Down Expand Up @@ -315,7 +316,7 @@ private async Task Return429FromRequestRateExceededException(RequestRateExceeded

public async ValueTask DisposeAsync()
{
_cancellationTokenSource.Cancel();
await _cancellationTokenSource.CancelAsync();
await _samplingLoopTask;
_cancellationTokenSource.Dispose();
_samplingLoopTask.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public PathBaseMiddleware(RequestDelegate next, PathString pathBase)

public async Task Invoke(HttpContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context, nameof(context));

var originalPathBase = context.Request.PathBase;
context.Request.PathBase = originalPathBase.Add(_pathBase);
Expand Down
Loading

0 comments on commit 1dae2e5

Please sign in to comment.