release orchestrator v1 draft and build fixes
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StellaOps.Plugin.Sandbox.Communication;
|
||||
using StellaOps.Plugin.Sandbox.Network;
|
||||
using StellaOps.Plugin.Sandbox.Process;
|
||||
using StellaOps.Plugin.Sandbox.Resources;
|
||||
|
||||
namespace StellaOps.Plugin.Sandbox.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for registering sandbox services.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds plugin sandbox services to the service collection.
|
||||
/// </summary>
|
||||
/// <param name="services">The service collection.</param>
|
||||
/// <param name="configureOptions">Optional configuration for plugin process manager.</param>
|
||||
/// <returns>The service collection for chaining.</returns>
|
||||
public static IServiceCollection AddPluginSandbox(
|
||||
this IServiceCollection services,
|
||||
Action<PluginProcessManagerOptions>? configureOptions = null)
|
||||
{
|
||||
// Configure options
|
||||
if (configureOptions != null)
|
||||
{
|
||||
services.Configure(configureOptions);
|
||||
}
|
||||
else
|
||||
{
|
||||
services.Configure<PluginProcessManagerOptions>(_ => { });
|
||||
}
|
||||
|
||||
// Register TimeProvider if not already registered
|
||||
services.TryAddSingleton(TimeProvider.System);
|
||||
|
||||
// Register process manager
|
||||
services.AddSingleton<IPluginProcessManager, PluginProcessManager>();
|
||||
|
||||
// Register network policy enforcer
|
||||
services.AddSingleton<INetworkPolicyEnforcer, NetworkPolicyEnforcer>();
|
||||
|
||||
// Register resource limiter (platform-specific)
|
||||
services.AddSingleton<IResourceLimiter>(sp =>
|
||||
{
|
||||
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();
|
||||
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
return new WindowsResourceLimiter(
|
||||
loggerFactory.CreateLogger<WindowsResourceLimiter>());
|
||||
}
|
||||
else
|
||||
{
|
||||
return new LinuxResourceLimiter(
|
||||
loggerFactory.CreateLogger<LinuxResourceLimiter>());
|
||||
}
|
||||
});
|
||||
|
||||
// Register sandbox factory
|
||||
services.AddSingleton<ISandboxFactory, SandboxFactory>();
|
||||
|
||||
// Register gRPC bridge as transient (one per sandbox)
|
||||
services.AddTransient<IGrpcPluginBridge, GrpcPluginBridge>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds plugin sandbox services with custom resource limiter.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResourceLimiter">The resource limiter type.</typeparam>
|
||||
/// <param name="services">The service collection.</param>
|
||||
/// <returns>The service collection for chaining.</returns>
|
||||
public static IServiceCollection AddPluginSandbox<TResourceLimiter>(
|
||||
this IServiceCollection services)
|
||||
where TResourceLimiter : class, IResourceLimiter
|
||||
{
|
||||
services.AddPluginSandbox();
|
||||
|
||||
// Replace resource limiter registration
|
||||
services.AddSingleton<IResourceLimiter, TResourceLimiter>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds plugin sandbox services with custom network policy enforcer.
|
||||
/// </summary>
|
||||
/// <typeparam name="TNetworkEnforcer">The network policy enforcer type.</typeparam>
|
||||
/// <param name="services">The service collection.</param>
|
||||
/// <returns>The service collection for chaining.</returns>
|
||||
public static IServiceCollection AddPluginSandboxWithNetworkEnforcer<TNetworkEnforcer>(
|
||||
this IServiceCollection services)
|
||||
where TNetworkEnforcer : class, INetworkPolicyEnforcer
|
||||
{
|
||||
services.AddPluginSandbox();
|
||||
|
||||
// Replace network enforcer registration
|
||||
services.AddSingleton<INetworkPolicyEnforcer, TNetworkEnforcer>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user