Merge branch 'review/wp2' into review/integration
This commit is contained in:
@@ -2088,16 +2088,25 @@ public class ManagementActor : ReceiveActor
|
||||
|
||||
private static async Task<object?> HandleUpdateSite(IServiceProvider sp, UpdateSiteCommand cmd, string user)
|
||||
{
|
||||
ValidateSiteGrpcAddresses(cmd.GrpcNodeAAddress, cmd.GrpcNodeBAddress);
|
||||
var repo = sp.GetRequiredService<ISiteRepository>();
|
||||
var site = await repo.GetSiteByIdAsync(cmd.SiteId)
|
||||
?? throw new ManagementCommandException($"Site with ID {cmd.SiteId} not found.");
|
||||
site.Name = cmd.Name;
|
||||
site.Description = cmd.Description;
|
||||
site.NodeAAddress = cmd.NodeAAddress;
|
||||
site.NodeBAddress = cmd.NodeBAddress;
|
||||
site.GrpcNodeAAddress = cmd.GrpcNodeAAddress;
|
||||
site.GrpcNodeBAddress = cmd.GrpcNodeBAddress;
|
||||
// CLI-2: preserve-if-null partial update. Validate the EFFECTIVE addresses
|
||||
// (the merge of the command and the stored row) before anything is written.
|
||||
var grpcNodeA = PartialUpdate.Optional(cmd.GrpcNodeAAddress, site.GrpcNodeAAddress);
|
||||
var grpcNodeB = PartialUpdate.Optional(cmd.GrpcNodeBAddress, site.GrpcNodeBAddress);
|
||||
ValidateSiteGrpcAddresses(grpcNodeA, grpcNodeB);
|
||||
if (cmd.Name is not null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cmd.Name))
|
||||
throw new ManagementCommandException("Site name must not be empty.");
|
||||
site.Name = cmd.Name;
|
||||
}
|
||||
site.Description = PartialUpdate.Optional(cmd.Description, site.Description);
|
||||
site.NodeAAddress = PartialUpdate.Optional(cmd.NodeAAddress, site.NodeAAddress);
|
||||
site.NodeBAddress = PartialUpdate.Optional(cmd.NodeBAddress, site.NodeBAddress);
|
||||
site.GrpcNodeAAddress = grpcNodeA;
|
||||
site.GrpcNodeBAddress = grpcNodeB;
|
||||
await repo.UpdateSiteAsync(site);
|
||||
await repo.SaveChangesAsync();
|
||||
var commService = sp.GetService<CommunicationService>();
|
||||
@@ -2260,14 +2269,33 @@ public class ManagementActor : ReceiveActor
|
||||
var repo = sp.GetRequiredService<ISiteRepository>();
|
||||
var conn = await repo.GetDataConnectionByIdAsync(cmd.DataConnectionId)
|
||||
?? throw new ManagementCommandException($"DataConnection with ID {cmd.DataConnectionId} not found.");
|
||||
conn.Name = cmd.Name;
|
||||
conn.Protocol = cmd.Protocol;
|
||||
// CLI-2: preserve-if-null partial update — an omitted field keeps the stored
|
||||
// value; an empty string clears an optional configuration.
|
||||
if (cmd.Name is not null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cmd.Name))
|
||||
throw new ManagementCommandException("Data connection name must not be empty.");
|
||||
conn.Name = cmd.Name;
|
||||
}
|
||||
if (cmd.Protocol is not null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cmd.Protocol))
|
||||
throw new ManagementCommandException("Data connection protocol must not be empty.");
|
||||
conn.Protocol = cmd.Protocol;
|
||||
}
|
||||
// Sentinel-preserving merge: a client that round-trips a scrubbed config
|
||||
// (secrets replaced with the redaction sentinel) keeps the stored secret
|
||||
// rather than wiping it. Non-sentinel values overwrite as usual.
|
||||
conn.PrimaryConfiguration = ConfigSecretScrubber.MergeSentinels(cmd.PrimaryConfiguration, conn.PrimaryConfiguration);
|
||||
conn.BackupConfiguration = ConfigSecretScrubber.MergeSentinels(cmd.BackupConfiguration, conn.BackupConfiguration);
|
||||
conn.FailoverRetryCount = cmd.FailoverRetryCount;
|
||||
if (cmd.PrimaryConfiguration is not null)
|
||||
conn.PrimaryConfiguration = string.IsNullOrWhiteSpace(cmd.PrimaryConfiguration)
|
||||
? null
|
||||
: ConfigSecretScrubber.MergeSentinels(cmd.PrimaryConfiguration, conn.PrimaryConfiguration);
|
||||
if (cmd.BackupConfiguration is not null)
|
||||
conn.BackupConfiguration = string.IsNullOrWhiteSpace(cmd.BackupConfiguration)
|
||||
? null
|
||||
: ConfigSecretScrubber.MergeSentinels(cmd.BackupConfiguration, conn.BackupConfiguration);
|
||||
if (cmd.FailoverRetryCount is { } failoverRetryCount)
|
||||
conn.FailoverRetryCount = failoverRetryCount;
|
||||
await repo.UpdateDataConnectionAsync(conn);
|
||||
await repo.SaveChangesAsync();
|
||||
var publicShape = DataConnectionPublicShape(conn);
|
||||
@@ -4006,10 +4034,19 @@ public class ManagementActor : ReceiveActor
|
||||
var repo = sp.GetRequiredService<IInboundApiRepository>();
|
||||
var method = await repo.GetApiMethodByIdAsync(cmd.ApiMethodId)
|
||||
?? throw new ManagementCommandException($"ApiMethod with ID {cmd.ApiMethodId} not found.");
|
||||
method.Script = cmd.Script;
|
||||
method.TimeoutSeconds = cmd.TimeoutSeconds;
|
||||
method.ParameterDefinitions = cmd.ParameterDefinitions;
|
||||
method.ReturnDefinition = cmd.ReturnDefinition;
|
||||
// CLI-2: preserve-if-null partial update — an omitted field keeps the stored
|
||||
// value (an omitted --timeout used to reset it to 30 and drop both
|
||||
// definitions); an empty string clears an optional definition.
|
||||
if (cmd.Script is not null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cmd.Script))
|
||||
throw new ManagementCommandException("API method script must not be empty.");
|
||||
method.Script = cmd.Script;
|
||||
}
|
||||
if (cmd.TimeoutSeconds is { } timeoutSeconds)
|
||||
method.TimeoutSeconds = timeoutSeconds;
|
||||
method.ParameterDefinitions = PartialUpdate.Optional(cmd.ParameterDefinitions, method.ParameterDefinitions);
|
||||
method.ReturnDefinition = PartialUpdate.Optional(cmd.ReturnDefinition, method.ReturnDefinition);
|
||||
if (cmd.TraceAllCalls is { } traceAllCalls)
|
||||
method.TraceAllCalls = traceAllCalls;
|
||||
await repo.UpdateApiMethodAsync(method);
|
||||
@@ -4676,7 +4713,13 @@ public class ManagementActor : ReceiveActor
|
||||
// is safe even when ApplyAsync already released the same id.
|
||||
try
|
||||
{
|
||||
var preview = await importer.PreviewAsync(session.SessionId);
|
||||
// TRN-3: an explicit --map-site / --map-connection redirect changes what
|
||||
// the site-scoped preview rows resolve against, so the preview (and its
|
||||
// unresolved-connection blockers and auto-matches) runs under those
|
||||
// redirects — otherwise a connection present only on the MAPPED site was
|
||||
// a blocker no mapping could clear.
|
||||
var preview = await importer.PreviewAsync(
|
||||
session.SessionId, nameMap: BuildExplicitRedirectMap(cmd));
|
||||
|
||||
var blockers = preview.Items.Where(i => i.Kind == ConflictKind.Blocker).ToList();
|
||||
if (blockers.Count > 0)
|
||||
@@ -4702,6 +4745,7 @@ public class ManagementActor : ReceiveActor
|
||||
// automatically correct — no bare-connection-name special case needed.
|
||||
var renameStamp = DateTime.UtcNow.ToString("yyyyMMdd-HHmmss");
|
||||
var resolutionsMap = new Dictionary<(string, string), ImportResolution>();
|
||||
var renameFallbacks = new SortedSet<string>(StringComparer.Ordinal);
|
||||
foreach (var item in preview.Items)
|
||||
{
|
||||
var action = item.Kind switch
|
||||
@@ -4711,15 +4755,31 @@ public class ManagementActor : ReceiveActor
|
||||
ConflictKind.Modified => policy,
|
||||
_ => ResolutionAction.Skip,
|
||||
};
|
||||
var renameTo = (item.Kind == ConflictKind.Modified && policy == ResolutionAction.Rename)
|
||||
// TRN-9: --conflict-policy rename has no meaning for a site, data
|
||||
// connection or SMTP/SMS configuration (the importer rejects it);
|
||||
// fall back to Skip for those and say so in the result.
|
||||
if (action == ResolutionAction.Rename && !ImportRenameSupport.IsSupported(item.EntityType))
|
||||
{
|
||||
action = ResolutionAction.Skip;
|
||||
renameFallbacks.Add($"{item.EntityType} '{item.Name}'");
|
||||
}
|
||||
var renameTo = (item.Kind == ConflictKind.Modified && action == ResolutionAction.Rename)
|
||||
? $"{item.Name}-imported-{renameStamp}"
|
||||
: null;
|
||||
resolutionsMap[(item.EntityType, item.Name)] = new ImportResolution(
|
||||
item.EntityType, item.Name, action, renameTo);
|
||||
}
|
||||
|
||||
return await importer.ApplyAsync(
|
||||
var importResult = await importer.ApplyAsync(
|
||||
session.SessionId, resolutionsMap.Values.ToList(), username, nameMap: nameMap);
|
||||
if (renameFallbacks.Count == 0) return importResult;
|
||||
return importResult with
|
||||
{
|
||||
Warnings = importResult.Warnings
|
||||
.Concat(renameFallbacks.Select(f =>
|
||||
$"{f} was skipped: Rename is not supported for sites, data connections, SMTP or SMS configurations."))
|
||||
.ToList(),
|
||||
};
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -4732,6 +4792,27 @@ public class ManagementActor : ReceiveActor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TRN-3: the operator's explicit MapToExisting redirects (a <c>--map-site</c> /
|
||||
/// <c>--map-connection</c> with a target) as a <see cref="BundleNameMap"/> for the
|
||||
/// preview, or <c>null</c> when there are none (the preview then keeps its identity
|
||||
/// auto-match). Create-new specs are not redirects and are left to
|
||||
/// <see cref="BuildNameMap"/>.
|
||||
/// </summary>
|
||||
private static BundleNameMap? BuildExplicitRedirectMap(ImportBundleCommand cmd)
|
||||
{
|
||||
var sites = (cmd.SiteMappings ?? Array.Empty<SiteMappingSpec>())
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s.TargetSiteIdentifier))
|
||||
.Select(s => new SiteMapping(s.SourceSiteIdentifier, MappingAction.MapToExisting, s.TargetSiteIdentifier))
|
||||
.ToList();
|
||||
var connections = (cmd.ConnectionMappings ?? Array.Empty<ConnectionMappingSpec>())
|
||||
.Where(c => !string.IsNullOrWhiteSpace(c.TargetConnectionName))
|
||||
.Select(c => new ConnectionMapping(
|
||||
c.SourceSiteIdentifier, c.SourceConnectionName, MappingAction.MapToExisting, c.TargetConnectionName))
|
||||
.ToList();
|
||||
return sites.Count == 0 && connections.Count == 0 ? null : new BundleNameMap(sites, connections);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges the operator-supplied <see cref="SiteMappingSpec"/> /
|
||||
/// <see cref="ConnectionMappingSpec"/> lists with the preview's auto-matches
|
||||
|
||||
Reference in New Issue
Block a user