| | | 1 | | using System.Text.RegularExpressions; |
| | | 2 | | using Elsa.Platform.Integration.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Platform.Integration.Services; |
| | | 5 | | |
| | | 6 | | public static partial class PlatformDiagnosticSanitizer |
| | | 7 | | { |
| | | 8 | | public static PlatformDiagnostic Info(string code, string message) => |
| | 1 | 9 | | new(code, PlatformDiagnosticSeverity.Info, SafeMessage(message)); |
| | | 10 | | |
| | | 11 | | public static PlatformDiagnostic Warning(string code, string message) => |
| | 0 | 12 | | new(code, PlatformDiagnosticSeverity.Warning, SafeMessage(message)); |
| | | 13 | | |
| | | 14 | | public static PlatformDiagnostic Error(string code, string message) => |
| | 1 | 15 | | new(code, PlatformDiagnosticSeverity.Error, SafeMessage(message)); |
| | | 16 | | |
| | | 17 | | public static string SafeMessage(string? message) |
| | | 18 | | { |
| | 2 | 19 | | if (string.IsNullOrWhiteSpace(message)) |
| | 0 | 20 | | return "No diagnostic details were provided."; |
| | | 21 | | |
| | 2 | 22 | | var safe = SensitiveWordsRegex().Replace(message, "[redacted]"); |
| | 2 | 23 | | return safe.Length <= 500 ? safe : safe[..500]; |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | [GeneratedRegex("(api[-_ ]?key|bearer|client[-_ ]?secret|password|private[-_ ]?key|secret|token)", RegexOptions.Igno |
| | | 27 | | private static partial Regex SensitiveWordsRegex(); |
| | | 28 | | } |