From cd8e865dad326f85ff2357ad90bbd6aa65dea68e Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 6 Sep 2023 13:51:13 -0400 Subject: initial commit --- .../NVault.VaultExtensions/src/KvVaultStorage.cs | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 back-end/libs/NVault.VaultExtensions/src/KvVaultStorage.cs (limited to 'back-end/libs/NVault.VaultExtensions/src/KvVaultStorage.cs') diff --git a/back-end/libs/NVault.VaultExtensions/src/KvVaultStorage.cs b/back-end/libs/NVault.VaultExtensions/src/KvVaultStorage.cs new file mode 100644 index 0000000..b679404 --- /dev/null +++ b/back-end/libs/NVault.VaultExtensions/src/KvVaultStorage.cs @@ -0,0 +1,66 @@ +// Copyright (C) 2023 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; + } +} \ No newline at end of file -- cgit