Initial commit: ESB Certificate Manager.
EOF Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using ZA.CoreService.ESBCertificateManager.Models;
|
||||
|
||||
namespace ZA.CoreService.ESBCertificateManager.Data;
|
||||
|
||||
public sealed class JsonTargetRepository : ITargetRepository
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
|
||||
private readonly string _filePath;
|
||||
|
||||
public JsonTargetRepository(string filePath)
|
||||
{
|
||||
_filePath = filePath;
|
||||
}
|
||||
|
||||
public string SourceDescription => $"Offline-Sample ({Path.GetFileName(_filePath)})";
|
||||
|
||||
public async Task<IReadOnlyList<DeploymentTarget>> GetActiveTargetsAsync(
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (!File.Exists(_filePath))
|
||||
{
|
||||
throw new FileNotFoundException(
|
||||
$"Sample-Zieldatei wurde nicht gefunden: {_filePath}",
|
||||
_filePath);
|
||||
}
|
||||
|
||||
await using FileStream stream = File.OpenRead(_filePath);
|
||||
List<DeploymentTarget>? targets = await JsonSerializer.DeserializeAsync<List<DeploymentTarget>>(
|
||||
stream,
|
||||
JsonOptions,
|
||||
cancellationToken);
|
||||
|
||||
return (targets ?? [])
|
||||
.Where(t => t.IsActive)
|
||||
.OrderBy(t => t.SortOrder)
|
||||
.ThenBy(t => t.Name)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user