Skip to content

Commit

Permalink
Revert "Implement IMaskinportenClient interface (#669)" (#713)
Browse files Browse the repository at this point in the history
This reverts commit d6bfccc.
  • Loading branch information
bjorntore authored Jul 10, 2024
1 parent 57ab8c4 commit 506fb06
Show file tree
Hide file tree
Showing 33 changed files with 42 additions and 1,994 deletions.
34 changes: 0 additions & 34 deletions src/Altinn.App.Api/Extensions/HttpClientBuilderExtensions.cs

This file was deleted.

61 changes: 0 additions & 61 deletions src/Altinn.App.Api/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Altinn.App.Core.Constants;
using Altinn.App.Core.Extensions;
using Altinn.App.Core.Features;
using Altinn.App.Core.Features.Maskinporten;
using Altinn.App.Core.Features.Maskinporten.Models;
using Altinn.Common.PEP.Authorization;
using Altinn.Common.PEP.Clients;
using AltinnCore.Authentication.JwtCookie;
Expand All @@ -17,7 +15,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Microsoft.FeatureManagement;
using Microsoft.IdentityModel.Tokens;
using OpenTelemetry;
Expand Down Expand Up @@ -68,7 +65,6 @@ IWebHostEnvironment env

services.AddPlatformServices(config, env);
services.AddAppServices(config, env);
services.AddMaskinportenClient();
services.ConfigureDataProtection();

var useOpenTelemetrySetting = config.GetValue<bool?>("AppSettings:UseOpenTelemetry");
Expand Down Expand Up @@ -100,50 +96,6 @@ IWebHostEnvironment env
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}

/// <summary>
/// <para>
/// Configures the <see cref="MaskinportenClient"/> service with a configuration object which will be static for the lifetime of the service.
/// </para>
/// <para>
/// If you have already provided a <see cref="MaskinportenSettings"/> configuration, either manually or
/// implicitly via <see cref="WebHostBuilderExtensions.ConfigureAppWebHost"/>, this will be overridden.
/// </para>
/// </summary>
/// <param name="services">The service collection</param>
/// <param name="configureOptions">
/// Action delegate that provides <see cref="MaskinportenSettings"/> configuration for the <see cref="MaskinportenClient"/> service
/// </param>
public static IServiceCollection ConfigureMaskinportenClient(
this IServiceCollection services,
Action<MaskinportenSettings> configureOptions
)
{
services.AddOptions<MaskinportenSettings>().Configure(configureOptions).ValidateDataAnnotations();

return services;
}

/// <summary>
/// Adds a singleton <see cref="AddMaskinportenClient"/> service to the service collection.
/// Binds <see cref="MaskinportenSettings"/>, either from `appsettings.json` or `maskinporten-settings.json` (if found).
/// <br/><br/>Note: This binding happens in <see cref="WebHostBuilderExtensions.AddMaskinportenSettingsFile"/>.
/// </summary>
/// <param name="services">The service collection</param>
private static IServiceCollection AddMaskinportenClient(this IServiceCollection services)
{
if (services.GetOptionsDescriptor<MaskinportenSettings>() is null)
{
services
.AddOptions<MaskinportenSettings>()
.BindConfiguration("MaskinportenSettings")
.ValidateDataAnnotations();
}

services.AddSingleton<IMaskinportenClient, MaskinportenClient>();

return services;
}

/// <summary>
/// Adds Application Insights to the service collection.
/// </summary>
Expand Down Expand Up @@ -460,19 +412,6 @@ private static void AddAntiforgery(IServiceCollection services)
services.TryAddSingleton<ValidateAntiforgeryTokenIfAuthCookieAuthorizationFilter>();
}

private static IServiceCollection RemoveOptions<TOptions>(this IServiceCollection services)
where TOptions : class
{
var descriptor = services.GetOptionsDescriptor<TOptions>();

if (descriptor is not null)
{
services.Remove(descriptor);
}

return services;
}

private static (string? Key, string? ConnectionString) GetAppInsightsConfig(
IConfiguration config,
IHostEnvironment env
Expand Down
32 changes: 0 additions & 32 deletions src/Altinn.App.Api/Extensions/WebHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Altinn.App.Core.Extensions;
using Altinn.App.Core.Features.Maskinporten;
using Altinn.App.Core.Features.Maskinporten.Models;
using Microsoft.Extensions.FileProviders;

namespace Altinn.App.Api.Extensions;

Expand Down Expand Up @@ -30,37 +27,8 @@ public static void ConfigureAppWebHost(this IWebHostBuilder builder, string[] ar
}

configBuilder.AddInMemoryCollection(config);

configBuilder.AddMaskinportenSettingsFile(context);

configBuilder.LoadAppConfig(args);
}
);
}

