102 lines
4.2 KiB
C#
102 lines
4.2 KiB
C#
|
|
using StellaOps.Plugin.Security;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace StellaOps.Plugin.Hosting;
|
|
|
|
public sealed class PluginHostOptions
|
|
{
|
|
private readonly List<string> _additionalPrefixes = new();
|
|
private readonly List<string> _pluginOrder = new();
|
|
private readonly List<string> _searchPatterns = new();
|
|
|
|
/// <summary>
|
|
/// Optional base directory used for resolving relative plugin paths. Defaults to <see cref="AppContext.BaseDirectory" />.
|
|
/// </summary>
|
|
public string? BaseDirectory { get; set; }
|
|
|
|
/// <summary>
|
|
/// Directory that contains plugin assemblies. Relative values are resolved against <see cref="BaseDirectory" />.
|
|
/// Defaults to <c>{PrimaryPrefix}.PluginBinaries</c> when a primary prefix is provided, otherwise <c>PluginBinaries</c>.
|
|
/// </summary>
|
|
public string? PluginsDirectory { get; set; }
|
|
|
|
/// <summary>
|
|
/// Primary prefix used to discover plugin assemblies. If not supplied, the entry assembly name is used.
|
|
/// </summary>
|
|
public string? PrimaryPrefix { get; set; }
|
|
|
|
/// <summary>
|
|
/// Additional prefixes that should be considered when building search patterns.
|
|
/// </summary>
|
|
public IList<string> AdditionalPrefixes => _additionalPrefixes;
|
|
|
|
/// <summary>
|
|
/// Explicit plugin ordering expressed as assembly names without extension.
|
|
/// Entries that are not discovered will be reported in <see cref="PluginHostResult.MissingOrderedPlugins" />.
|
|
/// </summary>
|
|
public IList<string> PluginOrder => _pluginOrder;
|
|
|
|
/// <summary>
|
|
/// Optional explicit search patterns. When empty, they are derived from prefix settings.
|
|
/// </summary>
|
|
public IList<string> SearchPatterns => _searchPatterns;
|
|
|
|
/// <summary>
|
|
/// When true (default) the plugin directory will be created if it does not exist.
|
|
/// </summary>
|
|
public bool EnsureDirectoryExists { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Controls whether sub-directories should be scanned. Defaults to true.
|
|
/// </summary>
|
|
public bool RecursiveSearch { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// The host application version used for plugin compatibility checking.
|
|
/// When set, plugins with <see cref="Versioning.StellaPluginVersionAttribute"/> will be validated.
|
|
/// </summary>
|
|
public Version? HostVersion { get; set; }
|
|
|
|
/// <summary>
|
|
/// Whether to enforce version compatibility checking. Defaults to true.
|
|
/// When false, incompatible plugins will be loaded with a warning.
|
|
/// </summary>
|
|
public bool EnforceVersionCompatibility { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Whether plugins must declare a <see cref="Versioning.StellaPluginVersionAttribute"/>. Defaults to true.
|
|
/// When true, plugins without the version attribute will be rejected.
|
|
/// This is recommended for production deployments to ensure all plugins are properly versioned.
|
|
/// </summary>
|
|
public bool RequireVersionAttribute { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Whether to enforce strict major version checking. Defaults to true.
|
|
/// When true and a plugin does not specify MaximumHostVersion, the loader assumes
|
|
/// the plugin only supports host versions with the same major version as MinimumHostVersion.
|
|
/// This prevents loading plugins designed for host 1.x on host 2.x without explicit compatibility declaration.
|
|
/// </summary>
|
|
public bool StrictMajorVersionCheck { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// The signature verifier to use for plugin validation.
|
|
/// Defaults to <see cref="NullPluginVerifier"/> (no verification).
|
|
/// Set to <see cref="CosignPluginVerifier"/> for production use.
|
|
/// </summary>
|
|
public IPluginSignatureVerifier? SignatureVerifier { get; set; }
|
|
|
|
/// <summary>
|
|
/// Whether to enforce signature verification. Defaults to false.
|
|
/// When true and <see cref="SignatureVerifier"/> is set, plugins without valid signatures will be rejected.
|
|
/// </summary>
|
|
public bool EnforceSignatureVerification { get; set; }
|
|
|
|
internal string ResolveBaseDirectory()
|
|
=> string.IsNullOrWhiteSpace(BaseDirectory)
|
|
? AppContext.BaseDirectory
|
|
: Path.GetFullPath(BaseDirectory);
|
|
}
|