Skip to content

Commit

Permalink
build(deps): upgrade flurl
Browse files Browse the repository at this point in the history
Refs: #1052
  • Loading branch information
Phil91 committed Oct 2, 2024
1 parent 2922d43 commit 1eca288
Show file tree
Hide file tree
Showing 235 changed files with 1,480 additions and 2,317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities;
using Org.Eclipse.TractusX.Portal.Backend.Processes.Library;
using Org.Eclipse.TractusX.Portal.Backend.Processes.Mailing.Library;
using System.Collections.Immutable;
using System.Globalization;
using System.Text.Json;
using System.Text.RegularExpressions;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Extensions;
using Org.Eclipse.TractusX.Portal.Backend.Processes.Library;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
********************************************************************************/

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;
using Org.Eclipse.TractusX.Portal.Backend.Dim.Library.Models;
Expand Down
2 changes: 0 additions & 2 deletions src/framework/Framework.Seeding/Framework.Seeding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />

<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions src/framework/Framework.Seeding/SeederHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

using Microsoft.Extensions.Logging;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Seeding.JsonHelper;
using System.Collections.Concurrent;
using System.Reflection;
using System.Text.Json;
Expand All @@ -31,7 +30,7 @@ public static class SeederHelper
{
private static readonly JsonSerializerOptions Options = new()
{
PropertyNamingPolicy = new SnakeCaseNamingPolicy(),
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
Converters = { new JsonDateTimeOffsetConverter() }
};

Expand Down
1 change: 0 additions & 1 deletion src/framework/Framework.Web/Framework.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Flurl.Signed" Version="3.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
Expand Down
8 changes: 2 additions & 6 deletions src/framework/Framework.Web/WebApplicationBuildRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Flurl.Util;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -64,11 +63,8 @@ public static async Task BuildAndRunWebApplicationAsync<TProgram>(
if (healthCheckPaths != null)
{
configuration
.Filter.ByExcluding(le =>
{
return le.Properties.TryGetValue("RequestPath", out var logProperty) &&
logProperty.ToKeyValuePairs().Any(x => healthCheckPaths.Contains(x.Value));
});
.Filter.ByExcluding(le => le.Properties.TryGetValue("RequestPath", out var logProperty) &&
healthCheckPaths.Contains(logProperty.ToString()));
}
});
builder.Services
Expand Down
35 changes: 19 additions & 16 deletions src/keycloak/Keycloak.ErrorHandling/FlurlErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,34 @@ public static class FlurlErrorHandler
{
public static void ConfigureErrorHandler(ILogger logger)
{
FlurlHttp.Configure(settings => settings.OnError = (call) =>
FlurlHttp.Clients.WithDefaults(c => c.OnError(call =>
{
var message = $"{call.HttpResponseMessage?.ReasonPhrase ?? "ReasonPhrase is null"}: {call.HttpRequestMessage.RequestUri}";

if (logger.IsEnabled(LogLevel.Debug))
{
LogDebug(logger, call);
}
if (call.HttpResponseMessage != null)

if (call.HttpResponseMessage is null)
{
throw new ServiceException(message, call.Exception);
}

var errorContent = JsonSerializer.Deserialize<KeycloakErrorResponse>(call.HttpResponseMessage.Content.ReadAsStream())?.ErrorMessage;
if (!string.IsNullOrWhiteSpace(errorContent))
{
var errorContent = JsonSerializer.Deserialize<KeycloakErrorResponse>(call.HttpResponseMessage.Content.ReadAsStream())?.ErrorMessage;
if (!string.IsNullOrWhiteSpace(errorContent))
{
message = errorContent;
}
throw call.HttpResponseMessage.StatusCode switch
{
HttpStatusCode.NotFound => new KeycloakEntityNotFoundException(message, call.Exception),
HttpStatusCode.Conflict => new KeycloakEntityConflictException(message, call.Exception),
HttpStatusCode.BadRequest => new KeycloakNoSuccessException(message, call.Exception),
_ => new ServiceException(message, call.Exception, call.HttpResponseMessage.StatusCode),
};
message = errorContent;
}
throw new ServiceException(message, call.Exception);
});

throw call.HttpResponseMessage.StatusCode switch
{
HttpStatusCode.NotFound => new KeycloakEntityNotFoundException(message, call.Exception),
HttpStatusCode.Conflict => new KeycloakEntityConflictException(message, call.Exception),
HttpStatusCode.BadRequest => new KeycloakNoSuccessException(message, call.Exception),
_ => new ServiceException(message, call.Exception, call.HttpResponseMessage.StatusCode),
};
}));
}

