Skip to content

Commit 3be7781

Browse files
committed
Cleanup old files.
Fix appsettings.json Refactor AutoTestBackupConfigDto.cs Implement managing auto test backup configuration
1 parent 0426a07 commit 3be7781

File tree

17 files changed

+536
-62
lines changed

17 files changed

+536
-62
lines changed

DbBackupService/Src/Bootstraper/Client/Client.UI/Data/Services/BackupsHttpClientService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,14 @@ public async Task<OneOf<Success, string>> BackupServerAsync(Guid serverId)
7070
{
7171
return await api.PostAsync("/api/backups/PerformBackup", serverId);
7272
}
73+
74+
public async Task<OneOf<AutoTestBackupConfigDto, string>> FetchAutoTestBackupConfig(Guid configurationId)
75+
{
76+
return await api.PostAsync<AutoTestBackupConfigDto, Guid>("/api/servers/FetchAutoTestConfig", configurationId);
77+
}
78+
79+
public async Task<OneOf<Success, string>> EditAutoTestBackupConfig(AutoTestBackupConfigDto config)
80+
{
81+
return await api.PostAsync("/api/servers/EditAutoTestConfig", config);
82+
}
7383
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
@using Client.UI.Data.Services
2+
@using Modules.Backup.Shared.Dtos
3+
4+
@inject BackupsHttpClientService Service
5+
@inject ISnackbar Snackbar
6+
7+
<MudDialog>
8+
<DialogContent>
9+
<MudCard Elevation="3" Class="pa-4 rounded-2xl mb-5">
10+
<MudCardContent Class="d-flex flex-column align-center">
11+
@if (_config is null)
12+
{
13+
<MudProgressCircular Indeterminate="true" Color="Color.Primary"/>
14+
<MudText Align="Align.Center">Searching for specified server configuration...</MudText>
15+
}
16+
else
17+
{
18+
<MudGrid Justify="Justify.Center" Spacing="4">
19+
<MudItem xs="12" Class="d-flex flex-column justify-center align-center">
20+
<MudCheckBox T="bool" @bind-Value="_config.IsEnabled" Label="Enable Automatic Tests" LabelPlacement="Placement.End"/>
21+
</MudItem>
22+
</MudGrid>
23+
}
24+
</MudCardContent>
25+
</MudCard>
26+
27+
<MudContainer Class="d-flex justify-between pa-4">
28+
<MudButton OnClick="@Close" Variant="Variant.Text" Color="Color.Default" Disabled="@_isSaving">Close
29+
</MudButton>
30+
<MudButton OnClick="@Save" Variant="Variant.Filled" Color="Color.Success" Disabled="@_isSaving">
31+
@if (_isSaving)
32+
{
33+
<MudProgressCircular Indeterminate="true" Color="Color.Primary"/>
34+
}
35+
else
36+
{
37+
<span>Save Config</span>
38+
}
39+
</MudButton>
40+
</MudContainer>
41+
</DialogContent>
42+
</MudDialog>
43+
44+
@code {
45+
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
46+
[Parameter] public Guid ConfigurationId { get; set; }
47+
48+
private AutoTestBackupConfigDto? _config;
49+
50+
private bool _isSaving;
51+
52+
protected override async Task OnInitializedAsync()
53+
{
54+
_isSaving = true;
55+
56+
var result = await Service.FetchAutoTestBackupConfig(ConfigurationId);
57+
58+
result.Switch(
59+
config => _config = config,
60+
error => Snackbar.Add(error, Severity.Error)
61+
);
62+
63+
_isSaving = false;
64+
}
65+
66+
private void Close()
67+
=> MudDialog.Cancel();
68+
69+
private async Task Save()
70+
{
71+
_isSaving = true;
72+
73+
if (_config is null)
74+
{
75+
Snackbar.Add("Config can't be null", Severity.Error);
76+
77+
_isSaving = false;
78+
return;
79+
}
80+
81+
var result = await Service.EditAutoTestBackupConfig(_config);
82+
83+
result.Switch(
84+
_ => Snackbar.Add("Successfully saved configuration", Severity.Success),
85+
error => Snackbar.Add(error, Severity.Error)
86+
);
87+
88+
_isSaving = false;
89+
}
90+
}

