暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SecretsStore.cs 1022B

1234567891011121314151617181920212223242526
  1. using System.Text.Json;
  2. namespace Flo.Installer.Provisioning;
  3. internal sealed class SecretsStore(string path)
  4. {
  5. public bool Exists() => File.Exists(path);
  6. public IReadOnlyDictionary<string, string> Load()
  7. => JsonSerializer.Deserialize<Dictionary<string, string>>(File.ReadAllBytes(path))
  8. ?? throw new InvalidOperationException($"Malformed secrets file: {path}");
  9. public void Save(IReadOnlyDictionary<string, string> secrets)
  10. {
  11. Directory.CreateDirectory(Path.GetDirectoryName(path)!);
  12. File.WriteAllText(path, JsonSerializer.Serialize(secrets, new JsonSerializerOptions { WriteIndented = true }));
  13. RestrictPermissions(path);
  14. }
  15. // Phase 5 will swap this for DPAPI on Windows and real ACLs; Linux keeps the file-mode approach.
  16. private static void RestrictPermissions(string path)
  17. {
  18. if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
  19. File.SetUnixFileMode(path, UnixFileMode.UserRead | UnixFileMode.UserWrite);
  20. }
  21. }