feat(mvp): docker-compose snippet in UI, agent flow tests
- Site detail: generate registration token with copy/paste docker-compose snippet - Docker snippet: pre-filled with token + agent hostname, ready to copy - Agents integration tests: register with valid token, heartbeat with API key, invalid token rejection (3 new tests) - TokenResult DTO for API client - IJSRuntime clipboard copy for docker-compose snippet
This commit is contained in:
1 parent
2ea82504d7
commit
d4a86b8c7f
3 files changed
+229
-1
No files matched your search
@@ -4,6 +4,7 @@
|
||||
@inject HeimdallApiClient Api
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Nav
|
||||
@inject IJSRuntime Js
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mb-6">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Videocam" Class="mr-2" />
|
||||
@@ -44,7 +45,56 @@ else
|
||||
</MudGrid>
|
||||
</MudPaper>
|
||||
|
||||
<MudText Typo="Typo.h6" Class="mb-4">Navigation rapide</MudText>
|
||||
@* Token d'enregistrement *@
|
||||
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
||||
<MudText Typo="Typo.h6" Class="mb-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Key" Class="mr-1" />
|
||||
Token d'enregistrement agent
|
||||
</MudText>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_generatedToken))
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Class="mb-4">
|
||||
<strong>Token d'enregistrement :</strong><br />
|
||||
<code class="d-block mt-2 p-2" style="background:#fff;word-break:break-all;font-size:0.9rem;">
|
||||
@_generatedToken
|
||||
</code>
|
||||
<MudText Typo="Typo.body2" Color="Color.Warning" Class="mt-2">
|
||||
⚠ Copiez ce token maintenant. Il ne sera plus jamais affiché.
|
||||
</MudText>
|
||||
<MudText Typo="Typo.body2" Class="mt-1">
|
||||
Expire le : @_tokenExpiresAt.ToString("g")
|
||||
</MudText>
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Warning" OnClick="@GenerateToken" Disabled="@_generating">
|
||||
@if (_generating) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
||||
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" />
|
||||
@(!string.IsNullOrEmpty(_generatedToken) ? "Régénérer" : "Générer un token")
|
||||
</MudButton>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_generatedToken))
|
||||
{
|
||||
<MudText Typo="Typo.subtitle1" Class="mt-6 mb-2">Docker Compose — Agent</MudText>
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-2">
|
||||
Copiez ce bloc dans votre fichier <code>docker-compose.yml</code> pour connecter un agent à ce site :
|
||||
</MudText>
|
||||
|
||||
<MudPaper Class="pa-4" Style="background:#1a1a2e; border-radius:8px;" Elevation="0">
|
||||
<pre style="color:#e0e0e0; font-size:0.85rem; margin:0; white-space:pre-wrap;"><code>@_dockerComposeSnippet</code></pre>
|
||||
</MudPaper>
|
||||
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Primary" Class="mt-2"
|
||||
OnClick="@CopyDockerCompose">
|
||||
<MudIcon Icon="@Icons.Material.Filled.ContentCopy" Class="mr-1" Size="Size.Small" />
|
||||
Copier le docker-compose
|
||||
</MudButton>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@* Navigation rapide *@
|
||||
<MudText Typo="Typo.h6" Class="mb-4">Gestion</MudText>
|
||||
<MudGrid>
|
||||
<MudItem xs="12" sm="4">
|
||||
<MudPaper Elevation="3" Class="pa-4 text-center" Style="border-radius: 12px; cursor: pointer;"
|
||||
@@ -75,6 +125,10 @@ else
|
||||
|
||||
private SiteItem? _site;
|
||||
private bool _loading = true;
|
||||
private bool _generating;
|
||||
private string? _generatedToken;
|
||||
private DateTime _tokenExpiresAt;
|
||||
private string _dockerComposeSnippet = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -85,4 +139,49 @@ else
|
||||
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||||
finally { _loading = false; }
|
||||
}
|
||||
|
||||
private async Task GenerateToken()
|
||||
{
|
||||
_generating = true;
|
||||
try
|
||||
{
|
||||
var result = await Api.GenerateSiteTokenAsync(Id);
|
||||
if (result is null)
|
||||
{
|
||||
Snackbar.Add("Erreur lors de la génération du token", Severity.Error);
|
||||
return;
|
||||
}
|
||||
_generatedToken = result.Token;
|
||||
_tokenExpiresAt = result.ExpiresAt;
|
||||
_dockerComposeSnippet = GenerateDockerComposeSnippet(_generatedToken);
|
||||
Snackbar.Add("Token généré ! Copiez le docker-compose ci-dessous.", Severity.Warning);
|
||||
}
|
||||
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||||
finally { _generating = false; }
|
||||
}
|
||||
|
||||
private string GenerateDockerComposeSnippet(string token)
|
||||
{
|
||||
var hostname = $"agent-{_site?.Name?.ToLower().Replace(" ", "-") ?? "demo"}";
|
||||
return $$"""
|
||||
heimdall-agent:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/Dockerfile.agent
|
||||
environment:
|
||||
HEIMDALL_CENTRAL_URL: "http://heimdall-central:8080"
|
||||
HEIMDALL_SITE_TOKEN: "{{token}}"
|
||||
HEIMDALL_AGENT_NAME: "{{hostname}}"
|
||||
restart: unless-stopped
|
||||
""";
|
||||
}
|
||||
|
||||
private async Task CopyDockerCompose()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_dockerComposeSnippet))
|
||||
{
|
||||
await Js.InvokeVoidAsync("navigator.clipboard.writeText", _dockerComposeSnippet);
|
||||
Snackbar.Add("Docker-compose copié dans le presse-papier", Severity.Success);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user