refactor: Remove unused properties and methods from VexExportManifestRecord and VexConsensusRecord
This commit is contained in:
		| @@ -90,18 +90,6 @@ internal sealed class VexExportManifestRecord | |||||||
|     public string? ConsensusRevision { get; set; } |     public string? ConsensusRevision { get; set; } | ||||||
|         = null; |         = 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; } |     public string? PredicateType { get; set; } | ||||||
|         = null; |         = null; | ||||||
|  |  | ||||||
| @@ -139,10 +127,6 @@ internal sealed class VexExportManifestRecord | |||||||
|             FromCache = manifest.FromCache, |             FromCache = manifest.FromCache, | ||||||
|             SourceProviders = manifest.SourceProviders.ToList(), |             SourceProviders = manifest.SourceProviders.ToList(), | ||||||
|             ConsensusRevision = manifest.ConsensusRevision, |             ConsensusRevision = manifest.ConsensusRevision, | ||||||
|             PolicyRevisionId = manifest.PolicyRevisionId, |  | ||||||
|             PolicyDigest = manifest.PolicyDigest, |  | ||||||
|             ConsensusDigest = manifest.ConsensusDigest?.ToUri(), |  | ||||||
|             ScoreDigest = manifest.ScoreDigest?.ToUri(), |  | ||||||
|             PredicateType = manifest.Attestation?.PredicateType, |             PredicateType = manifest.Attestation?.PredicateType, | ||||||
|             RekorApiVersion = manifest.Attestation?.Rekor?.ApiVersion, |             RekorApiVersion = manifest.Attestation?.Rekor?.ApiVersion, | ||||||
|             RekorLocation = manifest.Attestation?.Rekor?.Location, |             RekorLocation = manifest.Attestation?.Rekor?.Location, | ||||||
| @@ -183,40 +167,10 @@ internal sealed class VexExportManifestRecord | |||||||
|             SourceProviders, |             SourceProviders, | ||||||
|             FromCache, |             FromCache, | ||||||
|             ConsensusRevision, |             ConsensusRevision, | ||||||
|             PolicyRevisionId, |  | ||||||
|             PolicyDigest, |  | ||||||
|             ParseContentAddress(ConsensusDigest), |  | ||||||
|             ParseContentAddress(ScoreDigest), |  | ||||||
|             attestation, |             attestation, | ||||||
|             SizeBytes); |             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) |     public static string CreateId(VexQuerySignature signature, VexExportFormat format) | ||||||
|         => string.Format(CultureInfo.InvariantCulture, "{0}|{1}", signature.Value, format.ToString().ToLowerInvariant()); |         => string.Format(CultureInfo.InvariantCulture, "{0}|{1}", signature.Value, format.ToString().ToLowerInvariant()); | ||||||
| } | } | ||||||
| @@ -357,9 +311,6 @@ internal sealed class VexConsensusRecord | |||||||
|  |  | ||||||
|     public List<VexConsensusConflictDocument> Conflicts { get; set; } = new(); |     public List<VexConsensusConflictDocument> Conflicts { get; set; } = new(); | ||||||
|  |  | ||||||
|     public VexSignalDocument? Signals { get; set; } |  | ||||||
|         = null; |  | ||||||
|  |  | ||||||
|     public string? PolicyVersion { get; set; } |     public string? PolicyVersion { get; set; } | ||||||
|         = null; |         = null; | ||||||
|  |  | ||||||
| @@ -372,9 +323,6 @@ internal sealed class VexConsensusRecord | |||||||
|     public string? Summary { get; set; } |     public string? Summary { get; set; } | ||||||
|         = null; |         = null; | ||||||
|  |  | ||||||
|     public DateTime GeneratedAt { get; set; } |  | ||||||
|         = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); |  | ||||||
|  |  | ||||||
|     public static string CreateId(string vulnerabilityId, string productKey) |     public static string CreateId(string vulnerabilityId, string productKey) | ||||||
|         => string.Format(CultureInfo.InvariantCulture, "{0}|{1}", vulnerabilityId.Trim(), productKey.Trim()); |         => string.Format(CultureInfo.InvariantCulture, "{0}|{1}", vulnerabilityId.Trim(), productKey.Trim()); | ||||||
|  |  | ||||||
| @@ -388,12 +336,10 @@ internal sealed class VexConsensusRecord | |||||||
|             CalculatedAt = consensus.CalculatedAt.UtcDateTime, |             CalculatedAt = consensus.CalculatedAt.UtcDateTime, | ||||||
|             Sources = consensus.Sources.Select(VexConsensusSourceDocument.FromDomain).ToList(), |             Sources = consensus.Sources.Select(VexConsensusSourceDocument.FromDomain).ToList(), | ||||||
|             Conflicts = consensus.Conflicts.Select(VexConsensusConflictDocument.FromDomain).ToList(), |             Conflicts = consensus.Conflicts.Select(VexConsensusConflictDocument.FromDomain).ToList(), | ||||||
|             Signals = VexSignalDocument.FromDomain(consensus.Signals), |  | ||||||
|             PolicyVersion = consensus.PolicyVersion, |             PolicyVersion = consensus.PolicyVersion, | ||||||
|             PolicyRevisionId = consensus.PolicyRevisionId, |             PolicyRevisionId = consensus.PolicyRevisionId, | ||||||
|             PolicyDigest = consensus.PolicyDigest, |             PolicyDigest = consensus.PolicyDigest, | ||||||
|             Summary = consensus.Summary, |             Summary = consensus.Summary, | ||||||
|             GeneratedAt = consensus.CalculatedAt.UtcDateTime, |  | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|     public VexConsensus ToDomain() |     public VexConsensus ToDomain() | ||||||
| @@ -404,7 +350,6 @@ internal sealed class VexConsensusRecord | |||||||
|             new DateTimeOffset(CalculatedAt, TimeSpan.Zero), |             new DateTimeOffset(CalculatedAt, TimeSpan.Zero), | ||||||
|             Sources.Select(static source => source.ToDomain()), |             Sources.Select(static source => source.ToDomain()), | ||||||
|             Conflicts.Select(static conflict => conflict.ToDomain()), |             Conflicts.Select(static conflict => conflict.ToDomain()), | ||||||
|             Signals?.ToDomain(), |  | ||||||
|             PolicyVersion, |             PolicyVersion, | ||||||
|             Summary, |             Summary, | ||||||
|             PolicyRevisionId, |             PolicyRevisionId, | ||||||
| @@ -534,245 +479,6 @@ internal sealed class VexConsensusConflictDocument | |||||||
|             Reason); |             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<string, string> 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<VexJustification>(Justification, ignoreCase: true); |  | ||||||
|  |  | ||||||
|         var metadata = (AdditionalMetadata ?? new Dictionary<string, string>(StringComparer.Ordinal)) |  | ||||||
|             .ToImmutableDictionary(StringComparer.Ordinal); |  | ||||||
|  |  | ||||||
|         return new VexClaim( |  | ||||||
|             VulnerabilityId, |  | ||||||
|             ProviderId, |  | ||||||
|             Product.ToDomain(), |  | ||||||
|             Enum.Parse<VexClaimStatus>(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<VexDocumentFormat>(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] | [BsonIgnoreExtraElements] | ||||||
| internal sealed class VexConfidenceDocument | internal sealed class VexConfidenceDocument | ||||||
| { | { | ||||||
| @@ -876,31 +582,12 @@ internal sealed class VexConnectorStateDocument | |||||||
|  |  | ||||||
|     public List<string> DocumentDigests { get; set; } = new(); |     public List<string> DocumentDigests { get; set; } = new(); | ||||||
|  |  | ||||||
|     public Dictionary<string, string> 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) |     public static VexConnectorStateDocument FromRecord(VexConnectorState state) | ||||||
|         => new() |         => new() | ||||||
|         { |         { | ||||||
|             ConnectorId = state.ConnectorId, |             ConnectorId = state.ConnectorId, | ||||||
|             LastUpdated = state.LastUpdated?.UtcDateTime, |             LastUpdated = state.LastUpdated?.UtcDateTime, | ||||||
|             DocumentDigests = state.DocumentDigests.ToList(), |             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() |     public VexConnectorState ToRecord() | ||||||
| @@ -912,11 +599,6 @@ internal sealed class VexConnectorStateDocument | |||||||
|         return new VexConnectorState( |         return new VexConnectorState( | ||||||
|             ConnectorId, |             ConnectorId, | ||||||
|             lastUpdated, |             lastUpdated, | ||||||
|             DocumentDigests.ToImmutableArray(), |             DocumentDigests.ToImmutableArray()); | ||||||
|             ResumeTokens?.ToImmutableDictionary(StringComparer.Ordinal) ?? ImmutableDictionary<string, string>.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()); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user