feat(storage): stockage configurable par l'IHM — providers Fichier + S3 (Fixes #78)
- IStorageProvider (Application) : Upload/Download/Delete/DeleteBatch/Health - LocalStorageProvider : écriture atomique (tmp + move), anti path-traversal - AlarikStorageProvider : S3-compatible (AWS SDK, ForcePathStyle), upload staging→final (atomique), batch delete 1000/appel (Correctif D6) - StorageProviderFactory : provider résolu depuis les settings DB (storage.provider = Local|S3) avec fallback env, re-résolu à chaque appel - Seed idempotent des clés storage.* (catégorie 'storage') au démarrage - UI : section 'Stockage' dédiée dans SettingsPage (sélecteur Local/S3, champs conditionnels, clé secrète masquée, bouton Tester → POST /api/settings/storage/test) - Tests : 6 LocalStorageProvider (roundtrip, delete, batch, traversal, health) ; Web 217/217, Infrastructure 177/177, Application 391/391
This commit is contained in:
1 parent
2e188e4dda
commit
7d6213696f
11 files changed
+685
-1
No files matched your search
@@ -0,0 +1,162 @@
|
||||
@namespace Heimdall.Web.Components.Settings
|
||||
@inject HeimdallApiClient Api
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-lg);">
|
||||
<div class="d-flex align-center mb-3">
|
||||
<MudText Typo="Typo.h6" Class="flex-grow-1">
|
||||
<i class="fas fa-database mr-2"></i> Stockage
|
||||
</MudText>
|
||||
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary">@_provider</MudChip>
|
||||
</div>
|
||||
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-3">
|
||||
Choisissez le mode de stockage des snapshots et enregistrements : disque local (« Fichier ») ou objet S3 (Alarik/MinIO).
|
||||
</MudText>
|
||||
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="6">
|
||||
<MudSelect T="string" Label="Provider" Variant="Variant.Outlined" Value="@_provider" ValueChanged="async v => await SaveProviderAsync(v)" Immediate="true">
|
||||
<MudSelectItem T="string" Value="@("Local")">Fichier (disque local)</MudSelectItem>
|
||||
<MudSelectItem T="string" Value="@("S3")">S3 (Alarik / MinIO)</MudSelectItem>
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
@if (_provider == "Local")
|
||||
{
|
||||
<MudItem xs="12">
|
||||
<MudTextField T="string" Label="Chemin racine" Variant="Variant.Outlined"
|
||||
Value="@GetValue("storage.local.path")"
|
||||
ValueChanged="OnLocalPathChanged"
|
||||
HelperText="Dossier local où sont écrits snapshots et enregistrements." />
|
||||
</MudItem>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudItem xs="12" md="6">
|
||||
<MudTextField T="string" Label="Endpoint S3" Variant="Variant.Outlined"
|
||||
Value="@GetValue("storage.s3.endpoint")"
|
||||
ValueChanged="OnEndpointChanged"
|
||||
HelperText="Ex : http://alarik:9000" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<MudTextField T="string" Label="Bucket" Variant="Variant.Outlined"
|
||||
Value="@GetValue("storage.s3.bucket")"
|
||||
ValueChanged="OnBucketChanged" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<MudTextField T="string" Label="Clé d'accès" Variant="Variant.Outlined"
|
||||
Value="@GetValue("storage.s3.accessKey")"
|
||||
ValueChanged="OnAccessKeyChanged" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<MudTextField T="string" Label="Clé secrète" Variant="Variant.Outlined"
|
||||
Value="@GetValue("storage.s3.secretKey")" Type="InputType.Password"
|
||||
ValueChanged="OnSecretKeyChanged" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<MudTextField T="string" Label="Région" Variant="Variant.Outlined"
|
||||
Value="@GetValue("storage.s3.region")"
|
||||
ValueChanged="OnRegionChanged" />
|
||||
</MudItem>
|
||||
}
|
||||
</MudGrid>
|
||||
|
||||
<div class="d-flex align-center mt-3">
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.VerifiedUser"
|
||||
OnClick="@TestAsync" Disabled="@_testing">
|
||||
@(_testing ? "Test en cours…" : "Tester la connexion")
|
||||
</MudButton>
|
||||
@if (_testResult is not null)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Class="ml-3"
|
||||
Color="@(_testResult.Healthy == true ? Color.Success : Color.Error)" Variant="Variant.Outlined">
|
||||
@(_testResult.Healthy == true ? "Opérationnel" : _testResult.Configured == false ? "Non configuré" : "Injoignable")
|
||||
</MudChip>
|
||||
}
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
private List<AppSettingItem> _settings = [];
|
||||
private string _provider = "Local";
|
||||
private bool _testing;
|
||||
private StorageTestResult? _testResult;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_settings = await Api.GetSettingsAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// API indisponible (ex : test) — on reste sur les défauts.
|
||||
_settings = [];
|
||||
}
|
||||
_provider = GetValue("storage.provider") ?? "Local";
|
||||
}
|
||||
|
||||
private string? GetValue(string key)
|
||||
=> _settings.FirstOrDefault(s => s.Key == key)?.Value;
|
||||
|
||||
private async Task SaveProviderAsync(string provider)
|
||||
{
|
||||
_provider = provider;
|
||||
await SaveValueAsync("storage.provider", provider);
|
||||
}
|
||||
|
||||
private Task OnLocalPathChanged(string v) => SaveValueAsync("storage.local.path", v);
|
||||
private Task OnEndpointChanged(string v) => SaveValueAsync("storage.s3.endpoint", v);
|
||||
private Task OnBucketChanged(string v) => SaveValueAsync("storage.s3.bucket", v);
|
||||
private Task OnAccessKeyChanged(string v) => SaveValueAsync("storage.s3.accessKey", v);
|
||||
private Task OnSecretKeyChanged(string v) => SaveValueAsync("storage.s3.secretKey", v);
|
||||
private Task OnRegionChanged(string v) => SaveValueAsync("storage.s3.region", v);
|
||||
|
||||
private async Task SaveValueAsync(string key, string? value)
|
||||
{
|
||||
value ??= string.Empty;
|
||||
var existing = _settings.FirstOrDefault(s => s.Key == key);
|
||||
try
|
||||
{
|
||||
if (existing is null)
|
||||
{
|
||||
await Api.CreateSettingAsync(new CreateAppSettingRequest(
|
||||
Key: key, Value: value, Category: "storage",
|
||||
Description: key.StartsWith("storage.s3.secretKey", StringComparison.Ordinal)
|
||||
? "Clé secrète S3" : key,
|
||||
ValueType: "string", AllowedValues: null, AgentScoped: true));
|
||||
}
|
||||
else
|
||||
{
|
||||
await Api.UpdateSettingAsync(key, new UpdateAppSettingRequest(
|
||||
Value: value, Description: existing.Description ?? key,
|
||||
Category: "storage", ValueType: "string", AllowedValues: null, AgentScoped: null));
|
||||
}
|
||||
// Les records sont immuables : recharger plutôt que muter.
|
||||
_settings = await Api.GetSettingsAsync();
|
||||
Snackbar.Add($"Paramètre {key} mis à jour", Severity.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Échec de la mise à jour : {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task TestAsync()
|
||||
{
|
||||
_testing = true;
|
||||
try
|
||||
{
|
||||
_testResult = await Api.TestStorageAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Test impossible : {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_testing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user