Issue #21: implement worker bootstrap and options
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MxGateway.Worker.Bootstrap;
|
||||
|
||||
public static class WorkerLogRedactor
|
||||
{
|
||||
public const string RedactedValue = "[redacted]";
|
||||
|
||||
private static readonly string[] SensitiveFieldNameParts =
|
||||
[
|
||||
"nonce",
|
||||
"secret",
|
||||
"password",
|
||||
"token",
|
||||
"credential",
|
||||
"apikey",
|
||||
"api_key",
|
||||
];
|
||||
|
||||
public static Dictionary<string, object?> RedactFields(IReadOnlyDictionary<string, object?> fields)
|
||||
{
|
||||
Dictionary<string, object?> redactedFields = [];
|
||||
|
||||
foreach (KeyValuePair<string, object?> field in fields)
|
||||
{
|
||||
redactedFields[field.Key] = RedactValue(field.Key, field.Value);
|
||||
}
|
||||
|
||||
return redactedFields;
|
||||
}
|
||||
|
||||
public static object? RedactValue(string fieldName, object? value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (string sensitiveFieldNamePart in SensitiveFieldNameParts)
|
||||
{
|
||||
if (fieldName.IndexOf(sensitiveFieldNamePart, StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
{
|
||||
return RedactedValue;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user