From 340d0c40cdf813b04127f8b49de347d2bc81382e Mon Sep 17 00:00:00 2001 From: Ivar Nesje Date: Fri, 26 May 2023 16:08:24 +0200 Subject: [PATCH] A few minor fixes (#36) * Use cached layers for Dockerfile to improve build times locally. * Set longer expiration on the cookie that remembers your prefered user * Ignore a few nullability warnings to make the build warning free ** I don't have any idea about better error handeling than a NullPointerException so I just ignore with ! --- Dockerfile | 8 ++++---- src/Controllers/HomeController.cs | 4 ++-- src/Services/LocalApp/Implementation/LocalAppHttp.cs | 4 ++-- src/Services/Register/Implementation/PartiesWrapper.cs | 4 ++-- src/Services/TestData/TestDataService.cs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 544ad4b7..d9db89b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build - -COPY ./src ./src - WORKDIR /src + +COPY ./src/LocalTest.csproj . RUN dotnet restore LocalTest.csproj -RUN dotnet build LocalTest.csproj -c Release -o /app_output + +COPY ./src . RUN dotnet publish LocalTest.csproj -c Release -o /app_output FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine AS final diff --git a/src/Controllers/HomeController.cs b/src/Controllers/HomeController.cs index 539e9e49..d09aed87 100644 --- a/src/Controllers/HomeController.cs +++ b/src/Controllers/HomeController.cs @@ -456,7 +456,7 @@ private void CreateJwtCookieAndAppendToResponse(string identityCookie, int altin SecurePolicy = CookieSecurePolicy.None, IsEssential = true, Domain = _generalSettings.Hostname, - Expiration = new TimeSpan(0, 1337, 0) + MaxAge = TimeSpan.FromDays(365), }; CookieOptions partyCookieOptions = partyCookieBuilder.Build(HttpContext); cookieManager.AppendResponseCookie( @@ -474,7 +474,7 @@ private void CreateJwtCookieAndAppendToResponse(string identityCookie, int altin SecurePolicy = CookieSecurePolicy.None, IsEssential = true, Domain = _generalSettings.Hostname, - Expiration = TimeSpan.MaxValue, + MaxAge = TimeSpan.FromDays(365), }; CookieOptions userSelectCookieOptions = cookieBuilder.Build(HttpContext); cookieManager.AppendResponseCookie( diff --git a/src/Services/LocalApp/Implementation/LocalAppHttp.cs b/src/Services/LocalApp/Implementation/LocalAppHttp.cs index 0d2ef283..ad84ed02 100644 --- a/src/Services/LocalApp/Implementation/LocalAppHttp.cs +++ b/src/Services/LocalApp/Implementation/LocalAppHttp.cs @@ -60,7 +60,7 @@ public LocalAppHttp(IOptions generalSettings, IHttpClientFactor return await _httpClient.GetStringAsync($"{appId}/api/v1/applicationmetadata?checkOrgApp=false"); }); - return JsonSerializer.Deserialize(content, JSON_OPTIONS); + return JsonSerializer.Deserialize(content!, JSON_OPTIONS); } public async Task GetTextResource(string org, string app, string language) @@ -71,7 +71,7 @@ public LocalAppHttp(IOptions generalSettings, IHttpClientFactor return await _httpClient.GetStringAsync($"{org}/{app}/api/v1/texts/{language}"); }); - var textResource = JsonSerializer.Deserialize(content, JSON_OPTIONS); + var textResource = JsonSerializer.Deserialize(content!, JSON_OPTIONS); if (textResource != null) { textResource.Id = $"{org}-{app}-{language}"; diff --git a/src/Services/Register/Implementation/PartiesWrapper.cs b/src/Services/Register/Implementation/PartiesWrapper.cs index 4ad19ce4..ac0611c8 100644 --- a/src/Services/Register/Implementation/PartiesWrapper.cs +++ b/src/Services/Register/Implementation/PartiesWrapper.cs @@ -53,10 +53,10 @@ public async Task LookupPartyIdBySSNOrOrgNo(string lookupValue) } /// - public async Task> GetPartyList(List partyIds) + public async Task> GetPartyList(List partyIds) { var data = await _testDataService.GetTestData(); - List filteredList = new List(); + List filteredList = new List(); foreach (int partyId in partyIds.Distinct()) { Party? party = data.Register.Party.TryGetValue(partyId.ToString()!, out var value) ? value : null; diff --git a/src/Services/TestData/TestDataService.cs b/src/Services/TestData/TestDataService.cs index 8a4e439b..aca43d46 100644 --- a/src/Services/TestData/TestDataService.cs +++ b/src/Services/TestData/TestDataService.cs @@ -22,7 +22,7 @@ public TestDataService(ILocalApp localApp, IOptions setti public async Task GetTestData() { - return await _cache.GetOrCreateAsync("TEST_DATA", + return (await _cache.GetOrCreateAsync("TEST_DATA", async (entry) => { entry.SlidingExpiration = TimeSpan.FromSeconds(5); @@ -43,6 +43,6 @@ public async Task GetTestData() } return await TestDataDiskReader.ReadFromDisk(_settings.LocalTestingStaticTestDataPath); - }); + }))!; } }