Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into #302-dsfinvk-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
forsthug committed Jul 5, 2024
2 parents 234453c + b8e5f90 commit b7090f9
Show file tree
Hide file tree
Showing 53 changed files with 1,783 additions and 1,631 deletions.
14 changes: 7 additions & 7 deletions azure-pipelines/fiskaltrust.Middleware.SmokeTests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ variables:
trigger: none
pr: none

schedules:
- cron: 0 0 * * *
displayName: Nightly Run
branches:
include:
- main
always: true
#schedules:
# - cron: 0 0 * * *
# displayName: Nightly Run
# branches:
# include:
# - main
# always: true

stages:
- template: templates/smoketests/harness.yaml
Expand Down
7 changes: 7 additions & 0 deletions queue/fiskaltrust.Middleware.sln
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Loca
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fiskaltrust.Middleware.Localization.QueueFR.IntegrationTest", "test\fiskaltrust.Middleware.Localization.QueueFR.IntegrationTest\fiskaltrust.Middleware.Localization.QueueFR.IntegrationTest.csproj", "{7F52D143-9179-4FCF-9DC7-B5F1681BD22A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fiskaltrust.Middleware.Storage.AzureTableStorage.UnitTest", "test\fiskaltrust.Middleware.Storage.AzureTableStorage.UnitTest\fiskaltrust.Middleware.Storage.AzureTableStorage.UnitTest.csproj", "{EEDA285C-82F8-4E6D-AAFA-9E42D3C4F0E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -337,6 +339,10 @@ Global
{7F52D143-9179-4FCF-9DC7-B5F1681BD22A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F52D143-9179-4FCF-9DC7-B5F1681BD22A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F52D143-9179-4FCF-9DC7-B5F1681BD22A}.Release|Any CPU.Build.0 = Release|Any CPU
{EEDA285C-82F8-4E6D-AAFA-9E42D3C4F0E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEDA285C-82F8-4E6D-AAFA-9E42D3C4F0E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEDA285C-82F8-4E6D-AAFA-9E42D3C4F0E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEDA285C-82F8-4E6D-AAFA-9E42D3C4F0E6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -398,6 +404,7 @@ Global
{3C0310D9-EC55-4115-A2D5-0DC8C1246645} = {C345F1F7-C2A5-472A-A55F-987A53DF3CCE}
{04B32BB6-2E1D-400F-B7B2-2638483B0825} = {16BF88B4-3302-49F5-A5FA-5DA96DD03F0E}
{7F52D143-9179-4FCF-9DC7-B5F1681BD22A} = {16BF88B4-3302-49F5-A5FA-5DA96DD03F0E}
{EEDA285C-82F8-4E6D-AAFA-9E42D3C4F0E6} = {EAEEF28B-F372-48C1-8F9B-45CEB95159A2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E8BEA609-BD83-4165-A14A-D010D2CC87AD}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.3.59-rc2",
"version": "1.3.60-rc2",
"releaseBranches": [
"^refs/tags/queue/azuretablestorage/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -57,21 +58,14 @@ public void ConfigureServices(IServiceCollection services)

private static async Task CreateConfigurationActionJournalAsync(MiddlewareConfiguration middlewareConfiguration, IActionJournalRepository actionJournalRepository)
{
var configurationCopy = new Dictionary<string, object>(middlewareConfiguration.Configuration)
var configuration = new Dictionary<string, object>
{
{ "MachineName", Environment.MachineName },
{ "ProcessArchitecture", RuntimeInformation.ProcessArchitecture.ToString() },
{ "OSArchitecture", RuntimeInformation.OSArchitecture.ToString() },
{ "OSDescription", RuntimeInformation.OSDescription.ToString() }
{ "OSDescription", RuntimeInformation.OSDescription.ToString() },
{ "...", "redacted"}
};
configurationCopy.Remove("configuration");
foreach (var key in configurationCopy.Keys.ToArray())
{
if (key.ToLowerInvariant().Contains("connectionstring") || key.ToLowerInvariant().EndsWith("_encrypted"))
{
configurationCopy[key] = "********";
}
}

var actionJournal = new ftActionJournal
{
Expand All @@ -88,8 +82,8 @@ private static async Task CreateConfigurationActionJournalAsync(MiddlewareConfig
QueueId = middlewareConfiguration.QueueId,
IsSandbox = middlewareConfiguration.IsSandbox,
ServiceFolder = middlewareConfiguration.ServiceFolder,
Configuration = configurationCopy,
PreviewFeatures = middlewareConfiguration.PreviewFeatures
Configuration = configuration,
PreviewFeatures = middlewareConfiguration.PreviewFeatures,
}),
TimeStamp = DateTime.UtcNow.Ticks
};
Expand Down
4 changes: 3 additions & 1 deletion queue/src/fiskaltrust.Middleware.Queue/JournalProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ private async Task<object> GetConfiguration()
QueueDEList = await _configurationRepository.GetQueueDEListAsync().ConfigureAwait(false),
QueueFRList = await _configurationRepository.GetQueueFRListAsync().ConfigureAwait(false),
QueueMEList = await _configurationRepository.GetQueueMEListAsync().ConfigureAwait(false),
QueueITList = await _configurationRepository.GetQueueITListAsync().ConfigureAwait(false),
SignaturCreationUnitATList = await _configurationRepository.GetSignaturCreationUnitATListAsync().ConfigureAwait(false),
SignaturCreationUnitDEList = await _configurationRepository.GetSignaturCreationUnitDEListAsync().ConfigureAwait(false),
SignaturCreationUnitFRList = await _configurationRepository.GetSignaturCreationUnitFRListAsync().ConfigureAwait(false),
SignaturCreationUnitMEList = await _configurationRepository.GetSignaturCreationUnitMEListAsync().ConfigureAwait(false)
SignaturCreationUnitMEList = await _configurationRepository.GetSignaturCreationUnitMEListAsync().ConfigureAwait(false),
SignaturCreationUnitITList = await _configurationRepository.GetSignaturCreationUnitITListAsync().ConfigureAwait(false),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Azure.Storage.Blobs;
using fiskaltrust.Middleware.Abstractions;
using fiskaltrust.Middleware.Storage.AzureTableStorage.Migrations;
using fiskaltrust.Middleware.Storage.AzureTableStorage.Repositories;
using fiskaltrust.Middleware.Storage.AzureTableStorage.Repositories.Configuration;
using Microsoft.Extensions.Logging;

namespace fiskaltrust.Middleware.Storage.AzureTableStorage
Expand All @@ -17,17 +19,21 @@ public class DatabaseMigrator
private readonly TableServiceClient _tableServiceClient;
private readonly QueueConfiguration _queueConfiguration;

public bool? MigratedFrom1_2 { get; set; }

private readonly IAzureTableStorageMigration[] _migrations;

public DatabaseMigrator(ILogger<IMiddlewareBootstrapper> logger, TableServiceClient tableServiceClient, BlobServiceClient blobServiceClient, QueueConfiguration queueConfiguration)
{
_logger = logger;
_tableServiceClient = tableServiceClient;
_queueConfiguration = queueConfiguration;
MigratedFrom1_2 = null;

_migrations = new[]
_migrations = new IAzureTableStorageMigration[]
{
new Migration_000_Initial(_tableServiceClient, blobServiceClient, queueConfiguration)
new Migration_000_Initial(_tableServiceClient, blobServiceClient, queueConfiguration),
new Migration_001_TableNameFix(_tableServiceClient, queueConfiguration)
};
}

Expand All @@ -36,12 +42,24 @@ public async Task MigrateAsync()
if (await MigrationTableExists())
{
var currentMigration = await GetCurrentMigrationAsync();
MigratedFrom1_2 = await GetMigratedFrom1_2Async();
await ExecuteMigrationsAsync(_migrations.Where(x => x.Version > currentMigration));
}
else
{
_logger.LogInformation("Database tables were not yet created, executing all {MigrationCount} migrations.", _migrations.Length);
await _tableServiceClient.CreateTableIfNotExistsAsync(GetMigrationTableName());

var cashboxTableName = $"x{_queueConfiguration.QueueId.ToString().Replace("-", "")}{AzureTableStorageCashBoxRepository.TABLE_NAME}";
if (await _tableServiceClient.QueryAsync(t => t.Name == cashboxTableName).AnyAsync())
{
var cashBoxTableClient = _tableServiceClient.GetTableClient(cashboxTableName);
var cashBoxes = await cashBoxTableClient.QueryAsync<TableEntity>().FirstOrDefaultAsync();
if (cashBoxes is not null)
{
MigratedFrom1_2 = true;
}
}
await ExecuteMigrationsAsync(_migrations);
}
}
Expand All @@ -63,10 +81,17 @@ private async Task<int> GetCurrentMigrationAsync()
return migration?.GetInt32("CurrentVersion") ?? -1;
}

private async Task<bool> GetMigratedFrom1_2Async()
{
var tableClient = _tableServiceClient.GetTableClient(GetMigrationTableName());
var migration = await tableClient.QueryAsync<TableEntity>().FirstOrDefaultAsync();
return migration?.GetBoolean(nameof(MigratedFrom1_2)) ?? false;
}

private async Task SetCurrentMigrationAsync(int version)
{
var tableClient = _tableServiceClient.GetTableClient(GetMigrationTableName());
await tableClient.UpsertEntityAsync(new TableEntity(_queueConfiguration.QueueId.ToString(), "Current") { { "CurrentVersion", version } });
await tableClient.UpsertEntityAsync(new TableEntity(_queueConfiguration.QueueId.ToString(), "Current") { { "CurrentVersion", version }, { nameof(MigratedFrom1_2), MigratedFrom1_2 } });
}

private async Task<bool> MigrationTableExists() => await _tableServiceClient.QueryAsync(t => t.Name == GetMigrationTableName()).AnyAsync();
Expand Down
Loading

0 comments on commit b7090f9

Please sign in to comment.