| | | 1 | | using System.Text.Json; |
| | | 2 | | using Elsa.Platform.Integration.Services; |
| | | 3 | | using Loom; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Platform.Integration.Steps; |
| | | 6 | | |
| | | 7 | | [Step("elsa.configure-settings")] |
| | 0 | 8 | | public sealed class ConfigureSettingsStep( |
| | 0 | 9 | | IShellConfigurationOverlayStore overlayStore, |
| | 0 | 10 | | PlatformShellReloadTracker reloadTracker) : IStep, IValidatingStep |
| | | 11 | | { |
| | 0 | 12 | | public string ShellId { get; init; } = "Default"; |
| | | 13 | | |
| | 0 | 14 | | public JsonElement Settings { get; init; } |
| | | 15 | | |
| | | 16 | | public ValueTask<IReadOnlyList<RecipeDiagnostic>> ValidateAsync( |
| | | 17 | | StepValidationContext context, |
| | | 18 | | CancellationToken cancellationToken = default) |
| | | 19 | | { |
| | 0 | 20 | | List<RecipeDiagnostic> diagnostics = []; |
| | 0 | 21 | | if (string.IsNullOrWhiteSpace(ShellId)) |
| | 0 | 22 | | diagnostics.Add(context.Error("ELSA_PLATFORM_SHELL_ID_REQUIRED", "Shell ID is required.", context.Target("in |
| | | 23 | | |
| | 0 | 24 | | if (Settings.ValueKind != JsonValueKind.Object) |
| | 0 | 25 | | diagnostics.Add(context.Error("ELSA_PLATFORM_SETTINGS_REQUIRED", "Settings must be a JSON object.", context. |
| | | 26 | | |
| | 0 | 27 | | return ValueTask.FromResult<IReadOnlyList<RecipeDiagnostic>>(diagnostics); |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | public async ValueTask ExecuteAsync(StepContext context, CancellationToken cancellationToken = default) |
| | | 31 | | { |
| | 0 | 32 | | var changed = await overlayStore.ConfigureSettingsAsync(ShellId, Settings, cancellationToken); |
| | 0 | 33 | | if (changed) |
| | 0 | 34 | | reloadTracker.MarkForReload(ShellId); |
| | 0 | 35 | | } |
| | | 36 | | } |