|
| 1 | +namespace Sigtran.NET.Core.Utilities; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Describes assembled package publication evidence for gate evaluation. |
| 5 | +/// </summary> |
| 6 | +public sealed class SigtranPackagePublicationEvidenceAssembly |
| 7 | +{ |
| 8 | + /// <summary>Creates an assembled package publication evidence result.</summary> |
| 9 | + /// <param name="credentialReadiness">The package publication credential readiness.</param> |
| 10 | + /// <param name="integrityManifest">The package integrity manifest.</param> |
| 11 | + /// <param name="evidenceManifest">The publication evidence manifest.</param> |
| 12 | + /// <param name="assembledAtUtc">The UTC assembly time.</param> |
| 13 | + public SigtranPackagePublicationEvidenceAssembly( |
| 14 | + SigtranPackagePublicationCredentialReadiness credentialReadiness, |
| 15 | + SigtranPackageIntegrityManifest integrityManifest, |
| 16 | + SigtranPublicationEvidenceManifest evidenceManifest, |
| 17 | + DateTimeOffset assembledAtUtc) |
| 18 | + { |
| 19 | + CredentialReadiness = credentialReadiness ?? throw new ArgumentNullException(nameof(credentialReadiness)); |
| 20 | + IntegrityManifest = integrityManifest ?? throw new ArgumentNullException(nameof(integrityManifest)); |
| 21 | + EvidenceManifest = evidenceManifest ?? throw new ArgumentNullException(nameof(evidenceManifest)); |
| 22 | + AssembledAtUtc = assembledAtUtc.Offset == TimeSpan.Zero ? assembledAtUtc : assembledAtUtc.ToUniversalTime(); |
| 23 | + } |
| 24 | + |
| 25 | + /// <summary>The package publication credential readiness.</summary> |
| 26 | + public SigtranPackagePublicationCredentialReadiness CredentialReadiness { get; } |
| 27 | + |
| 28 | + /// <summary>The package integrity manifest.</summary> |
| 29 | + public SigtranPackageIntegrityManifest IntegrityManifest { get; } |
| 30 | + |
| 31 | + /// <summary>The publication evidence manifest.</summary> |
| 32 | + public SigtranPublicationEvidenceManifest EvidenceManifest { get; } |
| 33 | + |
| 34 | + /// <summary>The UTC assembly time.</summary> |
| 35 | + public DateTimeOffset AssembledAtUtc { get; } |
| 36 | + |
| 37 | + /// <summary>Whether the assembly time is normalized to UTC.</summary> |
| 38 | + public bool HasUtcAssemblyTime => AssembledAtUtc.Offset == TimeSpan.Zero; |
| 39 | + |
| 40 | + /// <summary>Whether package integrity evidence is complete.</summary> |
| 41 | + public bool PackageIntegrityReady => IntegrityManifest.IsComplete |
| 42 | + && EvidenceManifest.PackageIntegrityComplete; |
| 43 | + |
| 44 | + /// <summary>Whether supply-chain promotion evidence is complete.</summary> |
| 45 | + public bool SupplyChainPromotionReady => EvidenceManifest.SupplyChainPromotionReady; |
| 46 | + |
| 47 | + /// <summary>Whether commercial evidence is complete.</summary> |
| 48 | + public bool CommercialEvidenceReady => EvidenceManifest.CommercialEvidenceReady; |
| 49 | + |
| 50 | + /// <summary>Whether assembled evidence can move into release publish guard evaluation.</summary> |
| 51 | + public bool IsReadyForPublishGuard => CredentialReadiness.IsReadyForEvidenceAssembly |
| 52 | + && EvidenceManifest.IsComplete |
| 53 | + && HasUtcAssemblyTime; |
| 54 | + |
| 55 | + /// <summary>Formats a compact package publication evidence assembly summary.</summary> |
| 56 | + /// <returns>The package publication evidence assembly summary.</returns> |
| 57 | + public string Describe() |
| 58 | + { |
| 59 | + return $"packagePublicationEvidenceReady={IsReadyForPublishGuard} integrity={PackageIntegrityReady} supplyChain={SupplyChainPromotionReady} commercialEvidence={CommercialEvidenceReady}"; |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +/// <summary> |
| 64 | +/// Provides package publication evidence assembly helpers. |
| 65 | +/// </summary> |
| 66 | +public static class SigtranPackagePublicationEvidenceAssemblies |
| 67 | +{ |
| 68 | + /// <summary>Assembles package publication evidence from credential readiness and retained evidence gates.</summary> |
| 69 | + /// <param name="credentialReadiness">The package publication credential readiness.</param> |
| 70 | + /// <param name="supplyChainPromotionReady">Whether supply-chain promotion evidence is ready.</param> |
| 71 | + /// <param name="commercialEvidenceReady">Whether commercial evidence is ready.</param> |
| 72 | + /// <param name="assembledAtUtc">The UTC assembly time.</param> |
| 73 | + /// <returns>The package publication evidence assembly.</returns> |
| 74 | + public static SigtranPackagePublicationEvidenceAssembly Assemble( |
| 75 | + SigtranPackagePublicationCredentialReadiness credentialReadiness, |
| 76 | + bool supplyChainPromotionReady, |
| 77 | + bool commercialEvidenceReady, |
| 78 | + DateTimeOffset assembledAtUtc) |
| 79 | + { |
| 80 | + ArgumentNullException.ThrowIfNull(credentialReadiness); |
| 81 | + SigtranPackageIntegrityManifest integrityManifest = credentialReadiness.ArtifactSet.ToIntegrityManifest(); |
| 82 | + bool packageIntegrityComplete = credentialReadiness.ArtifactSet.IsReadyForCredentialEvaluation |
| 83 | + && integrityManifest.IsComplete; |
| 84 | + bool approvedCommercialEvidenceReady = credentialReadiness.ArtifactSet.Request.HandoffGateAllowsPackageEvaluation |
| 85 | + && commercialEvidenceReady; |
| 86 | + |
| 87 | + SigtranPublicationEvidenceManifest evidenceManifest = new( |
| 88 | + credentialReadiness.ArtifactSet.Request.PackageVersion, |
| 89 | + credentialReadiness.ArtifactSet.Request.Channel.Kind, |
| 90 | + packageIntegrityComplete, |
| 91 | + supplyChainPromotionReady, |
| 92 | + approvedCommercialEvidenceReady); |
| 93 | + |
| 94 | + return new(credentialReadiness, integrityManifest, evidenceManifest, assembledAtUtc); |
| 95 | + } |
| 96 | +} |
0 commit comments