using StellaOps.Scanner.Cache.Abstractions; using StellaOps.Scanner.Surface.Env; using System; using System.IO; using System.Threading; using System.Threading.Tasks; namespace StellaOps.Scanner.Reachability; public interface IReachabilityUnionPublisherService { Task PublishAsync(ReachabilityUnionGraph graph, string analysisId, CancellationToken cancellationToken = default); } /// /// Default service that writes a union graph to CAS using the worker surface cache root. /// public sealed class ReachabilityUnionPublisherService : IReachabilityUnionPublisherService { private readonly ISurfaceEnvironment environment; private readonly IFileContentAddressableStore cas; private readonly ReachabilityUnionPublisher publisher; public ReachabilityUnionPublisherService( ISurfaceEnvironment environment, IFileContentAddressableStore cas, ReachabilityUnionPublisher publisher) { this.environment = environment ?? throw new ArgumentNullException(nameof(environment)); this.cas = cas ?? throw new ArgumentNullException(nameof(cas)); this.publisher = publisher ?? throw new ArgumentNullException(nameof(publisher)); } public Task PublishAsync(ReachabilityUnionGraph graph, string analysisId, CancellationToken cancellationToken = default) { var workRoot = Path.Combine(environment.Settings.CacheRoot.FullName, "reachability"); Directory.CreateDirectory(workRoot); return publisher.PublishAsync(graph, cas, workRoot, analysisId, cancellationToken); } }