19 lines
705 B
C#
19 lines
705 B
C#
namespace MxGateway.Client.Cli;
|
|
|
|
/// <summary>Utility to redact API keys from error messages for safe output.</summary>
|
|
internal static class MxGatewayCliSecretRedactor
|
|
{
|
|
/// <summary>Replaces occurrences of the API key in the value with a redacted placeholder.</summary>
|
|
/// <param name="value">The message text to redact.</param>
|
|
/// <param name="apiKey">The API key to remove; no redaction if null or empty.</param>
|
|
public static string Redact(string value, string? apiKey)
|
|
{
|
|
if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(apiKey))
|
|
{
|
|
return value;
|
|
}
|
|
|
|
return value.Replace(apiKey, "[redacted]", StringComparison.Ordinal);
|
|
}
|
|
}
|