release orchestrator v1 draft and build fixes
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
namespace StellaOps.Cryptography.Plugin;
|
||||
|
||||
using StellaOps.Plugin.Abstractions;
|
||||
using StellaOps.Plugin.Abstractions.Capabilities;
|
||||
using StellaOps.Plugin.Abstractions.Context;
|
||||
using StellaOps.Plugin.Abstractions.Health;
|
||||
using StellaOps.Plugin.Abstractions.Lifecycle;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for cryptographic plugins providing common functionality.
|
||||
/// Implements IPlugin and ICryptoCapability interfaces.
|
||||
/// </summary>
|
||||
public abstract class CryptoPluginBase : IPlugin, ICryptoCapability
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin context set during initialization.
|
||||
/// </summary>
|
||||
protected IPluginContext? Context { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Plugin information including ID, name, version.
|
||||
/// </summary>
|
||||
public abstract PluginInfo Info { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Trust level for crypto plugins - always BuiltIn.
|
||||
/// </summary>
|
||||
public PluginTrustLevel TrustLevel => PluginTrustLevel.BuiltIn;
|
||||
|
||||
/// <summary>
|
||||
/// Capabilities provided by this plugin.
|
||||
/// </summary>
|
||||
public PluginCapabilities Capabilities => PluginCapabilities.Crypto;
|
||||
|
||||
/// <summary>
|
||||
/// Current lifecycle state.
|
||||
/// </summary>
|
||||
public PluginLifecycleState State { get; protected set; } = PluginLifecycleState.Discovered;
|
||||
|
||||
/// <summary>
|
||||
/// List of algorithms supported by this crypto provider.
|
||||
/// </summary>
|
||||
public abstract IReadOnlyList<string> SupportedAlgorithms { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the crypto plugin.
|
||||
/// </summary>
|
||||
/// <param name="context">Plugin context with configuration and services.</param>
|
||||
/// <param name="ct">Cancellation token.</param>
|
||||
public async Task InitializeAsync(IPluginContext context, CancellationToken ct)
|
||||
{
|
||||
Context = context;
|
||||
State = PluginLifecycleState.Initializing;
|
||||
|
||||
try
|
||||
{
|
||||
await InitializeCryptoServiceAsync(context, ct);
|
||||
State = PluginLifecycleState.Active;
|
||||
context.Logger.Info("{PluginName} initialized successfully", Info.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
State = PluginLifecycleState.Failed;
|
||||
context.Logger.Error(ex, "Failed to initialize {PluginName}", Info.Name);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override to initialize the specific crypto service.
|
||||
/// </summary>
|
||||
/// <param name="context">Plugin context.</param>
|
||||
/// <param name="ct">Cancellation token.</param>
|
||||
protected abstract Task InitializeCryptoServiceAsync(IPluginContext context, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Perform health check on the crypto provider.
|
||||
/// </summary>
|
||||
/// <param name="ct">Cancellation token.</param>
|
||||
/// <returns>Health check result.</returns>
|
||||
public virtual async Task<HealthCheckResult> HealthCheckAsync(CancellationToken ct)
|
||||
{
|
||||
if (State != PluginLifecycleState.Active)
|
||||
{
|
||||
return HealthCheckResult.Unhealthy($"Plugin is in state {State}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Default health check: verify we can hash test data
|
||||
var testData = "health-check-test"u8.ToArray();
|
||||
var algorithm = SelectHealthCheckAlgorithm();
|
||||
|
||||
if (algorithm != null)
|
||||
{
|
||||
await HashAsync(testData, algorithm, ct);
|
||||
}
|
||||
|
||||
return HealthCheckResult.Healthy();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return HealthCheckResult.Unhealthy(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Select an algorithm for health checks.
|
||||
/// </summary>
|
||||
protected virtual string? SelectHealthCheckAlgorithm()
|
||||
{
|
||||
return SupportedAlgorithms.FirstOrDefault(a =>
|
||||
a.Contains("256", StringComparison.OrdinalIgnoreCase) ||
|
||||
a.Contains("SHA", StringComparison.OrdinalIgnoreCase) ||
|
||||
a.Contains("HASH", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if this provider can handle the specified operation and algorithm.
|
||||
/// </summary>
|
||||
/// <param name="operation">Crypto operation type.</param>
|
||||
/// <param name="algorithm">Algorithm identifier.</param>
|
||||
/// <returns>True if supported.</returns>
|
||||
public abstract bool CanHandle(CryptoOperation operation, string algorithm);
|
||||
|
||||
/// <summary>
|
||||
/// Sign data using the specified algorithm and key.
|
||||
/// </summary>
|
||||
public abstract Task<byte[]> SignAsync(ReadOnlyMemory<byte> data, CryptoSignOptions options, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Verify a signature.
|
||||
/// </summary>
|
||||
public abstract Task<bool> VerifyAsync(ReadOnlyMemory<byte> data, ReadOnlyMemory<byte> signature, CryptoVerifyOptions options, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Encrypt data.
|
||||
/// </summary>
|
||||
public abstract Task<byte[]> EncryptAsync(ReadOnlyMemory<byte> data, CryptoEncryptOptions options, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Decrypt data.
|
||||
/// </summary>
|
||||
public abstract Task<byte[]> DecryptAsync(ReadOnlyMemory<byte> data, CryptoDecryptOptions options, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Compute hash of data.
|
||||
/// </summary>
|
||||
public abstract Task<byte[]> HashAsync(ReadOnlyMemory<byte> data, string algorithm, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Dispose the crypto plugin.
|
||||
/// </summary>
|
||||
public abstract ValueTask DisposeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Ensure the plugin is active before performing operations.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">If plugin is not active.</exception>
|
||||
protected void EnsureActive()
|
||||
{
|
||||
if (State != PluginLifecycleState.Active)
|
||||
{
|
||||
throw new InvalidOperationException($"{Info.Name} is not active (current state: {State})");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\StellaOps.Cryptography\StellaOps.Cryptography.csproj" />
|
||||
<ProjectReference Include="..\..\Plugin\StellaOps.Plugin.Abstractions\StellaOps.Plugin.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user