From de372742bcbe36550089cf92af607527ef0c2daf Mon Sep 17 00:00:00 2001 From: Timo Notheisen <65653426+tnotheis@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:47:31 +0100 Subject: [PATCH] Remove FilesSanityCheck (#992) --- .ci/fsc/buildContainerImage.js | 11 --- .ci/sc/buildContainerImage.js | 12 ---- .ci/sc/pushContainerImage.js | 11 --- .github/workflows/test.yml | 3 - .../src/FilesSanityCheck/Dockerfile | 36 ---------- .../Extensions/IConfigurationExtensions.cs | 42 ----------- .../FilesSanityCheck/FilesSanityCheck.csproj | 25 ------- .../Infrastructure/DataSource/DataSource.cs | 33 --------- .../Infrastructure/DataSource/IDataSource.cs | 10 --- .../Infrastructure/Reporter/IReporter.cs | 12 ---- .../Infrastructure/Reporter/LogReporter.cs | 58 ---------------- .../Infrastructure/SanityCheck/SanityCheck.cs | 64 ----------------- .../src/FilesSanityCheck/Program.cs | 60 ---------------- .../Properties/launchSettings.json | 15 ---- .../src/FilesSanityCheck/Worker.cs | 46 ------------- .../appsettings.Development.json | 8 --- .../src/FilesSanityCheck/appsettings.json | 12 ---- .../FilesSanityCheck.Tests.csproj | 25 ------- .../DataSource/FakeDataSource.cs | 20 ------ .../Infrastructure/Reporter/TestReporter.cs | 24 ------- .../Tests/SanityCheckTests.cs | 69 ------------------- .../Backbone.Tests.ArchUnit.csproj | 1 - Backbone.sln | 23 ------- 23 files changed, 620 deletions(-) delete mode 100755 .ci/fsc/buildContainerImage.js delete mode 100755 .ci/sc/buildContainerImage.js delete mode 100755 .ci/sc/pushContainerImage.js delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Dockerfile delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Extensions/IConfigurationExtensions.cs delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/FilesSanityCheck.csproj delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/DataSource/DataSource.cs delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/DataSource/IDataSource.cs delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/Reporter/IReporter.cs delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/Reporter/LogReporter.cs delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/SanityCheck/SanityCheck.cs delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Program.cs delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Properties/launchSettings.json delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/Worker.cs delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/appsettings.Development.json delete mode 100644 Applications/FilesSanityCheck/src/FilesSanityCheck/appsettings.json delete mode 100644 Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/FilesSanityCheck.Tests.csproj delete mode 100644 Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Infrastructure/DataSource/FakeDataSource.cs delete mode 100644 Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Infrastructure/Reporter/TestReporter.cs delete mode 100644 Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Tests/SanityCheckTests.cs diff --git a/.ci/fsc/buildContainerImage.js b/.ci/fsc/buildContainerImage.js deleted file mode 100755 index 943c97e885..0000000000 --- a/.ci/fsc/buildContainerImage.js +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env node - -import { $ } from "zx"; -import { getRequiredEnvVar } from "../lib.js"; - -const tag = getRequiredEnvVar("TAG"); - -const platforms = process.env.PLATFORMS ?? "linux/amd64,linux/arm64"; -const push = process.env.PUSH === "1" ? ["--push", "--provenance=true", "--sbom=true"] : ""; - -await $`docker buildx build --file ./Applications/FilesSanityCheck/src/FilesSanityCheck/Dockerfile --tag ghcr.io/nmshd/backbone-files-sanity-check:${tag} --platform ${platforms} --build-arg VERSION=${tag} ${push} .`; diff --git a/.ci/sc/buildContainerImage.js b/.ci/sc/buildContainerImage.js deleted file mode 100755 index d34b868a82..0000000000 --- a/.ci/sc/buildContainerImage.js +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env node - -import { $ } from "zx"; -import { getRequiredEnvVar, toCamelCase } from "../lib.js"; - -const tag = getRequiredEnvVar("TAG"); -const moduleName = getRequiredEnvVar("MODULE"); -const projectSuffix = $.env["PROJECT_SUFFIX"] ? `.${$.env["PROJECT_SUFFIX"]}` : ""; - -const moduleNameCamelCase = toCamelCase(moduleName); - -await $`docker build --file ./Modules/${moduleName}/src/${moduleName}.Jobs.SanityCheck${projectSuffix}/Dockerfile --tag ghcr.io/nmshd/backbone-${moduleNameCamelCase}-sanity-check:${tag} --build-arg VERSION=${tag} .`; diff --git a/.ci/sc/pushContainerImage.js b/.ci/sc/pushContainerImage.js deleted file mode 100755 index 15266a7684..0000000000 --- a/.ci/sc/pushContainerImage.js +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env node - -import { $ } from "zx"; -import { getRequiredEnvVar, toCamelCase } from "../lib.js"; - -const tag = getRequiredEnvVar("TAG"); -const moduleName = getRequiredEnvVar("MODULE"); - -const moduleNameCamelCase = toCamelCase(moduleName); - -await $`docker push ghcr.io/nmshd/backbone-${moduleNameCamelCase}-sanity-check:${tag}`; diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7197c3f8b5..2119f6cfa1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -107,9 +107,6 @@ jobs: - dockerfile: Applications/EventHandlerService/src/EventHandlerService/Dockerfile image: event-handler - - dockerfile: Applications/FilesSanityCheck/src/FilesSanityCheck/Dockerfile - image: files-sanity-check - - dockerfile: Applications/IdentityDeletionJobs/src/Job.IdentityDeletion/Dockerfile image: identity-deletion-jobs diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Dockerfile b/Applications/FilesSanityCheck/src/FilesSanityCheck/Dockerfile deleted file mode 100644 index 632598e575..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base -WORKDIR /app - -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build -WORKDIR /src - -COPY ["Directory.Build.props", "."] -COPY ["Applications/FilesSanityCheck/src/FilesSanityCheck/FilesSanityCheck.csproj", "Applications/FilesSanityCheck/src/FilesSanityCheck/"] -COPY ["BuildingBlocks/src/BuildingBlocks.Application.Abstractions/BuildingBlocks.Application.Abstractions.csproj", "BuildingBlocks/src/BuildingBlocks.Application.Abstractions/"] -COPY ["BuildingBlocks/src/BuildingBlocks.Domain/BuildingBlocks.Domain.csproj", "BuildingBlocks/src/BuildingBlocks.Domain/"] -COPY ["BuildingBlocks/src/DevelopmentKit.Identity/DevelopmentKit.Identity.csproj", "BuildingBlocks/src/DevelopmentKit.Identity/"] -COPY ["BuildingBlocks/src/StronglyTypedIds/StronglyTypedIds.csproj", "BuildingBlocks/src/StronglyTypedIds/"] -COPY ["BuildingBlocks/src/Tooling/Tooling.csproj", "BuildingBlocks/src/Tooling/"] -COPY ["Modules/Files/src/Files.Application/Files.Application.csproj", "Modules/Files/src/Files.Application/"] -COPY ["BuildingBlocks/src/BuildingBlocks.Application/BuildingBlocks.Application.csproj", "BuildingBlocks/src/BuildingBlocks.Application/"] -COPY ["Modules/Files/src/Files.Domain/Files.Domain.csproj", "Modules/Files/src/Files.Domain/"] -COPY ["Modules/Files/src/Files.Infrastructure/Files.Infrastructure.csproj", "Modules/Files/src/Files.Infrastructure/"] -COPY ["BuildingBlocks/src/BuildingBlocks.Infrastructure/BuildingBlocks.Infrastructure.csproj", "BuildingBlocks/src/BuildingBlocks.Infrastructure/"] -COPY ["Common/src/Common.Infrastructure/Common.Infrastructure.csproj", "Common/src/Common.Infrastructure/"] - -RUN dotnet restore /p:ContinuousIntegrationBuild=true "Applications/FilesSanityCheck/src/FilesSanityCheck/FilesSanityCheck.csproj" - -COPY . . - -ARG VERSION - -WORKDIR "/src/Applications/FilesSanityCheck/src/FilesSanityCheck" -RUN dotnet build /p:ContinuousIntegrationBuild=true "FilesSanityCheck.csproj" --configuration Release --output /app/build --no-restore - -FROM build AS publish -RUN dotnet publish /p:ContinuousIntegrationBuild=true /property:UseAppHost=false --configuration Release --output /app/publish --no-restore "FilesSanityCheck.csproj" - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Backbone.Modules.Files.Jobs.SanityCheck.dll"] diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Extensions/IConfigurationExtensions.cs b/Applications/FilesSanityCheck/src/FilesSanityCheck/Extensions/IConfigurationExtensions.cs deleted file mode 100644 index fbd29d9c69..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Extensions/IConfigurationExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Backbone.FilesSanityCheck.Extensions; - -internal static class IConfigurationExtensions -{ - public static BlobStorageConfiguration GetBlobStorageConfiguration(this IConfiguration configuration) - { - return configuration.GetSection("BlobStorage").Get() ?? new BlobStorageConfiguration(); - } - - public static SqlDatabaseConfiguration GetSqlDatabaseConfiguration(this IConfiguration configuration) - { - return configuration.GetSection("SqlDatabase").Get() ?? new SqlDatabaseConfiguration(); - } -} - -public class SqlDatabaseConfiguration -{ - [Required] - [MinLength(1)] - [RegularExpression("SqlServer|Postgres")] - public string Provider { get; set; } = string.Empty; - - [Required] - [MinLength(1)] - public string ConnectionString { get; set; } = string.Empty; -} - -public class BlobStorageConfiguration -{ - [Required] - [MinLength(1)] - [RegularExpression("Azure|GoogleCloud")] - public string CloudProvider { get; set; } = string.Empty; - - [Required] - [MinLength(1)] - public string ConnectionInfo { get; set; } = string.Empty; - - public string ContainerName { get; set; } = string.Empty; -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/FilesSanityCheck.csproj b/Applications/FilesSanityCheck/src/FilesSanityCheck/FilesSanityCheck.csproj deleted file mode 100644 index 169bcf9a6d..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/FilesSanityCheck.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - Linux - ..\..\..\.. - - - - - - - - - - - - - - - - PreserveNewest - - - - diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/DataSource/DataSource.cs b/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/DataSource/DataSource.cs deleted file mode 100644 index 0797645aaa..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/DataSource/DataSource.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.Persistence.BlobStorage; -using Backbone.Modules.Files.Application.Infrastructure.Persistence; -using Backbone.Modules.Files.Domain.Entities; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Options; -using File = Backbone.Modules.Files.Domain.Entities.File; - -namespace Backbone.FilesSanityCheck.Infrastructure.DataSource; - -public class DataSource : IDataSource -{ - private readonly IBlobStorage _blobStorage; - private readonly IFilesDbContext _dbContext; - private readonly BlobOptions _blobOptions; - - public DataSource(IBlobStorage blobStorage, IOptions blobOptions, IFilesDbContext dbContext) - { - _blobStorage = blobStorage; - _dbContext = dbContext; - _blobOptions = blobOptions.Value; - } - - public async Task> GetBlobIdsAsync(CancellationToken cancellationToken) - { - var blobIds = await _blobStorage.FindAllAsync(_blobOptions.RootFolder); - return await blobIds.ToListAsync(cancellationToken); - } - - public async Task> GetDatabaseIdsAsync(CancellationToken cancellationToken) - { - return await _dbContext.SetReadOnly().Select(u => u.Id).ToListAsync(cancellationToken); - } -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/DataSource/IDataSource.cs b/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/DataSource/IDataSource.cs deleted file mode 100644 index aa7ba3eb66..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/DataSource/IDataSource.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Backbone.Modules.Files.Domain.Entities; - -namespace Backbone.FilesSanityCheck.Infrastructure.DataSource; - -public interface IDataSource -{ - Task> GetDatabaseIdsAsync(CancellationToken cancellationToken); - - Task> GetBlobIdsAsync(CancellationToken cancellationToken); -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/Reporter/IReporter.cs b/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/Reporter/IReporter.cs deleted file mode 100644 index d5b96d7f43..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/Reporter/IReporter.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Backbone.Modules.Files.Domain.Entities; - -namespace Backbone.FilesSanityCheck.Infrastructure.Reporter; - -public interface IReporter -{ - void ReportOrphanedDatabaseId(FileId id); - - void ReportOrphanedBlobId(string id); - - void Complete(); -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/Reporter/LogReporter.cs b/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/Reporter/LogReporter.cs deleted file mode 100644 index 3e6433fb6a..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/Reporter/LogReporter.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Backbone.Modules.Files.Domain.Entities; - -namespace Backbone.FilesSanityCheck.Infrastructure.Reporter; - -public class LogReporter : IReporter -{ - private readonly ILogger _logger; - private readonly List _databaseIds; - private readonly List _blobIds; - - public LogReporter(ILogger logger) - { - _logger = logger; - - _databaseIds = []; - _blobIds = []; - } - - public void Complete() - { - foreach (var databaseId in _databaseIds) - { - _logger.NoBlobForFileId(databaseId); - } - - foreach (var blobId in _blobIds) - { - _logger.NoDatabaseEntryForBlobId(blobId); - } - } - - public void ReportOrphanedBlobId(string id) - { - _blobIds.Add(id); - } - - public void ReportOrphanedDatabaseId(FileId id) - { - _databaseIds.Add(id); - } -} - -internal static partial class LogReporterLogs -{ - [LoggerMessage( - EventId = 629592, - EventName = "Files.SanityCheck.NoBlobForFileId", - Level = LogLevel.Error, - Message = "No blob found for file id: '{databaseId}'.")] - public static partial void NoBlobForFileId(this ILogger logger, FileId databaseId); - - [LoggerMessage( - EventId = 487180, - EventName = "Files.SanityCheck.NoDatabaseEntryForBlobId", - Level = LogLevel.Error, - Message = "No database entry found for blob id: '{blobId}'.")] - public static partial void NoDatabaseEntryForBlobId(this ILogger logger, string blobId); -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/SanityCheck/SanityCheck.cs b/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/SanityCheck/SanityCheck.cs deleted file mode 100644 index 992fa84de0..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Infrastructure/SanityCheck/SanityCheck.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Backbone.FilesSanityCheck.Infrastructure.DataSource; -using Backbone.FilesSanityCheck.Infrastructure.Reporter; -using Backbone.Modules.Files.Domain.Entities; - -namespace Backbone.FilesSanityCheck.Infrastructure.SanityCheck; - -public class SanityCheck -{ - private readonly IDataSource _dataSource; - private readonly IReporter _reporter; - private List _blobIds; - private List _databaseIds; - - public SanityCheck(IDataSource dataSource, IReporter reporter) - { - _dataSource = dataSource; - _reporter = reporter; - _databaseIds = []; - _blobIds = []; - } - - public async Task Run(CancellationToken cancellationToken) - { - _databaseIds = (await _dataSource.GetDatabaseIdsAsync(cancellationToken)).ToList(); - _blobIds = (await _dataSource.GetBlobIdsAsync(cancellationToken)).ToList(); - - ReportOrphanedDatabaseIds(); - - if (cancellationToken.IsCancellationRequested) - return; - - ReportOrphanedBlobIds(); - - _reporter.Complete(); - } - - private void ReportOrphanedDatabaseIds() - { - foreach (var databaseId in GetOrphanedDatabaseIds()) - { - _reporter.ReportOrphanedDatabaseId(databaseId); - } - } - - private IEnumerable GetOrphanedDatabaseIds() - { - Func noCorrespondingBlobIdExists = databaseId => _blobIds.All(blobId => blobId != databaseId.Value); - return _databaseIds.Where(noCorrespondingBlobIdExists); - } - - private void ReportOrphanedBlobIds() - { - foreach (var blobId in GetOrphanedBlobIds()) - { - _reporter.ReportOrphanedBlobId(blobId); - } - } - - private IEnumerable GetOrphanedBlobIds() - { - Func noCorrespondingDatabaseIdExists = blobId => _databaseIds.All(databaseId => databaseId.Value != blobId); - return _blobIds.Where(noCorrespondingDatabaseIdExists); - } -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Program.cs b/Applications/FilesSanityCheck/src/FilesSanityCheck/Program.cs deleted file mode 100644 index 3bf6d8608a..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Program.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Reflection; -using Backbone.FilesSanityCheck.Extensions; -using Backbone.FilesSanityCheck.Infrastructure.DataSource; -using Backbone.FilesSanityCheck.Infrastructure.Reporter; -using Backbone.Modules.Files.Infrastructure.Persistence; -using Backbone.Tooling.Extensions; - -namespace Backbone.FilesSanityCheck; - -public class Program -{ - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - private static IHostBuilder CreateHostBuilder(string[] args) - { - return Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostContext, configuration) => - { - configuration.Sources.Clear(); - var env = hostContext.HostingEnvironment; - - configuration - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) - .AddJsonFile("appsettings.override.json", optional: true, reloadOnChange: true); - - if (env.IsDevelopment()) - { - var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName)); - configuration.AddUserSecrets(appAssembly, optional: true); - } - - configuration.AddEnvironmentVariables(); - configuration.AddCommandLine(args); - }) - .ConfigureServices((hostContext, services) => - { - var configuration = hostContext.Configuration; - - services.AddHostedService(); - - services.AddScoped(); - - services.AddScoped(); - - services.AddPersistence(options => - { - options.DbOptions.DbConnectionString = configuration.GetSqlDatabaseConfiguration().ConnectionString; - options.DbOptions.Provider = configuration.GetSqlDatabaseConfiguration().Provider; - - options.BlobStorageOptions.ConnectionInfo = configuration.GetBlobStorageConfiguration().ConnectionInfo; - options.BlobStorageOptions.CloudProvider = configuration.GetBlobStorageConfiguration().CloudProvider; - options.BlobStorageOptions.Container = configuration.GetBlobStorageConfiguration().ContainerName.IsNullOrEmpty() ? "files" : configuration.GetBlobStorageConfiguration().ContainerName; - }); - }); - } -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Properties/launchSettings.json b/Applications/FilesSanityCheck/src/FilesSanityCheck/Properties/launchSettings.json deleted file mode 100644 index 296d974615..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Properties/launchSettings.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "profiles": { - "Files.Jobs.SanityCheck": { - "commandName": "Project", - "environmentVariables": { - "DOTNET_ENVIRONMENT": "Development" - }, - "dotnetRunMessages": true, - "workingDirectory": "bin/Debug/$(TargetFramework)" - }, - "Docker": { - "commandName": "Docker" - } - } -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/Worker.cs b/Applications/FilesSanityCheck/src/FilesSanityCheck/Worker.cs deleted file mode 100644 index e205fd1c13..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/Worker.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Backbone.FilesSanityCheck.Infrastructure.DataSource; -using Backbone.FilesSanityCheck.Infrastructure.Reporter; - -namespace Backbone.FilesSanityCheck; - -public class Worker : IHostedService -{ - private readonly IHostApplicationLifetime _host; - private readonly IServiceScopeFactory _serviceScopeFactory; - private IDataSource _dataSource; - private IReporter _reporter; - - public Worker(IHostApplicationLifetime host, IServiceScopeFactory serviceScopeFactory) - { - _host = host; - _serviceScopeFactory = serviceScopeFactory; - - // the following fields are initialized in StartAsync, which is always called before any other method - _dataSource = null!; - _reporter = null!; - } - - public async Task StartAsync(CancellationToken cancellationToken) - { - using var scope = _serviceScopeFactory.CreateScope(); - - _dataSource = scope.ServiceProvider.GetRequiredService(); - _reporter = scope.ServiceProvider.GetRequiredService(); - - await RunSanityCheck(cancellationToken); - - _host.StopApplication(); - } - - public Task StopAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - - private async Task RunSanityCheck(CancellationToken cancellationToken) - { - var sanityCheck = new Infrastructure.SanityCheck.SanityCheck(_dataSource, _reporter); - - await sanityCheck.Run(cancellationToken); - } -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/appsettings.Development.json b/Applications/FilesSanityCheck/src/FilesSanityCheck/appsettings.Development.json deleted file mode 100644 index 88a9ac01d8..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/Applications/FilesSanityCheck/src/FilesSanityCheck/appsettings.json b/Applications/FilesSanityCheck/src/FilesSanityCheck/appsettings.json deleted file mode 100644 index 564ff5ce5f..0000000000 --- a/Applications/FilesSanityCheck/src/FilesSanityCheck/appsettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - }, - "SqlDatabase": { - "ConnectionString": "Server=localhost;Database=enmeshed;User Id=files;Password=Passw0rd;Trust Server Certificate=true" - } -} diff --git a/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/FilesSanityCheck.Tests.csproj b/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/FilesSanityCheck.Tests.csproj deleted file mode 100644 index 3c784fb0b1..0000000000 --- a/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/FilesSanityCheck.Tests.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - false - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - diff --git a/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Infrastructure/DataSource/FakeDataSource.cs b/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Infrastructure/DataSource/FakeDataSource.cs deleted file mode 100644 index b59a61d1b4..0000000000 --- a/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Infrastructure/DataSource/FakeDataSource.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Backbone.FilesSanityCheck.Infrastructure.DataSource; -using Backbone.Modules.Files.Domain.Entities; - -namespace Backbone.FilesSanityCheck.Tests.Infrastructure.DataSource; - -public class FakeDataSource : IDataSource -{ - public List DatabaseIds { get; } = []; - public List BlobIds { get; } = []; - - public Task> GetBlobIdsAsync(CancellationToken cancellationToken) - { - return Task.FromResult>(BlobIds); - } - - public Task> GetDatabaseIdsAsync(CancellationToken cancellationToken) - { - return Task.FromResult>(DatabaseIds); - } -} diff --git a/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Infrastructure/Reporter/TestReporter.cs b/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Infrastructure/Reporter/TestReporter.cs deleted file mode 100644 index 3a1cec0a8a..0000000000 --- a/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Infrastructure/Reporter/TestReporter.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Backbone.FilesSanityCheck.Infrastructure.Reporter; -using Backbone.Modules.Files.Domain.Entities; - -namespace Backbone.FilesSanityCheck.Tests.Infrastructure.Reporter; - -public class TestReporter : IReporter -{ - public List ReportedDatabaseIds { get; } = []; - public List ReportedBlobIds { get; } = []; - - public void Complete() - { - } - - public void ReportOrphanedBlobId(string id) - { - ReportedBlobIds.Add(id); - } - - public void ReportOrphanedDatabaseId(FileId id) - { - ReportedDatabaseIds.Add(id); - } -} diff --git a/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Tests/SanityCheckTests.cs b/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Tests/SanityCheckTests.cs deleted file mode 100644 index d68c3c3cd3..0000000000 --- a/Applications/FilesSanityCheck/test/Files.Jobs.SanityCheck.Tests/Tests/SanityCheckTests.cs +++ /dev/null @@ -1,69 +0,0 @@ -using Backbone.FilesSanityCheck.Infrastructure.SanityCheck; -using Backbone.FilesSanityCheck.Tests.Infrastructure.DataSource; -using Backbone.FilesSanityCheck.Tests.Infrastructure.Reporter; -using Backbone.Modules.Files.Domain.Entities; - -namespace Backbone.FilesSanityCheck.Tests.Tests; - -public class SanityCheckTests : AbstractTestsBase -{ - private readonly FakeDataSource _dataSource; - private readonly TestReporter _reporter; - private readonly SanityCheck _sanityCheck; - - public SanityCheckTests() - { - _dataSource = new FakeDataSource(); - _reporter = new TestReporter(); - _sanityCheck = new SanityCheck(_dataSource, _reporter); - } - - [Fact] - public async Task SanityCheckNoEntries() - { - await _sanityCheck.Run(CancellationToken.None); - - _reporter.ReportedDatabaseIds.Should().BeEmpty(); - _reporter.ReportedBlobIds.Should().BeEmpty(); - } - - [Fact] - public async Task SanityCheckConsistentEntries() - { - var fileId = FileId.New(); - - _dataSource.BlobIds.Add(fileId); - _dataSource.DatabaseIds.Add(fileId); - - await _sanityCheck.Run(CancellationToken.None); - - _reporter.ReportedDatabaseIds.Should().BeEmpty(); - _reporter.ReportedBlobIds.Should().BeEmpty(); - } - - [Fact] - public async Task SanityCheckInconsistentDatabase() - { - var fileId = FileId.New(); - - _dataSource.DatabaseIds.Add(fileId); - - await _sanityCheck.Run(CancellationToken.None); - - _reporter.ReportedDatabaseIds.Should().HaveCount(1).And.Contain(fileId); - _reporter.ReportedBlobIds.Should().BeEmpty(); - } - - [Fact] - public async Task SanityCheckInconsistentBlobs() - { - var fileId = FileId.New(); - - _dataSource.BlobIds.Add(fileId); - - await _sanityCheck.Run(CancellationToken.None); - - _reporter.ReportedDatabaseIds.Should().BeEmpty(); - _reporter.ReportedBlobIds.Should().HaveCount(1).And.Contain(fileId); - } -} diff --git a/Backbone.Tests.ArchUnit/Backbone.Tests.ArchUnit.csproj b/Backbone.Tests.ArchUnit/Backbone.Tests.ArchUnit.csproj index 1c5de47079..463cfcbd8c 100644 --- a/Backbone.Tests.ArchUnit/Backbone.Tests.ArchUnit.csproj +++ b/Backbone.Tests.ArchUnit/Backbone.Tests.ArchUnit.csproj @@ -49,7 +49,6 @@ - diff --git a/Backbone.sln b/Backbone.sln index 5905be68c5..262be9b64c 100644 --- a/Backbone.sln +++ b/Backbone.sln @@ -317,16 +317,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SseServer", "Applications\S EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SseServerTests", "Applications\SseServer\test\SseServerTests\SseServerTests.csproj", "{24AF731E-B133-404F-AAE2-19521C15FD2C}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FilesSanityCheck", "FilesSanityCheck", "{EE57C18D-9B33-439B-A486-33B0A7842BAF}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B64AD62D-06B8-44F5-BDF4-A2E60390D4FC}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{127E4B29-FD43-4BED-87A1-9423414DB87B}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilesSanityCheck", "Applications\FilesSanityCheck\src\FilesSanityCheck\FilesSanityCheck.csproj", "{B723B7DF-E91A-477A-B09C-08577CE52BB7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilesSanityCheck.Tests", "Applications\FilesSanityCheck\test\Files.Jobs.SanityCheck.Tests\FilesSanityCheck.Tests.csproj", "{FEB2983E-E95F-4DBC-AE9B-874C35442A4D}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F6BB3689-43FA-4B0B-BEFC-8129E6543F67}" ProjectSection(SolutionItems) = preProject Applications\AdminUi\.gitignore = Applications\AdminUi\.gitignore @@ -810,14 +800,6 @@ Global {24AF731E-B133-404F-AAE2-19521C15FD2C}.Debug|Any CPU.Build.0 = Debug|Any CPU {24AF731E-B133-404F-AAE2-19521C15FD2C}.Release|Any CPU.ActiveCfg = Release|Any CPU {24AF731E-B133-404F-AAE2-19521C15FD2C}.Release|Any CPU.Build.0 = Release|Any CPU - {B723B7DF-E91A-477A-B09C-08577CE52BB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B723B7DF-E91A-477A-B09C-08577CE52BB7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B723B7DF-E91A-477A-B09C-08577CE52BB7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B723B7DF-E91A-477A-B09C-08577CE52BB7}.Release|Any CPU.Build.0 = Release|Any CPU - {FEB2983E-E95F-4DBC-AE9B-874C35442A4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FEB2983E-E95F-4DBC-AE9B-874C35442A4D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FEB2983E-E95F-4DBC-AE9B-874C35442A4D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FEB2983E-E95F-4DBC-AE9B-874C35442A4D}.Release|Any CPU.Build.0 = Release|Any CPU {232AAB02-F4F8-4827-8866-00B7FC2CC0E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {232AAB02-F4F8-4827-8866-00B7FC2CC0E2}.Debug|Any CPU.Build.0 = Debug|Any CPU {232AAB02-F4F8-4827-8866-00B7FC2CC0E2}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -1038,11 +1020,6 @@ Global {1B510C96-DDFD-4376-AB75-44E0B8EFC723} = {C2DFC666-E2F6-4763-840F-1E2D3C40837D} {B36578AF-0AE7-4FEF-98C8-5836998B0597} = {5F4E2DF4-17B0-4575-900F-DC810076F24A} {24AF731E-B133-404F-AAE2-19521C15FD2C} = {531CEEB9-0346-4140-98B3-952ED8360063} - {EE57C18D-9B33-439B-A486-33B0A7842BAF} = {44C9D62D-813D-497A-8DDF-C06E515CB22E} - {B64AD62D-06B8-44F5-BDF4-A2E60390D4FC} = {EE57C18D-9B33-439B-A486-33B0A7842BAF} - {127E4B29-FD43-4BED-87A1-9423414DB87B} = {EE57C18D-9B33-439B-A486-33B0A7842BAF} - {B723B7DF-E91A-477A-B09C-08577CE52BB7} = {B64AD62D-06B8-44F5-BDF4-A2E60390D4FC} - {FEB2983E-E95F-4DBC-AE9B-874C35442A4D} = {127E4B29-FD43-4BED-87A1-9423414DB87B} {F6BB3689-43FA-4B0B-BEFC-8129E6543F67} = {4FA3C4B4-E502-4D1C-98B8-509C5F63EC59} {95EE2E41-D772-4DFF-86F9-A41A840B54D1} = {4FA3C4B4-E502-4D1C-98B8-509C5F63EC59} {232AAB02-F4F8-4827-8866-00B7FC2CC0E2} = {5FB130D7-C4E3-4893-B1A4-2DA0887B6482}