feat: implement Phase 6 — Software Deployment
Backend: - SoftwarePackage model (Name, Version, OsType, PackageManager, PackageName, InstallerUrl, Checksum, SilentArgs) - RmmDbContext: SoftwarePackages DbSet + unique index on (Name, Version, OsType) - SoftwarePackagesController: full CRUD with OsType filter - DeployController: POST /api/v1/deploy creates InstallSoftware/UninstallSoftware TaskItem - EF Migration: AddSoftwarePackages (20260319130448) Go Agent: - internal/deployer/deployer.go: Install() and Uninstall() with: - Chocolatey (Windows), apt/dnf (Linux), auto-detect - Direct installer fallback: HTTP download + SHA256 verify + silent install - Supports .msi, .exe (Windows) and .deb, .rpm (Linux) - main.go: COMMAND_TYPE_INSTALL_SOFTWARE and COMMAND_TYPE_UNINSTALL_SOFTWARE routed to deployer Frontend: - SoftwarePage: Katalog tab (CRUD, OS filter, smart package manager select) + Deploy tab - api/types.ts: SoftwarePackage, PackageManager, DeployRequest/Response types - api/client.ts: softwarePackagesApi and deployApi - App.tsx: Software nav item with Package icon Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
63
Backend/src/NexusRMM.Api/Controllers/DeployController.cs
Normal file
63
Backend/src/NexusRMM.Api/Controllers/DeployController.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NexusRMM.Core.Models;
|
||||
using NexusRMM.Infrastructure.Data;
|
||||
|
||||
namespace NexusRMM.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/deploy")]
|
||||
public class DeployController : ControllerBase
|
||||
{
|
||||
private readonly RmmDbContext _db;
|
||||
public DeployController(RmmDbContext db) => _db = db;
|
||||
|
||||
/// <summary>
|
||||
/// Startet Software-Deployment auf einem Agent.
|
||||
/// Erstellt einen TaskItem mit Typ InstallSoftware/UninstallSoftware.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Deploy([FromBody] DeployRequest req)
|
||||
{
|
||||
var agent = await _db.Agents.FindAsync(req.AgentId);
|
||||
if (agent is null) return NotFound(new { error = "Agent nicht gefunden" });
|
||||
|
||||
var pkg = await _db.SoftwarePackages.FindAsync(req.PackageId);
|
||||
if (pkg is null) return NotFound(new { error = "Paket nicht gefunden" });
|
||||
|
||||
var payload = new
|
||||
{
|
||||
packageName = pkg.PackageName,
|
||||
packageManager = pkg.PackageManager,
|
||||
installerUrl = pkg.InstallerUrl ?? "",
|
||||
checksum = pkg.Checksum ?? "",
|
||||
silentArgs = pkg.SilentArgs ?? "",
|
||||
displayName = pkg.Name,
|
||||
version = pkg.Version,
|
||||
};
|
||||
|
||||
var task = new TaskItem
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
AgentId = req.AgentId,
|
||||
Type = req.Action == "uninstall" ? TaskType.UninstallSoftware : TaskType.InstallSoftware,
|
||||
Payload = JsonSerializer.SerializeToElement(payload),
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
};
|
||||
|
||||
_db.Tasks.Add(task);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(Deploy), new { id = task.Id }, new
|
||||
{
|
||||
task.Id,
|
||||
task.AgentId,
|
||||
task.Type,
|
||||
task.Status,
|
||||
PackageName = pkg.Name,
|
||||
Version = pkg.Version,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public record DeployRequest(Guid AgentId, int PackageId, string Action); // Action: "install" | "uninstall"
|
||||
@@ -0,0 +1,85 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NexusRMM.Core.Models;
|
||||
using NexusRMM.Infrastructure.Data;
|
||||
|
||||
namespace NexusRMM.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/software-packages")]
|
||||
public class SoftwarePackagesController : ControllerBase
|
||||
{
|
||||
private readonly RmmDbContext _db;
|
||||
public SoftwarePackagesController(RmmDbContext db) => _db = db;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery] OsType? osType = null)
|
||||
{
|
||||
var q = _db.SoftwarePackages.AsQueryable();
|
||||
if (osType.HasValue) q = q.Where(p => p.OsType == osType.Value);
|
||||
return Ok(await q.OrderBy(p => p.Name).ToListAsync());
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
public async Task<IActionResult> GetById(int id)
|
||||
{
|
||||
var pkg = await _db.SoftwarePackages.FindAsync(id);
|
||||
return pkg is null ? NotFound() : Ok(pkg);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateSoftwarePackageRequest req)
|
||||
{
|
||||
var pkg = new SoftwarePackage
|
||||
{
|
||||
Name = req.Name,
|
||||
Version = req.Version,
|
||||
OsType = req.OsType,
|
||||
PackageManager = req.PackageManager,
|
||||
PackageName = req.PackageName,
|
||||
InstallerUrl = req.InstallerUrl,
|
||||
Checksum = req.Checksum,
|
||||
SilentArgs = req.SilentArgs,
|
||||
};
|
||||
_db.SoftwarePackages.Add(pkg);
|
||||
await _db.SaveChangesAsync();
|
||||
return CreatedAtAction(nameof(GetById), new { id = pkg.Id }, pkg);
|
||||
}
|
||||
|
||||
[HttpPut("{id:int}")]
|
||||
public async Task<IActionResult> Update(int id, [FromBody] CreateSoftwarePackageRequest req)
|
||||
{
|
||||
var pkg = await _db.SoftwarePackages.FindAsync(id);
|
||||
if (pkg is null) return NotFound();
|
||||
pkg.Name = req.Name;
|
||||
pkg.Version = req.Version;
|
||||
pkg.OsType = req.OsType;
|
||||
pkg.PackageManager = req.PackageManager;
|
||||
pkg.PackageName = req.PackageName;
|
||||
pkg.InstallerUrl = req.InstallerUrl;
|
||||
pkg.Checksum = req.Checksum;
|
||||
pkg.SilentArgs = req.SilentArgs;
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok(pkg);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:int}")]
|
||||
public async Task<IActionResult> Delete(int id)
|
||||
{
|
||||
var pkg = await _db.SoftwarePackages.FindAsync(id);
|
||||
if (pkg is null) return NotFound();
|
||||
_db.SoftwarePackages.Remove(pkg);
|
||||
await _db.SaveChangesAsync();
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
public record CreateSoftwarePackageRequest(
|
||||
string Name,
|
||||
string Version,
|
||||
OsType OsType,
|
||||
string PackageManager,
|
||||
string PackageName,
|
||||
string? InstallerUrl,
|
||||
string? Checksum,
|
||||
string? SilentArgs);
|
||||
Reference in New Issue
Block a user