DbBackupService/Src/Bootstraper/Client/Client.UI/Pages/BackupsModule/MyServers.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@
9191
<MudMenuItem Disabled="@_isProcessing" OnClick="@(() => PerformServerBackup(context.Id))">
9292
Perform Backup
9393
</MudMenuItem>
94+
<MudMenuItem Disabled="@_isProcessing" OnClick="@(() => EditTestsConfig(context.AutoTestBackupsConfigId))">
95+
Auto Tests Configuration
96+
</MudMenuItem>
9497
</ChildContent>
9598
</MudMenu>
9699
</MudTd>
@@ -236,4 +239,13 @@
236239
_isProcessing = false;
237240
}
238241

242+
private async Task EditTestsConfig(Guid autoTestConfigId)
243+
{
244+
var parameters = new DialogParameters<EditServerAutoTestConfigurationDialog>
245+
{
246+
{ x => x.ConfigurationId, autoTestConfigId }
247+
};
248+
249+
await DialogService.ShowAsync<EditServerAutoTestConfigurationDialog>($"Server Tests Configuration", parameters);
250+
}
239251
}

DbBackupService/Src/Bootstraper/Server/Server.Api/Server.Api.http

Lines changed: 0 additions & 6 deletions
This file was deleted.

DbBackupService/Src/Bootstraper/Server/Server.Api/appsettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"NotifyServiceSettings": {
33
"Env": "Dev",
4-
"Scheme": "{wsProtocol}",
5-
"DevelopmentPort": "{url.port}",
4+
"Scheme": "https",
5+
"DevelopmentPort": "5000",
66
"ProductionHost": "production.example.com"
77
},
88
"Logging": {
@@ -22,7 +22,7 @@
2222
"MainAdminEmailAddress": "admin@octo.com"
2323
},
2424
"AllowedHosts": "*",
25-
"AllowedOrigins": "{wsProtocol}://{url.hostname}:{url.port}",
25+
"AllowedOrigins": "https://localhost, https://localhost:5000, https://localhost:5001",
2626
"https_port": 443,
2727
"SeqConfiguration": {
2828
"ApiKey": "",

DbBackupService/Src/Bootstraper/Server/Server.Api/databasesConfigurations.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

DbBackupService/Src/Bootstraper/Server/Server.Api/oldProgram.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

DbBackupService/Src/Modules/AuthModule/Modules.Auth.Application/Services/TokenValidationService.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@ namespace Modules.Auth.Application.Services;
99
internal class TokenValidationService(IUserTokenService tokensRepoService, ILogger<TokenValidationService> logger)
1010
: ITokenValidationService
1111
{
12+
// TODO: Add this to configurable section in admin's configuration panel
13+
private readonly bool _enableTokenLogging = false;
14+
1215
public OneOf<True, False> IsValid(string? token, string? userEmail)
1316
{
14-
logger.LogInformation("Validating token {Token} for user {Email}...", token, userEmail);
17+
if(_enableTokenLogging)
18+
logger.LogInformation("Validating token {Token} for user {Email}...", token, userEmail);
1519

1620
if (string.IsNullOrWhiteSpace(token) || string.IsNullOrWhiteSpace(userEmail))
1721
{
1822
logger.LogInformation("Token or Email is empty.");
1923
return new False();
2024
}
2125

22-
logger.LogDebug("Searching DB with passed token...");
26+
if(_enableTokenLogging)
27+
logger.LogDebug("Searching DB with passed token...");
2328
var userToken = tokensRepoService.GetUserTokens(t =>
2429
t.Token == token &&
2530
t.Email?.ToUpper() == userEmail.ToUpper()).FirstOrDefault();
@@ -42,7 +47,8 @@ public OneOf<True, False> IsValid(string? token, string? userEmail)
4247
return new False();
4348
}
4449

45-
logger.LogInformation("Token {Token} for user {Email} is Valid.", token, userEmail);
50+
if(_enableTokenLogging)
51+
logger.LogInformation("Token {Token} for user {Email} is Valid.", token, userEmail);
4652
return new True();
4753
}
4854
}

DbBackupService/Src/Modules/BackupModule/Modules.Backup.Api/Servers/ServersEo.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public static WebApplication MapServersEndpoints(this WebApplication app)
5959

6060
api.MapPost("TestServerConnection", ServersOperations.TestServerConnection)
6161
.WithSummary("Test server connection and execute test query to check communication with DB");
62+
63+
api.MapPost("FetchAutoTestConfig", ServersOperations.GetAutoTestConfig)
64+
.WithSummary("Get specified server's AutoTest configuration");
65+
66+
api.MapPost("EditAutoTestConfig", ServersOperations.EditAutoTestConfig)
67+
.WithSummary("Edit provided server's AutoTest configuration");
6268

