Вынести коды параметров аудита и ключи JSON в константы
Магические строки кодов деталей аудита заменены каталогом AuditFields (68 мест), ключи элемента изменения и разбора JSON — константами, ключи хранилища ключей Telegram и геометрия маски — именованными константами.
This commit is contained in:
@@ -26,6 +26,15 @@ public sealed class TelegramKeysService(IGlobalSettingsStore store, ISecretCiphe
|
||||
|
||||
private const string EncryptedPrefix = "enc:";
|
||||
|
||||
// Ключи JSON значения telegramKeys (camelCase, как пишет SaveAsync).
|
||||
private const string ApiIdProperty = "apiId";
|
||||
private const string ApiHashProperty = "apiHash";
|
||||
|
||||
// Геометрия маски секрета: короткий (≤8) → «x…»; иначе «1234…5678».
|
||||
private const int MaskShortMaxLength = 8;
|
||||
private const int MaskShortVisibleChars = 1;
|
||||
private const int MaskEdgeVisibleChars = 4;
|
||||
|
||||
// Опции JSON значения telegramKeys: camelCase (как пишет SaveAsync) + терпимость регистра.
|
||||
private static readonly JsonSerializerOptions KeysJsonOptions = new()
|
||||
{
|
||||
@@ -49,8 +58,8 @@ public sealed class TelegramKeysService(IGlobalSettingsStore store, ISecretCiphe
|
||||
{
|
||||
using JsonDocument document = JsonDocument.Parse(row.ValueJson);
|
||||
JsonElement root = document.RootElement;
|
||||
string apiId = ReadString(root, "apiId");
|
||||
string apiHash = ReadString(root, "apiHash");
|
||||
string apiId = ReadString(root, ApiIdProperty);
|
||||
string apiHash = ReadString(root, ApiHashProperty);
|
||||
return new TgKeysSnapshot(apiId, cipher.Decrypt(apiHash));
|
||||
}
|
||||
catch (JsonException)
|
||||
@@ -143,8 +152,11 @@ public sealed class TelegramKeysService(IGlobalSettingsStore store, ISecretCiphe
|
||||
return value.Length switch
|
||||
{
|
||||
0 => string.Empty,
|
||||
<= 8 => string.Concat(value.AsSpan(0, 1), MaskEllipsis),
|
||||
_ => string.Concat(value.AsSpan(0, 4), MaskEllipsis, value.AsSpan(value.Length - 4)),
|
||||
<= MaskShortMaxLength => string.Concat(value.AsSpan(0, MaskShortVisibleChars), MaskEllipsis),
|
||||
_ => string.Concat(
|
||||
value.AsSpan(0, MaskEdgeVisibleChars),
|
||||
MaskEllipsis,
|
||||
value.AsSpan(value.Length - MaskEdgeVisibleChars)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user