private static void LogDebug(ILogger logger, FlurlCall call)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
********************************************************************************/

using Flurl.Http;
using Flurl.Http.Configuration;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;

namespace Org.Eclipse.TractusX.Portal.Backend.Keycloak.ErrorHandling;

Expand All @@ -30,25 +28,9 @@ public static void ConfigureExceptions(IEnumerable<string> urlsToTrust)
{
foreach (var urlToTrust in urlsToTrust)
{
FlurlHttp.ConfigureClient(urlToTrust, cli => cli.Settings.HttpClientFactory = new UntrustedCertHttpClientFactory());
FlurlHttp
.ConfigureClientForUrl(urlToTrust)
.ConfigureInnerHandler(chc => chc.ServerCertificateCustomValidationCallback = (_, _, _, _) => true);

Check failure

Code scanning / SonarCloud

Server certificates should be verified during SSL/TLS connections High

Enable server certificate validation on this SSL/TLS connection See more on SonarCloud
}
}
}

public class UntrustedCertHttpClientFactory : DefaultHttpClientFactory
{
public override HttpMessageHandler CreateMessageHandler()
{
var handler = base.CreateMessageHandler();
var httpClientHander = handler as HttpClientHandler;
if (httpClientHander != null)
{
httpClientHander.ServerCertificateCustomValidationCallback = (_, _, _, _) => true;
}
else
{
throw new ConfigurationException($"flurl HttpMessageHandler's type is not HttpClientHandler but {handler.GetType()}");
}
return handler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Flurl.Http.Signed" Version="3.2.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Flurl.Http.Signed" Version="4.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
</ItemGroup>

Expand Down
31 changes: 10 additions & 21 deletions src/keycloak/Keycloak.Factory/KeycloakFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,25 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Flurl.Http.Configuration;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Keycloak.Library;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Org.Eclipse.TractusX.Portal.Backend.Keycloak.Factory;

public class KeycloakFactory : IKeycloakFactory
public class KeycloakFactory(IOptions<KeycloakSettingsMap> settings)
: IKeycloakFactory
{
private readonly KeycloakSettingsMap _settings;
private readonly KeycloakSettingsMap _settings = settings.Value;

private static readonly JsonSerializerSettings SerializerSettings = new()
private static readonly JsonSerializerOptions SerializerSettings = new()
{
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy
{
ProcessDictionaryKeys = false
}
}
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};

public KeycloakFactory(IOptions<KeycloakSettingsMap> settings)
{
_settings = settings.Value;
}

public KeycloakClient CreateKeycloakClient(string instance)
{
if (!_settings.Keys.Contains(instance, StringComparer.InvariantCultureIgnoreCase))
Expand All @@ -59,7 +48,7 @@ public KeycloakClient CreateKeycloakClient(string instance)
var keycloakClient = settings.ClientSecret == null
? new KeycloakClient(settings.ConnectionString, settings.User, settings.Password, settings.AuthRealm, settings.UseAuthTrail)
: KeycloakClient.CreateWithClientId(settings.ConnectionString, settings.ClientId, settings.ClientSecret, settings.UseAuthTrail, settings.AuthRealm);
keycloakClient.SetSerializer(new NewtonsoftJsonSerializer(SerializerSettings));
keycloakClient.SetSerializer(SerializerSettings);

return keycloakClient;
}
Expand All @@ -73,7 +62,7 @@ public KeycloakClient CreateKeycloakClient(string instance, string clientId, str

var settings = _settings.Single(x => x.Key.Equals(instance, StringComparison.InvariantCultureIgnoreCase)).Value;
var keycloakClient = KeycloakClient.CreateWithClientId(settings.ConnectionString, clientId, secret, settings.UseAuthTrail, settings.AuthRealm);
keycloakClient.SetSerializer(new NewtonsoftJsonSerializer(SerializerSettings));
keycloakClient.SetSerializer(SerializerSettings);

return keycloakClient;
}
Expand Down
Loading

0 comments on commit 1eca288

Please sign in to comment.