private static IConfigurationBuilder AddMaskinportenSettingsFile(
this IConfigurationBuilder configurationBuilder,
WebHostBuilderContext context
)
{
string jsonProvidedPath =
context.Configuration.GetValue<string>("MaskinportenSettingsFilepath")
?? "/mnt/app-secrets/maskinporten-settings.json";
string jsonAbsolutePath = Path.GetFullPath(jsonProvidedPath);

if (File.Exists(jsonAbsolutePath))
{
string jsonDir = Path.GetDirectoryName(jsonAbsolutePath) ?? string.Empty;
string jsonFile = Path.GetFileName(jsonAbsolutePath);

configurationBuilder.AddJsonFile(
provider: new PhysicalFileProvider(jsonDir),
path: jsonFile,
optional: true,
reloadOnChange: true
);
}

return configurationBuilder;
}
}
1 change: 0 additions & 1 deletion src/Altinn.App.Core/Altinn.App.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<PackageReference Include="JsonPatch.Net" Version="3.1.0" />
<PackageReference Include="JWTCookieAuthentication" Version="3.0.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="9.0.0-preview.5.24306.11" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NetEscapades.EnumGenerators" Version="1.0.0-beta09" PrivateAssets="all" ExcludeAssets="runtime" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ public class EformidlingStatusCheckEventHandler2 : IEventHandler
private readonly IEFormidlingClient _eFormidlingClient;
private readonly ILogger<EformidlingStatusCheckEventHandler2> _logger;
private readonly IHttpClientFactory _httpClientFactory;

#pragma warning disable CS0618 // 'member' is obsolete:
private readonly IMaskinportenTokenProvider _maskinportenTokenProvider;
#pragma warning restore CS0618

private readonly PlatformSettings _platformSettings;
private readonly GeneralSettings _generalSettings;

Expand All @@ -40,9 +36,7 @@ public EformidlingStatusCheckEventHandler2(
IEFormidlingClient eFormidlingClient,
IHttpClientFactory httpClientFactory,
ILogger<EformidlingStatusCheckEventHandler2> logger,
#pragma warning disable CS0618 // 'member' is obsolete:
IMaskinportenTokenProvider maskinportenTokenProvider,
#pragma warning restore CS0618
IOptions<PlatformSettings> platformSettings,
IOptions<GeneralSettings> generalSettings
)
Expand Down
17 changes: 0 additions & 17 deletions src/Altinn.App.Core/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using IProcessEngine = Altinn.App.Core.Internal.Process.IProcessEngine;
using IProcessReader = Altinn.App.Core.Internal.Process.IProcessReader;
Expand Down Expand Up @@ -106,7 +105,6 @@ IWebHostEnvironment env
#pragma warning restore CS0618 // Type or member is obsolete
services.AddHttpClient<IProcessClient, ProcessClient>();
services.AddHttpClient<IPersonClient, PersonClient>();
services.AddHybridCache();

services.TryAddTransient<IUserTokenProvider, UserTokenProvider>();
services.TryAddTransient<IAccessTokenGenerator, AccessTokenGenerator>();
Expand Down Expand Up @@ -369,19 +367,4 @@ private static void AddFileValidatorServices(IServiceCollection services)
services.TryAddTransient<IFileValidationService, FileValidationService>();
services.TryAddTransient<IFileValidatorFactory, FileValidatorFactory>();
}

internal static IEnumerable<ServiceDescriptor> GetOptionsDescriptors<TOptions>(this IServiceCollection services)
where TOptions : class
{
return services.Where(d =>
d.ServiceType == typeof(IConfigureOptions<TOptions>)
|| d.ServiceType == typeof(IOptionsChangeTokenSource<TOptions>)
);
}

internal static ServiceDescriptor? GetOptionsDescriptor<TOptions>(this IServiceCollection services)
where TOptions : class
{
return services.GetOptionsDescriptors<TOptions>().FirstOrDefault();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 506fb06

Please sign in to comment.