< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.DataRetentionRegistrationExtensions
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/ci/agent/workspace/heimdall-api-docs_main/app/src/Presentation/ArturRios.Heimdall.WebApi/Registration/DataRetentionRegistrationExtensions.cs
Line coverage
53%
Covered lines: 21
Uncovered lines: 18
Coverable lines: 39
Total lines: 99
Line coverage: 53.8%
Branch coverage
50%
Covered branches: 5
Total branches: 10
Branch coverage: 50%
Method coverage
100%
Covered methods: 1
Fully covered methods: 0
Total methods: 1
Method coverage: 100%
Full method coverage: 0%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddDataRetention(...)50%201053.84%

File(s)

/home/ci/agent/workspace/heimdall-api-docs_main/app/src/Presentation/ArturRios.Heimdall.WebApi/Registration/DataRetentionRegistrationExtensions.cs

#LineLine coverage
 1using ArturRios.Data.Relational.Core.DependencyInjection;
 2using ArturRios.Heimdall.Command.Auditing;
 3using ArturRios.Heimdall.Command.Handlers;
 4using ArturRios.Heimdall.Command.Input;
 5using ArturRios.Heimdall.Command.Output;
 6using ArturRios.Heimdall.Shared.Retention;
 7using ArturRios.Heimdall.WebApi.Monitoring;
 8using ArturRios.Heimdall.WebApi.Retention;
 9using ArturRios.Util.WebApi.Configuration;
 10using ArturRios.Util.WebApi.Security.Extensions;
 11using Serilog;
 12
 13namespace ArturRios.Heimdall.WebApi;
 14
 15public static class DataRetentionRegistrationExtensions
 16{
 17    /// <summary>
 18    ///     Registers the retention schedule (NFR-19) and the pass that enforces it.
 19    /// </summary>
 20    /// <remarks>
 21    ///     The options are a singleton because they are a deployment-wide policy read once at
 22    ///     start-up, and the purge is registered as a hosted service unless it has been switched
 23    ///     off — which is a deployment decision an operator has to take deliberately, since keeping
 24    ///     personal data past its retention period is the thing NFR-19 forbids. The handler is
 25    ///     registered audited like every other command: the entry recording that the schedule was
 26    ///     enforced is as much the point as the deletion is.
 27    /// </remarks>
 28    public static IServiceCollection AddDataRetention(this IServiceCollection services)
 29    {
 97330        var retention = DataRetentionOptions.FromEnvironment();
 31
 97332        if (retention.InvalidVariables.Count > 0)
 33        {
 034            Log.Warning(
 035                "Ignoring unusable retention settings and applying the documented defaults: {Variables}",
 036                retention.InvalidVariables);
 37        }
 38
 97339        services.AddSingleton(retention);
 97340        services
 97341            .AddAuditedCommandHandler<PurgeExpiredTokensCommand, PurgeExpiredTokensCommandOutput,
 97342                PurgeExpiredTokensCommandHandler>();
 97343        services
 97344            .AddAuditedCommandHandler<AnonymiseExpiredDeletionsCommand, AnonymiseExpiredDeletionsCommandOutput,
 97345                AnonymiseExpiredDeletionsCommandHandler>();
 97346        services
 97347            .AddAuditedCommandHandler<PseudonymiseAuditActorsCommand, PseudonymiseAuditActorsCommandOutput,
 97348                PseudonymiseAuditActorsCommandHandler>();
 49
 97350        if (retention.PurgeEnabled)
 51        {
 97352            services.AddHostedService<TokenRetentionService>();
 53        }
 54        else
 55        {
 056            Log.Warning(
 057                "The token retention purge is switched off by {Variable}; expired tokens will not be removed",
 058                DataRetentionOptions.PurgeEnabledVariable);
 59        }
 60
 97361        if (retention.AnonymisationEnabled)
 62        {
 97363            services.AddHostedService<IdentityAnonymisationService>();
 64        }
 65        else
 66        {
 067            Log.Warning(
 068                "Identity anonymisation is switched off by {Variable}; logically deleted identities " +
 069                "will be kept past their retention window",
 070                DataRetentionOptions.AnonymisationEnabledVariable);
 71        }
 72
 97373        if (retention.SecurityMonitoringEnabled)
 74        {
 97375            services.AddHostedService<SecurityMonitoringService>();
 76        }
 77        else
 78        {
 079            Log.Warning(
 080                "Security signal detection is switched off by {Variable}; the audit trail and lockout " +
 081                "counters will keep recording what happens and nobody will be told about it",
 082                DataRetentionOptions.SecurityMonitoringEnabledVariable);
 83        }
 84
 97385        if (retention.AuditPseudonymisationEnabled)
 86        {
 97387            services.AddHostedService<AuditRetentionService>();
 88        }
 89        else
 90        {
 091            Log.Warning(
 092                "Audit attribution pseudonymisation is switched off by {Variable}; the trail will " +
 093                "keep naming people past its attribution period, including erased ones",
 094                DataRetentionOptions.AuditPseudonymisationEnabledVariable);
 95        }
 96
 97397        return services;
 98    }
 99}