stabilizaiton work - projects rework for maintenanceability and ui livening
This commit is contained in:
61
src/__Libraries/StellaOps.DistroIntel/DistroMappings.cs
Normal file
61
src/__Libraries/StellaOps.DistroIntel/DistroMappings.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace StellaOps.DistroIntel;
|
||||
|
||||
public static partial class DistroMappings
|
||||
{
|
||||
/// <summary>
|
||||
/// Finds derivatives for a canonical (parent) distro at a specific major release.
|
||||
/// Use this to find alternative evidence sources when native OVAL/CSAF is unavailable.
|
||||
/// </summary>
|
||||
/// <param name="canonicalDistro">The canonical distro identifier (e.g., "rhel").</param>
|
||||
/// <param name="majorRelease">The major release version.</param>
|
||||
/// <returns>Matching derivative mappings, ordered by confidence (High first).</returns>
|
||||
/// <example>
|
||||
/// var derivatives = DistroMappings.FindDerivativesFor("rhel", 9);
|
||||
/// // Returns: [(rhel, almalinux, 9, High), (rhel, rocky, 9, High), (rhel, oracle, 9, High)]
|
||||
/// </example>
|
||||
public static IEnumerable<DistroDerivative> FindDerivativesFor(string canonicalDistro, int majorRelease)
|
||||
{
|
||||
var key = (canonicalDistro.ToLowerInvariant(), majorRelease);
|
||||
if (_byCanonicalIndex.TryGetValue(key, out var derivatives))
|
||||
{
|
||||
return derivatives.OrderByDescending(d => d.Confidence);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the canonical (parent) distro for a derivative distro.
|
||||
/// Use this to map a derivative back to its upstream source.
|
||||
/// </summary>
|
||||
/// <param name="derivativeDistro">The derivative distro identifier (e.g., "almalinux").</param>
|
||||
/// <param name="majorRelease">The major release version.</param>
|
||||
/// <returns>The canonical mapping if found, null otherwise.</returns>
|
||||
/// <example>
|
||||
/// var canonical = DistroMappings.FindCanonicalFor("almalinux", 9);
|
||||
/// // Returns: (rhel, almalinux, 9, High)
|
||||
/// </example>
|
||||
public static DistroDerivative? FindCanonicalFor(string derivativeDistro, int majorRelease)
|
||||
{
|
||||
var key = (derivativeDistro.ToLowerInvariant(), majorRelease);
|
||||
return _byDerivativeIndex.GetValueOrDefault(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the confidence multiplier for a derivative relationship.
|
||||
/// Apply this to the base confidence when using derivative evidence.
|
||||
/// </summary>
|
||||
/// <param name="confidence">The derivative confidence level.</param>
|
||||
/// <returns>Multiplier value (0.95 for High, 0.80 for Medium).</returns>
|
||||
public static decimal GetConfidenceMultiplier(DerivativeConfidence confidence)
|
||||
{
|
||||
return confidence switch
|
||||
{
|
||||
DerivativeConfidence.High => 0.95m,
|
||||
DerivativeConfidence.Medium => 0.80m,
|
||||
_ => 0.70m // Unknown - conservative
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user