using System.Collections.Immutable; using Recyclarr.Common.Extensions; using Recyclarr.TrashLib.Startup; using YamlDotNet.Serialization; namespace Recyclarr.TrashLib.Config.Secrets; public class SecretsProvider : ISecretsProvider { public IImmutableDictionary Secrets => _secrets.Value; private readonly IAppPaths _paths; private readonly Lazy> _secrets; public SecretsProvider(IAppPaths paths) { _paths = paths; _secrets = new Lazy>(LoadSecretsFile); } private IImmutableDictionary LoadSecretsFile() { var result = new Dictionary(); var yamlPath = _paths.AppDataDirectory.YamlFile("secrets"); if (yamlPath is not null) { using var stream = yamlPath.OpenText(); var deserializer = new DeserializerBuilder().Build(); var dict = deserializer.Deserialize?>(stream); if (dict is not null) { result = dict; } } return result.ToImmutableDictionary(); } }