From 88c75fbe1ed2ea8cb8a40eb48ab7f5a70c59c6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ndor=20Kolumb=C3=A1n?= Date: Mon, 11 Nov 2024 09:52:54 +0200 Subject: [PATCH 1/7] Fix hashing issue for float values. --- .../ObjectHashServer.API.csproj | 54 +++++++++++-------- ObjectHashServer.API/ObjectHasherFunctions.cs | 24 +++++---- ObjectHashServer.API/Program.cs | 16 ++++++ ObjectHashServer.API/host.json | 17 +++--- 4 files changed, 70 insertions(+), 41 deletions(-) create mode 100644 ObjectHashServer.API/Program.cs diff --git a/ObjectHashServer.API/ObjectHashServer.API.csproj b/ObjectHashServer.API/ObjectHashServer.API.csproj index dd3a772..c12c47f 100644 --- a/ObjectHashServer.API/ObjectHashServer.API.csproj +++ b/ObjectHashServer.API/ObjectHashServer.API.csproj @@ -1,23 +1,33 @@ - - - net6.0 - v4 - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - Never - - + + + net8.0 + v4 + Exe + enable + enable + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + diff --git a/ObjectHashServer.API/ObjectHasherFunctions.cs b/ObjectHashServer.API/ObjectHasherFunctions.cs index 504d7c4..313ded8 100644 --- a/ObjectHashServer.API/ObjectHasherFunctions.cs +++ b/ObjectHashServer.API/ObjectHasherFunctions.cs @@ -1,19 +1,21 @@ using System; using System.IO; using System.Net; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Extensions.Http; -using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes; +using Microsoft.Azure.Functions.Worker; using Microsoft.OpenApi.Models; +using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Extensions; +using Microsoft.Azure.Functions.Worker.Http; + + using Newtonsoft.Json; using Newtonsoft.Json.Linq; using ObjectHashServer.BLL.Models; using ObjectHashServer.BLL.Models.Api.Request; using ObjectHashServer.BLL.Models.Api.Response; using ObjectHashServer.BLL.Services.Implementations; +using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; namespace ObjectHashServer.API { @@ -26,12 +28,12 @@ public class ObjectHasherFunctions /// Successful call /// Not Found /// Internal Server Error - [FunctionName("HashObject")] + [Function("HashObject")] [OpenApiOperation(operationId: "hash-object", Description = "Generates salts for the recieved json.")] [OpenApiRequestBody(contentType: "application/json", bodyType: typeof(JObject), Description = "Json for which the salts should be generated.", Required = true)] [OpenApiParameter(name: "generateSalts", In = ParameterLocation.Query, Required = true, Type = typeof(bool), Description = "Generate salts?")] [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(ObjectHashResponseModel), Description = "The generated/hashed result for the given json.")] - public async Task> HashObject([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "hash-object")] HttpRequest req) + public async Task HashObject([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "hash-object")] HttpRequest req) { try { @@ -62,7 +64,7 @@ public async Task> HashObject([HttpTrigger if (!generateSalts) requestModel.Salts = null; - return new ObjectHashResponseModel(new ObjectHash(requestModel)); + return new OkObjectResult(new ObjectHashResponseModel(new ObjectHash(requestModel))); } catch (Exception e) { @@ -79,7 +81,7 @@ public async Task> HashObject([HttpTrigger /// Successful call /// Not Found /// Internal Server Error - [FunctionName("ReHashObject")] + [Function("ReHashObject")] [OpenApiOperation(operationId: "rehash-object", Description = "Generates the hash for the recieved ObjectBaseRequestModel.")] [OpenApiRequestBody(contentType: "application/json", bodyType: typeof(ObjectBaseRequestModel), Description = "ObjectBaseRequestModel for which the hash should be generated.", Required = true)] [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(ObjectHashResponseModel), Description = "The generated ObjectHashResponseModel containing the generated hash.")] @@ -118,7 +120,7 @@ public async Task> ReHashObject([HttpTrigg /// Successful call /// Not Found /// Internal Server Error - [FunctionName("RedactObject")] + [Function("RedactObject")] [OpenApiOperation(operationId: "redact-object", Description = "Calculates the redacted JSON given a settings file.")] [OpenApiRequestBody(contentType: "application/json", bodyType: typeof(ObjectRedactionRequestModel), Description = "ObjectRedactionRequestModel for which the redacted JSON should be calculated.", Required = true)] [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(ObjectRedactionResponseModel), Description = "ObjectRedactionResponseModel containing the redacted JSON.")] diff --git a/ObjectHashServer.API/Program.cs b/ObjectHashServer.API/Program.cs new file mode 100644 index 0000000..4672a7c --- /dev/null +++ b/ObjectHashServer.API/Program.cs @@ -0,0 +1,16 @@ +using Microsoft.Azure.Functions.Worker; +using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Extensions; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +var host = new HostBuilder() + .ConfigureFunctionsWebApplication() + .ConfigureOpenApi() // Ensure OpenAPI is configured + .ConfigureServices(services => + { + services.AddApplicationInsightsTelemetryWorkerService(); + services.ConfigureFunctionsApplicationInsights(); + }) + .Build(); + +host.Run(); \ No newline at end of file diff --git a/ObjectHashServer.API/host.json b/ObjectHashServer.API/host.json index beb2e40..5df170b 100644 --- a/ObjectHashServer.API/host.json +++ b/ObjectHashServer.API/host.json @@ -1,11 +1,12 @@ { - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - } + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + }, + "enableLiveMetricsFilters": true } + } } \ No newline at end of file From 022081c8bfab851bc820494746241a6cccab525d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ndor=20Kolumb=C3=A1n?= Date: Mon, 11 Nov 2024 09:53:22 +0200 Subject: [PATCH 2/7] Fix hashing issues for 0.5. --- .../Services/Implementations/ObjectHashImplementation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectHashServer.BLL/Services/Implementations/ObjectHashImplementation.cs b/ObjectHashServer.BLL/Services/Implementations/ObjectHashImplementation.cs index ca4b4d2..1c610c4 100644 --- a/ObjectHashServer.BLL/Services/Implementations/ObjectHashImplementation.cs +++ b/ObjectHashServer.BLL/Services/Implementations/ObjectHashImplementation.cs @@ -336,7 +336,7 @@ private static string NormalizeDouble(double d) e += 1; } - while (d < 0.5) + while (d <= 0.5) { d *= 2; e -= 1; From 297a7d6c10d8c6607f1a751ce69117d503b22c62 Mon Sep 17 00:00:00 2001 From: SaroltaMihaly Date: Mon, 11 Nov 2024 10:52:07 +0200 Subject: [PATCH 3/7] CRY-23 | Migrate project to .Net 8 isolated, added json support --- ObjectHashServer.API/ObjectHasherFunctions.cs | 8 ++++---- ObjectHashServer.API/Program.cs | 15 ++++++++++++++- ObjectHashServer.BLL/ObjectHashServer.BLL.csproj | 2 +- ObjectHashServer/src/ObjectHashServer.csproj | 2 +- .../ObjectHashServer.UnitTests.csproj | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/ObjectHashServer.API/ObjectHasherFunctions.cs b/ObjectHashServer.API/ObjectHasherFunctions.cs index 313ded8..1cdbad7 100644 --- a/ObjectHashServer.API/ObjectHasherFunctions.cs +++ b/ObjectHashServer.API/ObjectHasherFunctions.cs @@ -85,7 +85,7 @@ public async Task HashObject([HttpTrigger(AuthorizationLevel.Anon [OpenApiOperation(operationId: "rehash-object", Description = "Generates the hash for the recieved ObjectBaseRequestModel.")] [OpenApiRequestBody(contentType: "application/json", bodyType: typeof(ObjectBaseRequestModel), Description = "ObjectBaseRequestModel for which the hash should be generated.", Required = true)] [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(ObjectHashResponseModel), Description = "The generated ObjectHashResponseModel containing the generated hash.")] - public async Task> ReHashObject([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "rehash-object")] HttpRequest req) + public async Task ReHashObject([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "rehash-object")] HttpRequest req) { try { @@ -103,7 +103,7 @@ public async Task> ReHashObject([HttpTrigg return result; } - return new ObjectHashResponseModel(new ObjectHash(requestModel)); + return new OkObjectResult(new ObjectHashResponseModel(new ObjectHash(requestModel))); } catch (Exception e) { @@ -124,7 +124,7 @@ public async Task> ReHashObject([HttpTrigg [OpenApiOperation(operationId: "redact-object", Description = "Calculates the redacted JSON given a settings file.")] [OpenApiRequestBody(contentType: "application/json", bodyType: typeof(ObjectRedactionRequestModel), Description = "ObjectRedactionRequestModel for which the redacted JSON should be calculated.", Required = true)] [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(ObjectRedactionResponseModel), Description = "ObjectRedactionResponseModel containing the redacted JSON.")] - public async Task> RedactObject([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "redact-object")] HttpRequest req) + public async Task RedactObject([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "redact-object")] HttpRequest req) { try { @@ -143,7 +143,7 @@ public async Task> RedactObject([Http } ObjectRedactionImplementation.RedactJToken(requestModel.Data, requestModel.RedactSettings, requestModel.Salts); - return new ObjectRedactionResponseModel(new ObjectRedaction(requestModel)); + return new OkObjectResult(new ObjectRedactionResponseModel(new ObjectRedaction(requestModel))); } catch (Exception e) { diff --git a/ObjectHashServer.API/Program.cs b/ObjectHashServer.API/Program.cs index 4672a7c..3ab008e 100644 --- a/ObjectHashServer.API/Program.cs +++ b/ObjectHashServer.API/Program.cs @@ -1,7 +1,10 @@ -using Microsoft.Azure.Functions.Worker; +using Azure.Core.Serialization; +using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Extensions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Newtonsoft.Json.Serialization; +using Newtonsoft.Json; var host = new HostBuilder() .ConfigureFunctionsWebApplication() @@ -10,6 +13,16 @@ { services.AddApplicationInsightsTelemetryWorkerService(); services.ConfigureFunctionsApplicationInsights(); + services.Configure(workerOptions => + { + var settings = NewtonsoftJsonObjectSerializer.CreateJsonSerializerSettings(); + settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + settings.NullValueHandling = NullValueHandling.Ignore; + + workerOptions.Serializer = new NewtonsoftJsonObjectSerializer(settings); + }); + + services.AddMvcCore().AddNewtonsoftJson(); }) .Build(); diff --git a/ObjectHashServer.BLL/ObjectHashServer.BLL.csproj b/ObjectHashServer.BLL/ObjectHashServer.BLL.csproj index f6b7cd6..0093bda 100644 --- a/ObjectHashServer.BLL/ObjectHashServer.BLL.csproj +++ b/ObjectHashServer.BLL/ObjectHashServer.BLL.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable disable diff --git a/ObjectHashServer/src/ObjectHashServer.csproj b/ObjectHashServer/src/ObjectHashServer.csproj index 3b9a30b..85fcb97 100644 --- a/ObjectHashServer/src/ObjectHashServer.csproj +++ b/ObjectHashServer/src/ObjectHashServer.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 diff --git a/ObjectHashServer/test/ObjectHashServer.UnitTests/ObjectHashServer.UnitTests.csproj b/ObjectHashServer/test/ObjectHashServer.UnitTests/ObjectHashServer.UnitTests.csproj index 240569b..38aa0df 100644 --- a/ObjectHashServer/test/ObjectHashServer.UnitTests/ObjectHashServer.UnitTests.csproj +++ b/ObjectHashServer/test/ObjectHashServer.UnitTests/ObjectHashServer.UnitTests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false From dba6071baabd67226aacfd674c143349d42f1f96 Mon Sep 17 00:00:00 2001 From: SaroltaMihaly Date: Mon, 11 Nov 2024 11:00:37 +0200 Subject: [PATCH 4/7] CRY-23 | Changed dotnet version in workflows --- .github/workflows/notarization-objecthash.yml | 2 +- .github/workflows/test-production.yml | 2 +- .github/workflows/test-staging.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/notarization-objecthash.yml b/.github/workflows/notarization-objecthash.yml index 5844a88..72caa56 100644 --- a/.github/workflows/notarization-objecthash.yml +++ b/.github/workflows/notarization-objecthash.yml @@ -7,7 +7,7 @@ env: AZURE_FUNCTIONAPP_NAME: notarization-objecthash AZURE_FUNCTIONAPP_PACKAGE_PATH: ObjectHashServer.API\. CONFIGURATION: Release - DOTNET_CORE_VERSION: 6.0.x + DOTNET_CORE_VERSION: 8.0.x WORKING_DIRECTORY: ObjectHashServer.API jobs: build-and-deploy: diff --git a/.github/workflows/test-production.yml b/.github/workflows/test-production.yml index c6e1e71..d72e9dd 100644 --- a/.github/workflows/test-production.yml +++ b/.github/workflows/test-production.yml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Install dependencies run: dotnet restore - name: Build master diff --git a/.github/workflows/test-staging.yml b/.github/workflows/test-staging.yml index 76f21e6..97b91c9 100644 --- a/.github/workflows/test-staging.yml +++ b/.github/workflows/test-staging.yml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Install dependencies run: dotnet restore - name: Build master From f20046a73a60646fadc482fcfaa71edd6903bc6b Mon Sep 17 00:00:00 2001 From: SaroltaMihaly Date: Mon, 11 Nov 2024 11:26:32 +0200 Subject: [PATCH 5/7] CRY-23 | Removed obsolete references from Startup --- ObjectHashServer/src/Startup.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ObjectHashServer/src/Startup.cs b/ObjectHashServer/src/Startup.cs index a2dcc0c..bff334d 100644 --- a/ObjectHashServer/src/Startup.cs +++ b/ObjectHashServer/src/Startup.cs @@ -12,9 +12,9 @@ namespace ObjectHashServer public class Startup { private readonly IConfiguration _configuration; - private readonly IWebHostEnvironment _environment; + private readonly IHostEnvironment _environment; - public Startup(IConfiguration configuration, IWebHostEnvironment environment) + public Startup(IConfiguration configuration, IHostEnvironment environment) { _configuration = configuration; _environment = environment; @@ -33,7 +33,7 @@ public void ConfigureServices(IServiceCollection services) services.AddMvc(config => { config.Filters.Add(new ExceptionHandlerFilterAttribute()); - }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0).AddNewtonsoftJson(); + }).AddNewtonsoftJson(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. From 0d5c96c15765451b41f541fa94055bc5b55c6200 Mon Sep 17 00:00:00 2001 From: SaroltaMihaly Date: Mon, 11 Nov 2024 11:39:08 +0200 Subject: [PATCH 6/7] CRY-23 | Removed obsolete references from ExceptionHandlerFilterAttribute --- ObjectHashServer.BLL/Utils/ExceptionHandlerFilterAttribute.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ObjectHashServer.BLL/Utils/ExceptionHandlerFilterAttribute.cs b/ObjectHashServer.BLL/Utils/ExceptionHandlerFilterAttribute.cs index 9e7c1b9..d93c296 100644 --- a/ObjectHashServer.BLL/Utils/ExceptionHandlerFilterAttribute.cs +++ b/ObjectHashServer.BLL/Utils/ExceptionHandlerFilterAttribute.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using ObjectHashServer.BLL.Exceptions; using ObjectHashServer.BLL.Models.Api.Response; @@ -62,7 +63,7 @@ public override void OnException(ExceptionContext context) logger.LogError(0, exception, exception.Message); } - IHostingEnvironment env = context.HttpContext.RequestServices.GetRequiredService(); + IHostEnvironment env = context.HttpContext.RequestServices.GetRequiredService(); if (env.IsDevelopment()) { errorModel.ExceptionMessage = exception.Message; From 715ac02a1c366964a838771738f05a900c51c9fc Mon Sep 17 00:00:00 2001 From: SaroltaMihaly Date: Mon, 11 Nov 2024 11:53:38 +0200 Subject: [PATCH 7/7] CRY-23 | Removed local.settings.json references from project --- ObjectHashServer.API/ObjectHashServer.API.csproj | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ObjectHashServer.API/ObjectHashServer.API.csproj b/ObjectHashServer.API/ObjectHashServer.API.csproj index c12c47f..3cde665 100644 --- a/ObjectHashServer.API/ObjectHashServer.API.csproj +++ b/ObjectHashServer.API/ObjectHashServer.API.csproj @@ -8,7 +8,6 @@ - @@ -25,9 +24,5 @@ PreserveNewest - - PreserveNewest - Never -