| | | 1 | | namespace Elsa.Platform.Integration.Options; |
| | | 2 | | |
| | | 3 | | public class ElsaPlatformIntegrationOptions |
| | | 4 | | { |
| | | 5 | | public const string ConfigurationSection = "Elsa:PlatformIntegration"; |
| | | 6 | | |
| | 0 | 7 | | public bool Enabled { get; set; } |
| | | 8 | | |
| | 0 | 9 | | public Uri? PlatformEndpoint { get; set; } |
| | | 10 | | |
| | 0 | 11 | | public Guid WorkspaceId { get; set; } |
| | | 12 | | |
| | 0 | 13 | | public Guid EngineId { get; set; } |
| | | 14 | | |
| | 0 | 15 | | public string? EngineSecret { get; set; } |
| | | 16 | | |
| | 4 | 17 | | public string WorkerId { get; set; } = $"{Environment.MachineName}:{Environment.ProcessId}"; |
| | | 18 | | |
| | 4 | 19 | | public TimeSpan PollInterval { get; set; } = TimeSpan.FromSeconds(5); |
| | | 20 | | |
| | 4 | 21 | | public TimeSpan ClaimLeaseDuration { get; set; } = TimeSpan.FromMinutes(5); |
| | | 22 | | |
| | 4 | 23 | | public long MaxArtifactBytes { get; set; } = 4 * 1024 * 1024; |
| | | 24 | | |
| | 10 | 25 | | public string ShellOverlayPath { get; set; } = "platform-shell-overrides.json"; |
| | | 26 | | |
| | 5 | 27 | | public IReadOnlyList<string> Capabilities { get; set; } = ["loom.recipe.apply"]; |
| | | 28 | | |
| | | 29 | | public void Validate() |
| | | 30 | | { |
| | 0 | 31 | | if (!Enabled) |
| | 0 | 32 | | return; |
| | | 33 | | |
| | 0 | 34 | | if (PlatformEndpoint is null) |
| | 0 | 35 | | throw new InvalidOperationException("Elsa Platform endpoint is required when Platform integration is enabled |
| | 0 | 36 | | if (WorkspaceId == Guid.Empty) |
| | 0 | 37 | | throw new InvalidOperationException("Elsa Platform workspace ID is required when Platform integration is ena |
| | 0 | 38 | | if (EngineId == Guid.Empty) |
| | 0 | 39 | | throw new InvalidOperationException("Elsa Platform engine ID is required when Platform integration is enable |
| | 0 | 40 | | if (string.IsNullOrWhiteSpace(EngineSecret)) |
| | 0 | 41 | | throw new InvalidOperationException("Elsa Platform engine secret is required when Platform integration is en |
| | 0 | 42 | | if (string.IsNullOrWhiteSpace(WorkerId)) |
| | 0 | 43 | | throw new InvalidOperationException("Elsa Platform worker ID is required when Platform integration is enable |
| | 0 | 44 | | if (PollInterval <= TimeSpan.Zero) |
| | 0 | 45 | | throw new InvalidOperationException("Elsa Platform poll interval must be positive."); |
| | 0 | 46 | | if (ClaimLeaseDuration < TimeSpan.FromSeconds(1) || ClaimLeaseDuration.TotalSeconds > int.MaxValue) |
| | 0 | 47 | | throw new InvalidOperationException("Elsa Platform claim lease duration must be between 1 second and the max |
| | 0 | 48 | | if (MaxArtifactBytes <= 0 || MaxArtifactBytes > Array.MaxLength) |
| | 0 | 49 | | throw new InvalidOperationException("Elsa Platform maximum artifact size must be between 1 byte and the maxi |
| | 0 | 50 | | if (string.IsNullOrWhiteSpace(ShellOverlayPath)) |
| | 0 | 51 | | throw new InvalidOperationException("Elsa Platform shell overlay path is required when Platform integration |
| | 0 | 52 | | } |
| | | 53 | | } |