feat(grpc-data): X0 node-side tolerant readers drop unknown operation bits per row (counted) instead of rejecting the snapshot
Covers the deployment runtime (plan site) plus two node-side validator passes the plan missed: DeploymentArtifact data-row parse and LocalExportCatalog.Compile now use DataConnectionValidator.ValidateDeployed. Authoring (Validate) still rejects the reserved bits.
This commit is contained in:
@@ -9,17 +9,33 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Validation;
|
||||
/// <summary>Validates deployed data-service configuration without resolving consumer-side secrets.</summary>
|
||||
public static class DataConnectionValidator
|
||||
{
|
||||
private const DataOperations KnownOperations = DataOperations.Browse | DataOperations.Metadata |
|
||||
DataOperations.Read | DataOperations.Write | DataOperations.Subscribe;
|
||||
/// <summary>
|
||||
/// The operations AUTHORING may grant. Deliberately the v1 set: it grows only in the phase that implements a bit
|
||||
/// (H2, A2), so authoring cannot get ahead of the code (plan section 4.3, "grow site").
|
||||
/// </summary>
|
||||
private const DataOperations KnownOperations = DataOperationSets.V1;
|
||||
private static readonly StringComparer Ids = StringComparer.OrdinalIgnoreCase;
|
||||
|
||||
public static IReadOnlyList<ValidationError> Validate(DraftSnapshot draft)
|
||||
/// <summary>Authoring/deploy-gate validation: an operation bit outside the known set is an error.</summary>
|
||||
public static IReadOnlyList<ValidationError> Validate(DraftSnapshot draft) => Validate(draft, deployed: false);
|
||||
|
||||
/// <summary>
|
||||
/// Node-side re-validation of an already-deployed artifact (artifact parse, origin catalog compile). Identical to
|
||||
/// <see cref="Validate(DraftSnapshot)"/> except that operation bits this build does not understand are IGNORED
|
||||
/// rather than rejected (X0 tolerant reader): a newer central may author them, and rejecting would take down every
|
||||
/// data connection/export on the node. Each consumer of the rows keeps only the bits it understands (fail closed).
|
||||
/// </summary>
|
||||
public static IReadOnlyList<ValidationError> ValidateDeployed(DraftSnapshot draft) => Validate(draft, deployed: true);
|
||||
|
||||
private static IReadOnlyList<ValidationError> Validate(DraftSnapshot draft, bool deployed)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(draft);
|
||||
var errors = new List<ValidationError>();
|
||||
void Add(string code, string id, string message) => errors.Add(new(code, message, id));
|
||||
bool Same(string? a, string? b) => Ids.Equals(a, b);
|
||||
bool ValidOps(DataOperations operations) => operations != DataOperations.None && (operations & ~KnownOperations) == 0;
|
||||
bool ValidOps(DataOperations operations) => operations != DataOperations.None &&
|
||||
(deployed || (operations & ~KnownOperations) == 0);
|
||||
DataOperations Understood(DataOperations operations) => deployed ? operations & DataOperationSets.Understood : operations;
|
||||
bool NodesValid(IEnumerable<string> ids, string owner)
|
||||
{
|
||||
var list = ids.ToList();
|
||||
@@ -251,7 +267,7 @@ public static class DataConnectionValidator
|
||||
Same(other.ClusterId, mapping.ClusterId) && other.Realm == mapping.Realm && Same(other.LocalParentKind, mapping.LocalParentKind) &&
|
||||
Same(other.LocalParentId, mapping.LocalParentId) && string.Equals(other.BranchName, mapping.BranchName, StringComparison.Ordinal)))
|
||||
Add("DataMappingNameCollision", id, "A mapping branch collides with an existing sibling.");
|
||||
if (!ValidOps(mapping.AllowedOperations) || connection is null || (mapping.AllowedOperations & ~connection.AllowedOperations) != 0 ||
|
||||
if (!ValidOps(mapping.AllowedOperations) || connection is null || (Understood(mapping.AllowedOperations) & ~connection.AllowedOperations) != 0 ||
|
||||
(mapping.AllowedOperations.HasFlag(DataOperations.Write) && !mapping.WriteThrough))
|
||||
Add("DataMappingOperationsInvalid", id, "Mapping operations must be permitted by the connection and write-through policy.");
|
||||
if (mapping.MaxProjectionNodes <= 0 || mapping.MaxProjectionDepth <= 0 || mapping.MetadataLeaseMilliseconds <= 0 ||
|
||||
|
||||
Reference in New Issue
Block a user