Skip to content

Commit

Permalink
clean up program.cs, fixed null in createresponse
Browse files Browse the repository at this point in the history
  • Loading branch information
erlendoksvoll committed Nov 14, 2023
1 parent 6f1a089 commit 2cb122e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
Expand All @@ -7,8 +7,8 @@
<UseAppHost>false</UseAppHost>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.5.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.3.0" />
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
<PackageReference Include="Dan.Common" Version="1.4.0" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Core.NewtonsoftJson" Version="1.0.0" />
Expand Down
14 changes: 8 additions & 6 deletions src/Altinn.Dan.Plugin.Pensjon/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,31 @@ public async Task<HttpResponseData> GetNorskPensjon(
var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var evidenceHarvesterRequest = JsonConvert.DeserializeObject<EvidenceHarvesterRequest>(requestBody);

return await EvidenceSourceResponse.CreateResponse(null, () => GetEvidenceValuesPensjon(evidenceHarvesterRequest));
return await EvidenceSourceResponse.CreateResponse(req, () => GetEvidenceValuesPensjon(evidenceHarvesterRequest));
}

private async Task<List<EvidenceValue>> GetEvidenceValuesPensjon(EvidenceHarvesterRequest evidenceHarvesterRequest)
{
var content = await MakeRequest(_settings.NorskPensjonUrl, evidenceHarvesterRequest.SubjectParty);

var ecb = new EvidenceBuilder(new Metadata(), "NorskPensjon");
ecb.AddEvidenceValue($"default", content, Metadata.SOURCE, false);
ecb.AddEvidenceValue("default", content, Metadata.SOURCE, false);

return ecb.GetEvidenceValues();
}

private async Task<string> MakeRequest(string target, Party subject)
{
HttpResponseMessage result = null;
var requestBody = new NorskPensjonRequest();
requestBody.Fodselsnummer = subject.NorwegianSocialSecurityNumber;
var requestBody = new NorskPensjonRequest
{
Fodselsnummer = subject.NorwegianSocialSecurityNumber
};

try
{
var request = new HttpRequestMessage(HttpMethod.Post, target);
request.Content = new StringContent(JsonConvert.SerializeObject(requestBody), Encoding.UTF8,
"application/json");
request.Content = new StringContent(JsonConvert.SerializeObject(requestBody), Encoding.UTF8, "application/json");
result = await _client.SendAsync(request);
switch (result.StatusCode)
{
Expand Down
15 changes: 2 additions & 13 deletions src/Altinn.Dan.Plugin.Pensjon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net.Http;
using System.Threading.Tasks;
using Altinn.Dan.Plugin.Pensjon.Config;
using Dan.Common.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -19,14 +20,9 @@ class Program
private static Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureDanPluginDefaults()
.ConfigureServices(services =>
{
services.AddLogging();
// See https://docs.microsoft.com/en-us/azure/azure-monitor/app/worker-service#using-application-insights-sdk-for-worker-services
services.AddApplicationInsightsTelemetryWorkerService();
services.AddHttpClient();

services.AddOptions<ApplicationSettings>()
.Configure<IConfiguration>((settings, configuration) => configuration.Bind(settings));
ApplicationSettings = services.BuildServiceProvider().GetRequiredService<IOptions<ApplicationSettings>>().Value;
Expand All @@ -42,13 +38,6 @@ private static Task Main(string[] args)

return handler;
});

JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new List<JsonConverter>() { new StringEnumConverter() }
};
})
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.1-release-20211109-01" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
Expand Down

0 comments on commit 2cb122e

Please sign in to comment.