| | | 1 | | using Elsa.Features.Contracts; |
| | | 2 | | using Elsa.Platform.Integration.Options; |
| | | 3 | | using Loom; |
| | | 4 | | using Microsoft.Extensions.Options; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Platform.Integration.Steps; |
| | | 7 | | |
| | | 8 | | [Step("elsa.verify-capabilities")] |
| | 1 | 9 | | public sealed class VerifyCapabilitiesStep( |
| | 1 | 10 | | IInstalledFeatureProvider installedFeatureProvider, |
| | 1 | 11 | | IOptions<ElsaPlatformIntegrationOptions> options) : IStep, IValidatingStep |
| | | 12 | | { |
| | 1 | 13 | | public List<string>? Features { get; init; } |
| | | 14 | | |
| | 2 | 15 | | public List<string>? Capabilities { get; init; } |
| | | 16 | | |
| | | 17 | | public ValueTask<IReadOnlyList<RecipeDiagnostic>> ValidateAsync( |
| | | 18 | | StepValidationContext context, |
| | | 19 | | CancellationToken cancellationToken = default) |
| | | 20 | | { |
| | 1 | 21 | | List<RecipeDiagnostic> diagnostics = []; |
| | 1 | 22 | | var installedFeatures = installedFeatureProvider.List().ToList(); |
| | 2 | 23 | | foreach (var feature in Features ?? []) |
| | | 24 | | { |
| | 0 | 25 | | var exists = installedFeatures.Any(x => |
| | 0 | 26 | | string.Equals(x.Name, feature, StringComparison.OrdinalIgnoreCase) |
| | 0 | 27 | | || string.Equals(x.FullName, feature, StringComparison.OrdinalIgnoreCase)); |
| | 0 | 28 | | if (!exists) |
| | 0 | 29 | | diagnostics.Add(context.Error("ELSA_PLATFORM_FEATURE_MISSING", $"Required feature '{feature}' is not ins |
| | | 30 | | } |
| | | 31 | | |
| | 1 | 32 | | var runtimeCapabilities = options.Value.Capabilities; |
| | 4 | 33 | | foreach (var capability in Capabilities ?? []) |
| | | 34 | | { |
| | 1 | 35 | | if (!runtimeCapabilities.Contains(capability, StringComparer.OrdinalIgnoreCase)) |
| | 1 | 36 | | diagnostics.Add(context.Error("ELSA_PLATFORM_CAPABILITY_MISSING", $"Required runtime capability '{capabi |
| | | 37 | | } |
| | | 38 | | |
| | 1 | 39 | | return ValueTask.FromResult<IReadOnlyList<RecipeDiagnostic>>(diagnostics); |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | public ValueTask ExecuteAsync(StepContext context, CancellationToken cancellationToken = default) => |
| | 0 | 43 | | ValueTask.CompletedTask; |
| | | 44 | | } |