| | | 1 | | using CShells.AspNetCore.Features; |
| | | 2 | | using CShells.FastEndpoints.Features; |
| | | 3 | | using CShells.Features; |
| | | 4 | | using ConsoleLogStreaming.Core.Options; |
| | | 5 | | using Elsa.Diagnostics.ConsoleLogs.Extensions; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | using Microsoft.AspNetCore.Routing; |
| | | 8 | | using Microsoft.Extensions.DependencyInjection; |
| | | 9 | | using Microsoft.Extensions.Hosting; |
| | | 10 | | |
| | | 11 | | namespace Elsa.Diagnostics.ConsoleLogs.ShellFeatures; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Provides live raw console log streaming over REST and SignalR. |
| | | 15 | | /// </summary> |
| | | 16 | | [ShellFeature( |
| | | 17 | | DisplayName = "Console Logs", |
| | | 18 | | Description = "Provides live raw console log streaming over REST and SignalR", |
| | | 19 | | DependsOn = ["ElsaFastEndpoints", "Workflows"])] |
| | | 20 | | [UsedImplicitly] |
| | | 21 | | public class ConsoleLogsFeature : IFastEndpointsShellFeature, IWebShellFeature |
| | | 22 | | { |
| | 0 | 23 | | private static readonly ConsoleLogOptions DefaultOptions = new(); |
| | | 24 | | |
| | 0 | 25 | | public int RecentLogCapacity { get; set; } = DefaultOptions.RecentCapacity; |
| | 0 | 26 | | public int SubscriberChannelCapacity { get; set; } = DefaultOptions.SubscriberCapacity; |
| | 0 | 27 | | public int MaxRecentQuerySize { get; set; } = DefaultOptions.MaxRecentQuerySize; |
| | 0 | 28 | | public int MaxLineLength { get; set; } = DefaultOptions.MaxLineLength; |
| | 0 | 29 | | public TimeSpan IdleFlushTimeout { get; set; } = DefaultOptions.IdleFlushTimeout; |
| | 0 | 30 | | public bool StripAnsiEscapeSequences { get; set; } = !DefaultOptions.PreserveAnsi; |
| | 0 | 31 | | public string RedactionReplacement { get; set; } = "[Redacted]"; |
| | 0 | 32 | | public ICollection<string> SensitiveTextPatterns { get; set; } = [..DefaultOptions.RedactionRules.Select(x => x.Patt |
| | | 33 | | |
| | | 34 | | public void ConfigureServices(IServiceCollection services) |
| | | 35 | | { |
| | 0 | 36 | | services.AddConsoleLogsServices(ConfigureOptions); |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | public void MapEndpoints(IEndpointRouteBuilder endpoints, IHostEnvironment? environment) |
| | | 40 | | { |
| | 0 | 41 | | endpoints.MapConsoleLogsHub(); |
| | 0 | 42 | | } |
| | | 43 | | |
| | | 44 | | private void ConfigureOptions(ConsoleLogOptions options) |
| | | 45 | | { |
| | 0 | 46 | | options.RecentCapacity = RecentLogCapacity; |
| | 0 | 47 | | options.SubscriberCapacity = SubscriberChannelCapacity; |
| | 0 | 48 | | options.MaxRecentQuerySize = MaxRecentQuerySize; |
| | 0 | 49 | | options.MaxLineLength = MaxLineLength; |
| | 0 | 50 | | options.IdleFlushTimeout = IdleFlushTimeout; |
| | 0 | 51 | | options.PreserveAnsi = !StripAnsiEscapeSequences; |
| | 0 | 52 | | options.RedactionRules.Clear(); |
| | 0 | 53 | | foreach (var pattern in SensitiveTextPatterns) |
| | | 54 | | { |
| | 0 | 55 | | options.RedactionRules.Add(new() |
| | 0 | 56 | | { |
| | 0 | 57 | | Name = "Sensitive text", |
| | 0 | 58 | | Pattern = pattern, |
| | 0 | 59 | | Replacement = RedactionReplacement |
| | 0 | 60 | | }); |
| | | 61 | | } |
| | 0 | 62 | | } |
| | | 63 | | } |