// Copyright (C) 2024 Vaughn Nugent // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . using System.Threading.Tasks; using VaultSharp; using VNLib.Utils.Memory; namespace NVault.VaultExtensions { /// /// An abstract kv storage implementation that uses the vault client to store secrets /// public abstract class KvVaultStorage : IKvVaultStore { /// /// The vault client /// protected abstract IVaultClient Client { get; } /// /// The storage scope /// protected abstract IVaultKvClientScope Scope { get; } public virtual Task DeleteSecretAsync(VaultUserScope user, string path) { string tPath = TranslatePath(path); return Client.DeleteSecretAsync(Scope, user, tPath); } public virtual Task SetSecretAsync(VaultUserScope user, string path, PrivateString secret) { string tPath = TranslatePath(path); return Client.SetSecretAsync(Scope, user, tPath, secret); } public virtual Task GetSecretAsync(VaultUserScope user, string path) { string tPath = TranslatePath(path); return Client.GetSecretAsync(Scope, user, tPath); } /// /// Translates a realtive item path to a full path /// within the scope of the storage. This may be used to /// extend the scope of the operation /// /// The item path to scope /// The further scoped vault path for the item public virtual string TranslatePath(string path) => path; } }