6369
return app;
6470
}
@@ -179,4 +185,10 @@ public static async Task<IResult> TestServerConnection(
179185
{
180186
return await CallFuncAndReturnIResult(service.TestServerConnection, serverId);
181187
}
188+
189+
public static async Task<IResult> GetAutoTestConfig(HttpContext context, [FromServices] ServersService service, [FromBody] Guid configurationId)
190+
=> await CallFuncAndReturnIResult(service.GetAutoTestConfig, configurationId);
191+
192+
public static async Task<IResult> EditAutoTestConfig(HttpContext context, [FromServices] ServersService service, [FromBody] AutoTestBackupConfigDto config)
193+
=> await CallFuncAndReturnIResult(service.EditAutoTestConfig, config);
182194
}

DbBackupService/Src/Modules/BackupModule/Modules.Backup.Application/Services/ServersService.cs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public async Task<OneOf<List<ServerConnectionDto>, string>> GetServers(string? i
7676
DbName = server.DbName,
7777
DbType = server.DbType,
7878
DbUser = server.DbUser,
79-
IsTunnelRequired = server.IsTunnelRequired
79+
IsTunnelRequired = server.IsTunnelRequired,
80+
AutoTestBackupsConfigId = server.AutoTestBackupsConfigId
8081
};
8182

8283
var dbTunnel = db.DbServerTunnels.FirstOrDefault(x => x.Id == server.TunnelId);
@@ -212,6 +213,16 @@ public async Task<OneOf<Success, string>> CreateServer(ServerConnectionDto newSe
212213
IsDisabled = false
213214
};
214215

216+
var serverAutoTestBackupConfig = new AutomaticBackupTestConfig
217+
{
218+
Id = Guid.CreateVersion7(),
219+
// TODO: Change this to global setting that is configurable in admin's config panel
220+
IsEnabled = false,
221+
ServerId = dbServer.Id
222+
};
223+
224+
dbServer.AutoTestBackupsConfigId = serverAutoTestBackupConfig.Id;
225+
215226
// 3. Obsługa tunelu (opcjonalna)
216227
if (newServer.IsTunnelRequired)
217228
{
@@ -243,7 +254,8 @@ public async Task<OneOf<Success, string>> CreateServer(ServerConnectionDto newSe
243254

244255
// 4. Zapis serwera
245256
db.DbConnections.Add(dbServer);
246-
257+
db.AutomaticBackupTestConfigs.Add(serverAutoTestBackupConfig);
258+
247259
if (string.IsNullOrWhiteSpace(identityName))
248260
return "Can't access username";
249261

@@ -638,6 +650,9 @@ public async Task<OneOf<Success, string>> DeleteServer(Guid serverId)
638650

639651
var serverBackupConfig = db.Configurations.FirstOrDefault(x => x.ServerId == serverId);
640652
if (serverBackupConfig is not null) db.Configurations.Remove(serverBackupConfig);
653+
654+
var serverAutoTestConfig = db.AutomaticBackupTestConfigs.FirstOrDefault(x => x.ServerId == serverId);
655+
if (serverAutoTestConfig is not null) db.AutomaticBackupTestConfigs.Remove(serverAutoTestConfig);
641656

642657
var backups = db.Backups.Where(x => x.ServerConnectionId == server.Id);
643658
if (backups.Any())
@@ -657,4 +672,35 @@ public async Task<OneOf<Success, string>> DeleteServer(Guid serverId)
657672

658673
return new Success();
659674
}
675+
676+
677+
public async Task<OneOf<AutoTestBackupConfigDto, string>> GetAutoTestConfig(Guid configId)
678+
{
679+
if (configId == Guid.Empty)
680+
return "Invalid config id";
681+
682+
logger.LogInformation("Checking if config [{ConfigId}] exists...", configId);
683+
684+
var config = await db.AutomaticBackupTestConfigs.FindAsync(configId);
685+
if (config is null)
686+
return "Can't find config";
687+
688+
return new AutoTestBackupConfigDto
689+
{
690+
Id = config.Id,
691+
IsEnabled = config.IsEnabled
692+
};
693+
}
694+
695+
public async Task<OneOf<Success, string>> EditAutoTestConfig(AutoTestBackupConfigDto config)
696+
{
697+
var dbConfig = await db.AutomaticBackupTestConfigs.FindAsync(config.Id);
698+
if (dbConfig is null)
699+
return "Can't find config";
700+
701+
dbConfig.IsEnabled = config.IsEnabled;
702+
await db.SaveChangesAsync();
703+
704+
return new Success();
705+
}
660706
}

0 commit comments

Comments
 (0)