From 8e7ce55542fea7fabb0e31cb3721357af1a42a8d Mon Sep 17 00:00:00 2001 From: master Date: Sun, 19 Oct 2025 23:28:53 +0300 Subject: [PATCH] refactor: Remove unused properties and methods from VexExportManifestRecord and VexConsensusRecord --- .../VexMongoModels.cs | 320 +----------------- 1 file changed, 1 insertion(+), 319 deletions(-) diff --git a/src/StellaOps.Excititor.Storage.Mongo/VexMongoModels.cs b/src/StellaOps.Excititor.Storage.Mongo/VexMongoModels.cs index 55258eb9..f6ac4ec7 100644 --- a/src/StellaOps.Excititor.Storage.Mongo/VexMongoModels.cs +++ b/src/StellaOps.Excititor.Storage.Mongo/VexMongoModels.cs @@ -90,18 +90,6 @@ internal sealed class VexExportManifestRecord public string? ConsensusRevision { get; set; } = null; - public string? PolicyRevisionId { get; set; } - = null; - - public string? PolicyDigest { get; set; } - = null; - - public string? ConsensusDigest { get; set; } - = null; - - public string? ScoreDigest { get; set; } - = null; - public string? PredicateType { get; set; } = null; @@ -139,10 +127,6 @@ internal sealed class VexExportManifestRecord FromCache = manifest.FromCache, SourceProviders = manifest.SourceProviders.ToList(), ConsensusRevision = manifest.ConsensusRevision, - PolicyRevisionId = manifest.PolicyRevisionId, - PolicyDigest = manifest.PolicyDigest, - ConsensusDigest = manifest.ConsensusDigest?.ToUri(), - ScoreDigest = manifest.ScoreDigest?.ToUri(), PredicateType = manifest.Attestation?.PredicateType, RekorApiVersion = manifest.Attestation?.Rekor?.ApiVersion, RekorLocation = manifest.Attestation?.Rekor?.Location, @@ -183,40 +167,10 @@ internal sealed class VexExportManifestRecord SourceProviders, FromCache, ConsensusRevision, - PolicyRevisionId, - PolicyDigest, - ParseContentAddress(ConsensusDigest), - ParseContentAddress(ScoreDigest), attestation, SizeBytes); } - private static VexContentAddress? ParseContentAddress(string? value) - { - if (string.IsNullOrWhiteSpace(value)) - { - return null; - } - - var separatorIndex = value.IndexOf(':'); - if (separatorIndex <= 0 || separatorIndex >= value.Length - 1) - { - return null; - } - - var algorithm = value.Substring(0, separatorIndex); - var digest = value.Substring(separatorIndex + 1); - - try - { - return new VexContentAddress(algorithm, digest); - } - catch - { - return null; - } - } - public static string CreateId(VexQuerySignature signature, VexExportFormat format) => string.Format(CultureInfo.InvariantCulture, "{0}|{1}", signature.Value, format.ToString().ToLowerInvariant()); } @@ -357,9 +311,6 @@ internal sealed class VexConsensusRecord public List Conflicts { get; set; } = new(); - public VexSignalDocument? Signals { get; set; } - = null; - public string? PolicyVersion { get; set; } = null; @@ -372,9 +323,6 @@ internal sealed class VexConsensusRecord public string? Summary { get; set; } = null; - public DateTime GeneratedAt { get; set; } - = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); - public static string CreateId(string vulnerabilityId, string productKey) => string.Format(CultureInfo.InvariantCulture, "{0}|{1}", vulnerabilityId.Trim(), productKey.Trim()); @@ -388,12 +336,10 @@ internal sealed class VexConsensusRecord CalculatedAt = consensus.CalculatedAt.UtcDateTime, Sources = consensus.Sources.Select(VexConsensusSourceDocument.FromDomain).ToList(), Conflicts = consensus.Conflicts.Select(VexConsensusConflictDocument.FromDomain).ToList(), - Signals = VexSignalDocument.FromDomain(consensus.Signals), PolicyVersion = consensus.PolicyVersion, PolicyRevisionId = consensus.PolicyRevisionId, PolicyDigest = consensus.PolicyDigest, Summary = consensus.Summary, - GeneratedAt = consensus.CalculatedAt.UtcDateTime, }; public VexConsensus ToDomain() @@ -404,7 +350,6 @@ internal sealed class VexConsensusRecord new DateTimeOffset(CalculatedAt, TimeSpan.Zero), Sources.Select(static source => source.ToDomain()), Conflicts.Select(static conflict => conflict.ToDomain()), - Signals?.ToDomain(), PolicyVersion, Summary, PolicyRevisionId, @@ -534,245 +479,6 @@ internal sealed class VexConsensusConflictDocument Reason); } -[BsonIgnoreExtraElements] -internal sealed class VexSignalDocument -{ - public VexSeveritySignalDocument? Severity { get; set; } - = null; - - public bool? Kev { get; set; } - = null; - - public double? Epss { get; set; } - = null; - - public static VexSignalDocument? FromDomain(VexSignalSnapshot? signals) - { - if (signals is null) - { - return null; - } - - return new VexSignalDocument - { - Severity = VexSeveritySignalDocument.FromDomain(signals.Severity), - Kev = signals.Kev, - Epss = signals.Epss, - }; - } - - public VexSignalSnapshot ToDomain() - => new( - Severity?.ToDomain(), - Kev, - Epss); -} - -[BsonIgnoreExtraElements] -internal sealed class VexSeveritySignalDocument -{ - public string Scheme { get; set; } = default!; - - public double? Score { get; set; } - = null; - - public string? Label { get; set; } - = null; - - public string? Vector { get; set; } - = null; - - public static VexSeveritySignalDocument? FromDomain(VexSeveritySignal? signal) - { - if (signal is null) - { - return null; - } - - return new VexSeveritySignalDocument - { - Scheme = signal.Scheme, - Score = signal.Score, - Label = signal.Label, - Vector = signal.Vector, - }; - } - - public VexSeveritySignal ToDomain() - => new( - Scheme, - Score, - Label, - Vector); -} - -[BsonIgnoreExtraElements] -internal sealed class VexStatementRecord -{ - [BsonId] - public ObjectId Id { get; set; } - = ObjectId.GenerateNewId(); - - public string VulnerabilityId { get; set; } = default!; - - public string ProviderId { get; set; } = default!; - - public VexProductDocument Product { get; set; } = default!; - - public string Status { get; set; } = default!; - - public string? Justification { get; set; } - = null; - - public string? Detail { get; set; } - = null; - - public VexClaimDocumentRecord Document { get; set; } = default!; - - public DateTime FirstSeen { get; set; } - = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); - - public DateTime LastSeen { get; set; } - = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); - - public VexConfidenceDocument? Confidence { get; set; } - = null; - - public Dictionary AdditionalMetadata { get; set; } = new(StringComparer.Ordinal); - - public VexSignalDocument? Signals { get; set; } - = null; - - public DateTime InsertedAt { get; set; } - = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); - - public static VexStatementRecord FromDomain(VexClaim claim, DateTimeOffset observedAt) - => new() - { - VulnerabilityId = claim.VulnerabilityId, - ProviderId = claim.ProviderId, - Product = VexProductDocument.FromDomain(claim.Product), - Status = claim.Status.ToString().ToLowerInvariant(), - Justification = claim.Justification?.ToString().ToLowerInvariant(), - Detail = claim.Detail, - Document = VexClaimDocumentRecord.FromDomain(claim.Document), - FirstSeen = claim.FirstSeen.UtcDateTime, - LastSeen = claim.LastSeen.UtcDateTime, - Confidence = claim.Confidence is null ? null : VexConfidenceDocument.FromDomain(claim.Confidence), - AdditionalMetadata = claim.AdditionalMetadata.ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.Ordinal), - Signals = VexSignalDocument.FromDomain(claim.Signals), - InsertedAt = observedAt.UtcDateTime, - }; - - public VexClaim ToDomain() - { - VexJustification? justification = string.IsNullOrWhiteSpace(Justification) - ? null - : Enum.Parse(Justification, ignoreCase: true); - - var metadata = (AdditionalMetadata ?? new Dictionary(StringComparer.Ordinal)) - .ToImmutableDictionary(StringComparer.Ordinal); - - return new VexClaim( - VulnerabilityId, - ProviderId, - Product.ToDomain(), - Enum.Parse(Status, ignoreCase: true), - Document.ToDomain(), - new DateTimeOffset(FirstSeen, TimeSpan.Zero), - new DateTimeOffset(LastSeen, TimeSpan.Zero), - justification, - Detail, - Confidence?.ToDomain(), - Signals?.ToDomain(), - metadata); - } -} - -[BsonIgnoreExtraElements] -internal sealed class VexClaimDocumentRecord -{ - public string Format { get; set; } = default!; - - public string Digest { get; set; } = default!; - - public string SourceUri { get; set; } = default!; - - public string? Revision { get; set; } - = null; - - public VexSignatureMetadataDocument? Signature { get; set; } - = null; - - public static VexClaimDocumentRecord FromDomain(VexClaimDocument document) - => new() - { - Format = document.Format.ToString().ToLowerInvariant(), - Digest = document.Digest, - SourceUri = document.SourceUri.ToString(), - Revision = document.Revision, - Signature = document.Signature is null ? null : VexSignatureMetadataDocument.FromDomain(document.Signature), - }; - - public VexClaimDocument ToDomain() - { - var format = Enum.Parse(Format, ignoreCase: true); - return new VexClaimDocument( - format, - Digest, - new Uri(SourceUri), - Revision, - Signature?.ToDomain()); - } -} - -[BsonIgnoreExtraElements] -internal sealed class VexSignatureMetadataDocument -{ - public string Type { get; set; } = default!; - - public string? Subject { get; set; } - = null; - - public string? Issuer { get; set; } - = null; - - public string? KeyId { get; set; } - = null; - - public DateTime? VerifiedAt { get; set; } - = null; - - public string? TransparencyLogReference { get; set; } - = null; - - public static VexSignatureMetadataDocument FromDomain(VexSignatureMetadata metadata) - => new() - { - Type = metadata.Type, - Subject = metadata.Subject, - Issuer = metadata.Issuer, - KeyId = metadata.KeyId, - VerifiedAt = metadata.VerifiedAt?.UtcDateTime, - TransparencyLogReference = metadata.TransparencyLogReference, - }; - - public VexSignatureMetadata ToDomain() - { - var verifiedAt = VerifiedAt.HasValue - ? new DateTimeOffset(DateTime.SpecifyKind(VerifiedAt.Value, DateTimeKind.Utc)) - : (DateTimeOffset?)null; - - return new VexSignatureMetadata( - Type, - Subject, - Issuer, - KeyId, - verifiedAt, - TransparencyLogReference); - } -} - [BsonIgnoreExtraElements] internal sealed class VexConfidenceDocument { @@ -876,31 +582,12 @@ internal sealed class VexConnectorStateDocument public List DocumentDigests { get; set; } = new(); - public Dictionary ResumeTokens { get; set; } = new(StringComparer.Ordinal); - - public DateTime? LastSuccessAt { get; set; } - = null; - - public int FailureCount { get; set; } - = 0; - - public DateTime? NextEligibleRun { get; set; } - = null; - - public string? LastFailureReason { get; set; } - = null; - public static VexConnectorStateDocument FromRecord(VexConnectorState state) => new() { ConnectorId = state.ConnectorId, LastUpdated = state.LastUpdated?.UtcDateTime, DocumentDigests = state.DocumentDigests.ToList(), - ResumeTokens = state.ResumeTokens.ToDictionary(static pair => pair.Key, static pair => pair.Value, StringComparer.Ordinal), - LastSuccessAt = state.LastSuccessAt?.UtcDateTime, - FailureCount = state.FailureCount, - NextEligibleRun = state.NextEligibleRun?.UtcDateTime, - LastFailureReason = state.LastFailureReason, }; public VexConnectorState ToRecord() @@ -912,11 +599,6 @@ internal sealed class VexConnectorStateDocument return new VexConnectorState( ConnectorId, lastUpdated, - DocumentDigests.ToImmutableArray(), - ResumeTokens?.ToImmutableDictionary(StringComparer.Ordinal) ?? ImmutableDictionary.Empty, - LastSuccessAt.HasValue ? new DateTimeOffset(DateTime.SpecifyKind(LastSuccessAt.Value, DateTimeKind.Utc)) : null, - FailureCount, - NextEligibleRun.HasValue ? new DateTimeOffset(DateTime.SpecifyKind(NextEligibleRun.Value, DateTimeKind.Utc)) : null, - string.IsNullOrWhiteSpace(LastFailureReason) ? null : LastFailureReason.Trim()); + DocumentDigests.ToImmutableArray()); } }