Files
git.stella-ops.org/src/Policy/__Libraries/StellaOps.Policy/Licensing/LicenseComplianceModels.cs
2026-01-22 19:08:46 +02:00

121 lines
3.5 KiB
C#

using System.Collections.Immutable;
namespace StellaOps.Policy.Licensing;
public interface ILicenseComplianceEvaluator
{
Task<LicenseComplianceReport> EvaluateAsync(
IReadOnlyList<LicenseComponent> components,
LicensePolicy policy,
CancellationToken ct = default);
}
public sealed record LicenseComponent
{
public required string Name { get; init; }
public string? Version { get; init; }
public string? Purl { get; init; }
public string? LicenseExpression { get; init; }
public ImmutableArray<string> Licenses { get; init; } = [];
public ImmutableDictionary<string, string> Metadata { get; init; } = ImmutableDictionary<string, string>.Empty;
}
public sealed record LicenseComplianceReport
{
public LicenseInventory Inventory { get; init; } = new();
public ImmutableArray<LicenseFinding> Findings { get; init; } = [];
public ImmutableArray<LicenseConflict> Conflicts { get; init; } = [];
public LicenseComplianceStatus OverallStatus { get; init; } = LicenseComplianceStatus.Pass;
public ImmutableArray<AttributionRequirement> AttributionRequirements { get; init; } = [];
}
public sealed record LicenseInventory
{
public ImmutableArray<LicenseUsage> Licenses { get; init; } = [];
public ImmutableDictionary<LicenseCategory, int> ByCategory { get; init; } =
ImmutableDictionary<LicenseCategory, int>.Empty;
public int UnknownLicenseCount { get; init; }
public int NoLicenseCount { get; init; }
}
public sealed record LicenseUsage
{
public required string LicenseId { get; init; }
public string? Expression { get; init; }
public LicenseCategory Category { get; init; }
public ImmutableArray<string> Components { get; init; } = [];
public int Count { get; init; }
}
public sealed record LicenseFinding
{
public required LicenseFindingType Type { get; init; }
public required string LicenseId { get; init; }
public required string ComponentName { get; init; }
public string? ComponentPurl { get; init; }
public LicenseCategory Category { get; init; }
public string? Message { get; init; }
}
public sealed record LicenseConflict
{
public required string ComponentName { get; init; }
public string? ComponentPurl { get; init; }
public ImmutableArray<string> LicenseIds { get; init; } = [];
public string? Reason { get; init; }
}
public sealed record AttributionRequirement
{
public required string ComponentName { get; init; }
public string? ComponentPurl { get; init; }
public required string LicenseId { get; init; }
public ImmutableArray<string> Notices { get; init; } = [];
public bool IncludeLicenseText { get; init; }
}
public sealed record LicenseObligation
{
public required LicenseObligationType Type { get; init; }
public string? Details { get; init; }
}
public enum LicenseComplianceStatus
{
Pass = 0,
Warn = 1,
Fail = 2
}
public enum LicenseFindingType
{
ProhibitedLicense = 0,
CopyleftInProprietaryContext = 1,
LicenseConflict = 2,
UnknownLicense = 3,
MissingLicense = 4,
AttributionRequired = 5,
SourceDisclosureRequired = 6,
PatentClauseRisk = 7,
CommercialRestriction = 8,
ConditionalLicenseViolation = 9
}
public enum LicenseCategory
{
Unknown = 0,
Permissive = 1,
WeakCopyleft = 2,
StrongCopyleft = 3,
Proprietary = 4,
PublicDomain = 5
}
public enum LicenseObligationType
{
Attribution = 0,
SourceDisclosure = 1,
PatentGrant = 2,
TrademarkNotice = 3
}